Cov txheej txheem:

Arduino Nano-MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Tutorial: 4 Kauj Ruam
Arduino Nano-MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Tutorial: 4 Kauj Ruam

Video: Arduino Nano-MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Tutorial: 4 Kauj Ruam

Video: Arduino Nano-MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Tutorial: 4 Kauj Ruam
Video: Accelerometer controled Three-axis platofrm on Arduino 2024, Kaum ib hlis
Anonim
Image
Image

MMA8452Q yog lub ntse, lub zog qis, peb-axis, muaj peev xwm, lub tshuab ntsuas hluav taws xob micromachined nrog 12 qhov kev daws teeb meem. Cov neeg siv hloov pauv tau cov kev xaiv ua haujlwm tau muab nrog kev pab cuam ntawm lub zog ua haujlwm hauv lub nrawm, teeb tsa tau rau ob qho cuam tshuam tus pin. Nws muaj cov neeg siv xaiv tau cov nplai ntawm g 2g/± 4g/± 8g nrog cov qib siab lim lim cov ntaub ntawv nrog rau cov ntaub ntawv tsis lim dej muaj lub sijhawm tiag. Nov yog nws qhov ua qauv qhia nrog Arduino nano.

Kauj Ruam 1: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Arduino Nano

2. MMA8452Q

3. I²C Cable

4. I²C Shield rau Arduino Nano

Kauj Ruam 2: Kev Sib Txuas:

Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas

Siv daim I2C daim thaiv rau Arduino Nano thiab maj mam thawb nws hla tus pin ntawm Nano.

Tom qab ntawd txuas ib kawg ntawm I2C cable rau MMA8452Q sensor thiab lwm qhov kawg rau I2C daim ntaub thaiv.

Kev sib txuas tau qhia hauv daim duab saum toj no.

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Tus lej arduino rau MMMA8452Q tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github- DCUBE Store.

Nov yog qhov txuas.

Peb suav nrog tsev qiv ntawv Wire.h los pab txhawb I2c kev sib txuas lus ntawm lub sensor nrog Arduino board.

Koj tseem tuaj yeem luam cov cai los ntawm no, nws tau muab raws li hauv qab no:

// Faib nrog daim ntawv tso cai yuav dawb.

// Siv nws txhua txoj hauv kev uas koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm ua haujlwm.

// MMA8452Q

// Tus lej no yog tsim los ua haujlwm nrog MMA8452Q_I2CS I2C Mini Module.

#suav nrog

// MMA8452Q I2C chaw nyob yog 0x1C (28)

#define Ntxiv 0x1C

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 sau npe

Hlau.write (0x2A);

// StandBy hom

Hlau.write (0x00);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv tswj sau npe

Hlau.write (0x2A);

// Hom nquag

Hlau.write (0x01);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv tswj sau npe

Hlau.write (0x0E);

// Teeb tsa kom +/- 2g

Hlau.write (0x00);

// Nres I2C Kev Kis

Wire.endTransmission ();

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [7];

// Thov 7 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 7);

// Nyeem 7 bytes ntawm cov ntaub ntawv

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

yog (Wire.available () == 7)

{

cov ntaub ntawv [0] = Wire.read ();

cov ntaub ntawv [1] = Wire.read ();

cov ntaub ntawv [2] = Wire.read ();

cov ntaub ntawv [3] = Wire.read ();

cov ntaub ntawv [4] = Wire.read ();

cov ntaub ntawv [5] = Wire.read ();

cov ntaub ntawv [6] = Wire.read ();

}

// Hloov cov ntaub ntawv mus rau 12-ntsis

int xAccl = ((data [1] * 256) + data [2]) / 16;

yog (xAccl> 2047)

{

xAccl -= 4096;

}

int yAccl = ((cov ntaub ntawv [3] * 256) + cov ntaub ntawv [4]) / 16;

yog (yAccl> 2047)

{

yAccl -= 4096;

}

int zAccl = ((cov ntaub ntawv [5] * 256) + cov ntaub ntawv [6]) / 16;

yog (zAccl> 2047)

{

zAccl -= 4096;

}

// 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 (500);

}

Kauj Ruam 4: Cov ntawv thov:

MMA8452Q muaj ntau daim ntawv thov suav nrog E-Compass applications, Static orientation detection uas koom nrog Portrait/Landscape, Up/Down, Left/Right, Back/Front position identification, Notebook, e-reader, and Laptop Tumble and Freefall Detection, Real-time kev txheeb xyuas kev taw qhia suav nrog kev muaj tiag virtual thiab kev ua si 3D cov neeg siv txoj haujlwm tawm tswv yim, Kev tshuaj xyuas lub sijhawm tiag tiag xws li kev ntsuas tus lej ntsuas, ntsuas kev poob qis rau HDD, tuag-suav nrog GPS thaub qab thiab ntau ntxiv.

Pom zoo: