Cov txheej txheem:

Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Arduino Nano: 4 Cov Kauj Ruam
Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Kev Ntsuas Hluav Taws Xob Siv HMC5883 thiab Arduino Nano: 4 Cov Kauj Ruam
Video: Qhia txuas xaim hluav taws xob daim: 02 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 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. HMC5883

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:

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: Arduino Code los ntsuas Sib Nqus Sib Nqus:

Arduino Code los Ntsuas Kev Sib Nqus Sib Raug Zoo
Arduino Code los Ntsuas Kev Sib Nqus Sib Raug Zoo
Arduino Code los Ntsuas Kev Sib Nqus Sib Raug Zoo
Arduino Code los Ntsuas Kev Sib Nqus Sib Raug Zoo

Cia peb pib nrog Arduino code tam sim no.

Thaum siv lub ntsuas 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 Arduino board.

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

#suav nrog

// HMC5883 I2C chaw nyob yog 0x1E (30)

#define Ntxiv 0x1E

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 configure register A.

Hlau.write (0x00);

// Teeb tsa kev ntsuas ntsuas ib txwm muaj, cov ntaub ntawv tso tawm tus nqi = 0.75Hz

Hlau.write (0x60);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv hom sau npe

Hlau.write (0x02);

// Teeb ntsuas ntsuas tas mus li

Hlau.write (0x00);

// Nres I2C Kev Kis

Wire.endTransmission ();

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [6];

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv sau npe

Hlau.write (0x03);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 6 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 6);

// Nyeem 6 bytes ntawm cov ntaub ntawv

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

yog (Wire.available () == 6)

{

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

}

ncua (300);

// Hloov cov ntaub ntawv

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

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

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

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("Teb Sib nqus hauv X-Axis:");

Serial.println (xMag);

Serial.print ("Teb Sib nqus hauv Y-Axis:");

Serial.println (yMag);

Serial.print ("Teb Sib nqus hauv Z-Axis:");

Serial.println (zMag);

ncua (300);

}

Hauv cov tsev qiv ntawv xaim Wire.write () thiab Wire.read () yog siv los sau cov lus txib thiab nyeem cov ntawv tso tawm. Ua raws ib feem ntawm txoj cai qhia txog kev nyeem ntawv ntawm cov zis sensor.

// Nyeem 6 bytes ntawm cov ntaub ntawv // xMag msb, xMag lsb, zMag msb, zMag lsb, yMag msb, yMag lsb yog (Wire.available () == 6) {data [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 (); }

Serial.print () thiab Serial.println () yog siv los tso saib cov zis ntawm lub sensor ntawm cov saib xyuas ntawm Arduino IDE.

Qhov tso tawm ntawm lub ntsuas hluav taws xob tau qhia 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: