Cov txheej txheem:

Raspberry Pi MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Java Qhia: 4 Kauj Ruam
Raspberry Pi MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi MMA8452Q 3-Axis 12-ntsis/8-ntsis Digital Accelerometer Java Qhia: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
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 piv txwv nrog raspberry pi siv java code.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. MMA8452Q

3. I²C Cable

4. I²C Shield rau Raspberry Pi

5. Ethernet Cable

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 raspberry pi thiab maj mam thawb nws hla gpio pins ntawm raspberry pi.

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

Kuj txuas Ethernet cable rau pi lossis koj tuaj yeem siv WiFi module.

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

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Java code rau MMA8452Q tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/MMA8452Q

Peb tau siv pi4j tsev qiv ntawv rau java code, cov kauj ruam rau nruab pi4j ntawm raspberry pi tau piav qhia ntawm no:

pi4j.com/install.html

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 muaj nyob hauv Dcube Store.

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice;

ntshuam com.pi4j.io.i2c. I2CFactory;

ntshuam java.io. IOException;

pej xeem chav kawm MMA8452Q

{

pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua args ) cuam tshuam zam

{

// Tsim I2C npav

I2CBus tsheb npav = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau I2C ntaus ntawv, MMA8452Q I2C chaw nyob yog 0x1C (28)

I2CDevice ntaus ntawv = bus.getDevice (0x1C);

// Xa cov lus txib tos

ntaus ntawv.write (0x2A, (byte) 0x00);

// Xa cov lus txib nquag

ntaus ntawv.write (0x2A, (byte) 0x01);

// Teeb tsa ntau txog +/- 2g

device.write (0x0E, (byte) 0x00);

Xov.sleep (500);

// Nyeem 7 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x00 (0)

// Qhov xwm txheej, X msb, X lsb, Y msb, Y lsb, Z msb, Z lsb

byte cov ntaub ntawv = tshiab byte [7];

device.read (0x00, cov ntaub ntawv, 0, 7);

// Hloov qhov tseem ceeb

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

yog (xAccl> 2047)

{

xAccl = xAccl - 4096;

}

int yAccl = (((data [3] & 0xFF) * 256) + (data [4] & 0xFF)) / 16;

yog (yAccl> 2047)

{

yAccl = yAccl - 4096;

}

int zAccl = (((data [5] & 0xFF) * 256) + (data [6] & 0xFF)) / 16;

yog (zAccl> 2047)

{

zAccl = zAccl - 4096;

}

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("X-Axis: %d %n", xAccl);

System.out.printf ("Y-Axis: %d %n", yAccl);

System.out.printf ("Z-Axis: %d %n", zAccl);

}

}

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: