Cov txheej txheem:

Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Raspberry Pi: 4 Cov Kauj Ruam
Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Raspberry Pi: 4 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image

HMC5883 yog lub ntsuas hluav taws xob digital tsim los rau kev tshawb fawb qis hauv ntiaj teb. Cov cuab yeej no muaj ntau yam sib nqus sib nqus ntawm +/- 8 Oe thiab qhov tso tawm ntawm 160 Hz. HMC5883 lub ntsuas suav nrog kev siv lub pluaj tsis siv neeg lub pluaj tsav tsheb, tshem tawm kev tshem tawm, thiab 12-ntsis ADC uas ua rau 1 ° txog 2 ° ntsuas qhov ntsuas qhov tseeb. Txhua I²C Mini Modules tau tsim los ua haujlwm ntawm 5VDC.

Hauv qhov kev qhia no, peb yuav piav qhia ntxaws txog kev ua haujlwm ntawm HMC5883 nrog Raspberry pi thiab nws txoj haujlwm siv java programming lus.

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

Kho vajtse uas yuav tsum tau ua kom tiav txoj haujlwm yog raws li hauv qab no:

1. HMC5883

2. Raspberry Pi

3. I2C Cable

4. I2C Shield Rau Raspberry Pi

5. Ethernet Cable

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 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:

HMC5883 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: Java Code los Ntsuas Qhov Sib Nqus Sib Haum:

Java Code txhawm rau Ntsuas Sib nqus Sib Cais
Java Code txhawm rau Ntsuas Sib nqus Sib Cais
Java Code txhawm rau Ntsuas Sib nqus Sib Cais
Java Code txhawm rau Ntsuas Sib nqus Sib Cais

Qhov zoo ntawm kev siv raspberry pi yog, uas muab rau koj 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 no, peb tab tom qhia ntawm no nws tau ua haujlwm hauv Java. Tus lej java rau HMC5883 tuaj yeem rub tawm los ntawm peb cov zej zog github uas yog Dcube Store.

Ntxiv rau qhov yooj yim ntawm cov neeg siv, peb tab tom piav qhia cov cai ntawm no thiab:

Raws li thawj kauj ruam ntawm kev sau npe, koj yuav tsum rub lub pi4j lub tsev qiv ntawv hauv java, vim 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;

mport com.pi4j.io.i2c. I2CFactory;

ntshuam java.io. IOException; pej xeem hauv chav kawm HMC5883

{

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

{

// Tsim I2C npav

I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau txais I2C ntaus ntawv, HMC5883 I2C chaw nyob yog 0x1E (30)

I2CDevice ntaus ntawv = Bus.getDevice (0x1E);

// Xaiv Configuration register A.

// Kev ntsuas ntsuas ib txwm muaj, cov ntaub ntawv tus nqi o/p = 0.75 Hz

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

// Xaiv hom sau npe

// Nruam ntsuas hom

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

Xov.sleep (500);

// Nyeem 6 bytes ntawm cov ntaub ntawv los ntawm 0x03 (3)

// xMag msb, xMag lsb, zMag msb, zMag lsb, yMag msb, yMag lsb

byte cov ntaub ntawv = tshiab byte [6];

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

// Hloov cov ntaub ntawv

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

yog (xMag> 32767)

{

xMag -= 65536;

}

int zMag = ((data [2] & 0xFF) * 256 + (data [3] & 0xFF));

yog (zMag> 32767)

{

zMag -= 65536;

}

int yMag = ((data [4] & 0xFF) * 256 + (data [5] & 0xFF));

yog (yMag> 32767)

{

yMag -= 65536;

}

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Sib nqus teb hauv X-Axis: %d %n", xMag);

System.out.printf ("Sib nqus teb hauv Y-Axis: %d %n", yMag);

System.out.printf ("Sib nqus teb hauv Z-Axis: %d %n", zMag);

}

}

Sau () thiab nyeem () ua haujlwm tau siv los sau cov lus txib thiab nyeem cov ntawv tso tawm ua ntu zus. Ib feem hauv qab no qhia txog kev nyeem qhov tseem ceeb ntawm kev sib nqus.

// Nyeem 6 bytes ntawm cov ntaub ntawv los ntawm 0x03 (3)

// xMag msb, xMag lsb, zMag msb, zMag lsb, yMag msb, yMag lsb

byte cov ntaub ntawv = tshiab byte [6];

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

Cov zis tau pom hauv daim duab saum toj no.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

HMC5883 yog qhov ua haujlwm saum npoo av, ntau txheej txheej tsim rau kev sib nqus hauv ntiaj teb pom nrog lub ntsej muag digital rau cov ntawv thov xws li tus nqi qis thiab kev ntsuas hluav taws xob. Nws ib txog rau ob qib qib qib raug thiab qhov tseeb ua rau Cov Neeg taug Kev Taw Qhia thiab LBS Cov Ntawv Thov.

Pom zoo: