Cov txheej txheem:

Kev cuam tshuam ntawm 3-Axis Gyroscope Sensor BMG160 Nrog Raspberry Pi: 5 Kauj Ruam
Kev cuam tshuam ntawm 3-Axis Gyroscope Sensor BMG160 Nrog Raspberry Pi: 5 Kauj Ruam

Video: Kev cuam tshuam ntawm 3-Axis Gyroscope Sensor BMG160 Nrog Raspberry Pi: 5 Kauj Ruam

Video: Kev cuam tshuam ntawm 3-Axis Gyroscope Sensor BMG160 Nrog Raspberry Pi: 5 Kauj Ruam
Video: 3-5-22 keeb kwm ntawm Russian thiab Soviet Union 2024, Hlis ntuj nqeg
Anonim
Image
Image

Hauv lub ntiaj teb niaj hnub no, ntau dua ib nrab ntawm cov tub ntxhais hluas thiab menyuam yaus nyiam ua si thiab txhua tus neeg uas nyiam nws, txaus siab los ntawm cov txuj ci ntawm kev ua si paub qhov tseem ceeb ntawm kev nkag siab zoo hauv qhov no. Peb kuj tseem xav tsis thoob los ntawm tib yam thiab tsuas yog coj nws mus rau ntawm cov laug cam, peb xav txog kev ua haujlwm ntawm lub ntsuas hluav taws xob ntsuas hluav taws xob uas tuaj yeem ntsuas tus nqi ib leeg ntawm ib yam khoom. Yog li, lub ntsuas ntsuas peb tau coj los daws cov haujlwm yog BMG160. BMG160 yog 16-ntsis, digital, triaxial, gyroscope sensor uas tuaj yeem ntsuas tus lej nyob hauv peb chav nyob ib puag ncig.

Hauv qhov kev qhia no, peb yuav los qhia txog kev ua haujlwm ntawm BMG160 nrog Raspberry pi, siv Java ua cov lus programming.

Kho vajtse uas koj yuav xav tau rau lub hom phiaj no yog raws li hauv qab no:

1. BMG160

2. Raspberry Pi

3. I2C Cable

4. I2C Shield rau Raspberry Pi

5. Ethernet Cable

Kauj Ruam 1: BMG160 Txheej Txheem:

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

Ua ntej tshaj plaws peb xav paub koj nrog cov yam ntxwv tseem ceeb ntawm lub ntsuas qhov ntsuas uas yog BMG160 thiab cov txheej txheem kev sib txuas lus uas nws ua haujlwm.

BMG160 yog qhov tseem ceeb 16-ntsis, digital, triaxial, gyroscope sensor uas tuaj yeem ntsuas tus nqi kaum. Nws muaj peev xwm suav tus lej nyob hauv peb chav nyob ib puag ncig, x-, y- thiab z-axis, thiab muab cov cim teeb tsa sib xws. Nws tuaj yeem sib tham nrog raspberry pi board siv I2C kev sib txuas lus raws tu qauv. Cov qauv tshwj xeeb no tau tsim los kom tau raws li qhov xav tau rau cov neeg siv khoom siv nrog rau lub hom phiaj kev lag luam.

Cov txheej txheem kev sib txuas lus uas lub sensor ua haujlwm yog I2C. I2C sawv cev rau kev sib koom ua ke. Nws yog cov txheej txheem kev sib txuas lus uas kev sib txuas lus tau tshwm sim los ntawm SDA (cov ntaub ntawv xov xwm) thiab SCL (cov xov tooj). Nws tso cai txuas ntau yam khoom siv tib lub sijhawm. Nws yog ib qho ntawm cov txheej txheem kev sib txuas lus yooj yim tshaj plaws thiab muaj txiaj ntsig tshaj plaws.

Kauj Ruam 2: Yam Koj Xav Tau..

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

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

1. BMG160

2. Raspberry Pi

3. I2C Cable

4. I2C Shield Rau Raspberry Pi

5. Ethernet Cable

Kauj Ruam 3: Khoos Phis Tawj Hookup:

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 ntsuas cua thiab raspberry pi. 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:

BMG160 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 4: 3-Axis Gyroscope Measurement Siv Java Code:

3-Axis Gyroscope Ntsuas Siv Java Code
3-Axis Gyroscope Ntsuas Siv Java Code
3-Axis Gyroscope Ntsuas Siv Java Code
3-Axis Gyroscope Ntsuas Siv Java Code

Qhov zoo ntawm kev siv raspberry pi yog, uas yog muab rau koj qhov kev hloov pauv ntawm cov lus programming uas koj xav tau los teeb tsa lub rooj tsav xwm txhawm rau txhawm rau cuam tshuam lub sensor nrog nws. Kev siv cov txiaj ntsig zoo ntawm pawg thawj coj no, peb tab tom qhia ntawm no nws txoj haujlwm hauv Java. Java code rau BMG160 tuaj yeem rub tawm los ntawm peb lub zej zog github uas yog Dcube Store Community.

Ntxiv rau qhov yooj yim ntawm cov neeg siv, peb tab tom piav qhia cov cai ntawm no ib yam nkaus: Raws li thawj kauj ruam ntawm kev coding koj yuav tsum rub tawm lub tsev qiv ntawv pi4j thaum java, vim hais tias lub tsev qiv ntawv no txhawb nqa cov haujlwm siv hauv txoj cai. Yog li, txhawm rau rub lub tsev qiv ntawv koj tuaj yeem mus ntsib qhov txuas hauv qab no:

pi4j.com/install.html

Koj tuaj yeem luam qhov ua haujlwm java code rau lub ntsuas no los ntawm no kuj:

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 BMG160

{

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 txais I2C ntaus ntawv, BMG160 I2C chaw nyob yog 0x68 (104)

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

// Xaiv thaj tsam sau npe

// Kho qhov ntsuas ntau, 2000 dps

device.write (0x0F, (byte) 0x80);

// Xaiv bandwidth rau npe

// Bandwidth 200 Hz

device.write (0x10, (byte) 0x04);

Xov.sleep (500);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xGyro lsb, xGyro msb, yGyro lsb, yGyro msb, zGyro lsb, zGyro msb

byte cov ntaub ntawv = tshiab byte [6];

device.read (0x02, cov ntaub ntawv, 0, 6);

// Hloov cov ntaub ntawv

int xGyro = ((data [1] & 0xFF) * 256 + (data [0] & 0xFF));

yog (xGyro> 32767)

{

xGyro -= 65536;

}

int yGyro = ((cov ntaub ntawv [3] & 0xFF) * 256 + (data [2] & 0xFF));

yog (yGyro> 32767)

{

yGyro -= 65536;

}

int zGyro = ((cov ntaub ntawv [5] & 0xFF) * 256 + (cov ntaub ntawv [4] & 0xFF));

yog (zGyro> 32767)

{

zGyro -= 65536;

}

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("X-Axis ntawm kev sib hloov: %d %n", xGyro);

System.out.printf ("Y-axis ntawm kev sib hloov: %d %n", yGyro);

System.out.printf ("Z-axis ntawm kev sib hloov: %d %n", zGyro);

}

}

Lub tsev qiv ntawv uas txhawb nqa i2c kev sib txuas lus ntawm lub sensor thiab pawg thawj coj yog pi4j, nws ntau pob khoom I2CBus, I2CDevice thiab I2CFactory pab tsim kom muaj kev sib txuas.

ntshuam com.pi4j.io.i2c. I2CBus; ntshuam com.pi4j.io.i2c. I2CDevice; ntshuam com.pi4j.io.i2c. I2CFactory; ntshuam java.io. IOException;

Ib feem ntawm txoj cai no ua rau lub ntsuas ntsuas ntsuas tus lej los ntawm kev sau cov lus txib tshwj xeeb uas siv sau () ua haujlwm thiab tom qab ntawd cov ntaub ntawv raug nyeem siv siv nyeem () ua haujlwm.

// Xaiv ntau yam rau npe // Kho kom raug ntau qhov ntau, 2000 dps device.write (0x0F, (byte) 0x80); // Xaiv bandwidth register // Bandwidth 200 Hz device.write (0x10, (byte) 0x04); Xov.sleep (500);

// Nyeem 6 bytes ntawm cov ntaub ntawv

// xGyro lsb, xGyro msb, yGyro lsb, yGyro msb, zGyro lsb, zGyro msb byte cov ntaub ntawv = tshiab byte [6]; device.read (0x02, cov ntaub ntawv, 0, 6);

Cov ntaub ntawv tau txais los ntawm lub ntsuas hluav taws xob tau hloov pauv mus rau qhov tsim nyog siv los ntawm kev siv cov hauv qab no:

int xGyro = ((cov ntaub ntawv [1] & 0xFF) * 256 + (data [0] & 0xFF)); yog (xGyro> 32767) {xGyro -= 65536; } int yGyro = ((cov ntaub ntawv [3] & 0xFF) * 256 + (data [2] & 0xFF)); yog (yGyro> 32767) {yGyro -= 65536; } int zGyro = ((data [5] & 0xFF) * 256 + (data [4] & 0xFF)); yog (zGyro> 32767) {zGyro -= 65536; }

Cov zis tau luam tawm siv System.out.println () ua haujlwm, hauv cov qauv hauv qab no.

System.out.println ("X-Axis ntawm Kev Hloov: %d %n", xGyro); System.out.println ("Y-axis ntawm Kev Hloov: %d %n", yGyro); System.out.println ("Z-axis ntawm Kev Sib Hloov: %d %n", zGyro);

Qhov tso tawm ntawm lub ntsuas hluav taws xob tau qhia hauv daim duab saum toj no.

Kauj Ruam 5: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

BMG160 muaj ntau qhov kev thov hauv cov khoom siv xws li xov tooj ntawm tes, tib neeg siv tshuab sib txuas. Qhov ntsuas qhov ntsuas no tau tsim los kom tau raws li qhov xav tau rau cov neeg siv khoom siv xws li kev ruaj ntseg duab (DSC thiab lub koob yees duab-xov tooj), kev ua si thiab taw tes. Nws kuj tseem ua haujlwm hauv cov kab ke uas xav tau kev paub piav tes piav taw thiab cov kab ke siv hauv kev qhia sab hauv tsev.

Pom zoo: