Cov txheej txheem:

Kev Ntsuas Kev Siv H3LIS331DL thiab Arduino Nano: 4 Kauj Ruam
Kev Ntsuas Kev Siv H3LIS331DL thiab Arduino Nano: 4 Kauj Ruam

Video: Kev Ntsuas Kev Siv H3LIS331DL thiab Arduino Nano: 4 Kauj Ruam

Video: Kev Ntsuas Kev Siv H3LIS331DL thiab Arduino Nano: 4 Kauj Ruam
Video: Qhia txuas xaim hluav taws xob daim: 02 2024, Kaum ib hlis
Anonim
Image
Image

H3LIS331DL, yog lub zog qis ua tau zoo 3-axis linear accelerometer koom nrog "nano" tsev neeg, nrog digital I²C cov lej sib txuas. H3LIS331DL muaj cov neeg siv xaiv tau cov nplai ntawm g 100g/± 200g/± 400g thiab nws muaj peev xwm ntsuas qhov nrawm nrog cov ntaub ntawv tso tawm tus nqi los ntawm 0.5 Hz txog 1 kHz. H3LIS331DL tau lees tias ua haujlwm dhau qhov ntsuas kub ntev los ntawm -40 ° C txog +85 ° C.

Hauv qhov kev qhia no peb yuav nthuav qhia qhov cuam tshuam ntawm H3LIS331DL nrog Arduino Nano.

Kauj Ruam 1: Yuav Tsum Kho Vajtse:

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Cov ntaub ntawv uas peb xav tau kom ua tiav peb lub hom phiaj suav nrog cov khoom siv hauv qab no:

1. H3LIS331DL

2. Arduino Nano

3. I2C Cable

4. I2C Shield rau Arduino Nano

Kauj ruam 2: Khoos phis tawj sib txuas:

Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup

Tshooj khoos phis tawj sib txuas ntu piav qhia qhov txuas txuas uas xav tau ntawm lub sensor thiab arduino nano. Ua kom muaj kev sib txuas raug yog qhov tseem ceeb xav tau thaum ua haujlwm ntawm ib qho system rau qhov xav tau cov zis. Yog li, qhov xav tau kev sib txuas yog raws li hauv qab no:

H3LIS331DL yuav ua haujlwm dhau I2C. Nov yog qhov piv txwv kab hluav taws xob daim duab, qhia txog yuav ua li cas xaim txhua lub interface ntawm lub sensor.

Tawm-ntawm-lub thawv, lub rooj tsavxwm tau teeb tsa rau I2C interface, zoo li peb pom zoo siv qhov kev sib txuas no yog tias koj tsis ntseeg lwm yam. Txhua yam koj xav tau yog plaub lub xov hlau!

Tsuas yog plaub qhov kev sib txuas xav tau Vcc, Gnd, SCL thiab SDA tus pin thiab cov no txuas nrog kev pab ntawm I2C cable.

Cov kev sib txuas no tau qhia hauv cov duab saum toj no.

Kauj Ruam 3: Arduino Code rau Kev Ntsuas Kev Ntsuas:

Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas
Arduino Code rau Kev Ntsuas Kev Ntsuas

Cia pib nrog tus lej arduino tam sim no.

Thaum siv lub ntsuas qhov ntsuas nrog arduino, peb suav nrog Wire.h lub tsev qiv ntawv. "Hlau" lub tsev qiv ntawv muaj cov haujlwm uas pab txhawb i2c kev sib txuas lus ntawm lub sensor thiab pawg thawj coj saib arduino.

Tag nrho cov cai arduino tau muab hauv qab no kom yooj yim ntawm cov neeg siv:

#suav nrog

// H3LIS331DL I2C chaw nyob yog 0x18 (24)

#define Ntxiv 0x18

void teeb tsa ()

{

// Pib I2C kev sib txuas lus li MASTER

Hlau.begin ();

// Initialise Serial Communication, teeb baud tus nqi = 9600

Serial.begin (9600);

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv tswj npe 1

Hlau.write (0x20);

// Pab kom X, Y, Z axis, lub zog rau hom, cov ntaub ntawv tso tawm tus nqi 50Hz

Hlau.write (0x27);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv tswj npe 4

Hlau.write (0x23);

// Teeb tsa qhov ntsuas tag nrho, +/- 100g, hloov kho tas li

Hlau.write (0x00);

// Nres I2C Kev Kis

Wire.endTransmission ();

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [6];

rau (int i = 0; i <6; i ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv sau npe

Hlau.write ((40+i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xAccl lsb, xAccl msb, yAccl lsb, yAccl msb, zAccl lsb, zAccl msb

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

ncua (300);

// Hloov cov ntaub ntawv

int xAccl = ((data [1] * 256) + data [0]);

int yAccl = ((cov ntaub ntawv [3] * 256) + cov ntaub ntawv [2]);

int zAccl = ((cov ntaub ntawv [5] * 256) + cov ntaub ntawv [4]);

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("Ua kom nrawm hauv X-Axis:");

Serial.println (xAccl);

Serial.print ("Kev nrawm hauv Y-Axis:");

Serial.println (yAccl);

Serial.print ("Ua kom nrawm hauv Z-Axis:");

Serial.println (zAccl);

ncua (300);

}

Txhua yam koj yuav tsum tau ua yog hlawv cov cai hauv arduino thiab txheeb xyuas koj cov ntawv nyeem ntawm chaw nres nkoj txuas. Qhov tso tawm tau pom hauv daim duab saum toj no.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

Accelerometers zoo li H3LIS331DL feem ntau pom nws daim ntawv thov hauv kev ua si thiab tso saib qhov hloov pauv profile. Qhov ntsuas qhov ntsuas no tseem ua haujlwm hauv kev tswj hwm lub zog zoo rau kev siv mobile. H3LIS331DL yog triaxial digital acceleration sensor uas tau suav nrog lub ntse ntawm-nti cov lus tsa suab cuam tshuam kev tswj hwm.

Pom zoo: