Cov txheej txheem:

Kev Ntsuas Kev Ntsuas Siv BMA250 thiab Particle Photon: 4 Kauj Ruam
Kev Ntsuas Kev Ntsuas Siv BMA250 thiab Particle Photon: 4 Kauj Ruam

Video: Kev Ntsuas Kev Ntsuas Siv BMA250 thiab Particle Photon: 4 Kauj Ruam

Video: Kev Ntsuas Kev Ntsuas Siv BMA250 thiab Particle Photon: 4 Kauj Ruam
Video: Xwm Kab Yog Dab Tsi?: Hmoob Nkag Siab Yuam Kev Tag Lawm 2024, Hlis ntuj nqeg
Anonim
Image
Image

BMA250 yog qhov me me, nyias, lub zog loj, 3-axis accelerometer nrog kev ntsuas siab (13-ntsis) ntsuas txog li g 16 g. Cov ntaub ntawv tso tawm digital yog ua raws li 16-ntsis twos ua tiav thiab siv tau los ntawm I2C digital interface. Nws ntsuas qhov kev nrawm nrawm ntawm lub ntiajteb txawj nqus hauv kev thov qaij-nkag siab, nrog rau kev nrawm nrawm los ntawm kev txav lossis poob siab. Nws qhov kev daws teeb meem siab (3.9 mg/LSB) ua rau ntsuas ntsuas qhov xav tau hloov qis dua 1.0 °.

Hauv qhov kev qhia no peb yuav ntsuas qhov nrawm hauv txhua qhov peb kab sib dhos uas siv BMA250 thiab Particle photon.

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. BMA250

2. Particle Photon

3. I2C Cable

4. I2C Shield rau Particle Photon

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 txuas uas xav tau ntawm lub sensor thiab cov duab photon. 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:

BMA250 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: Txoj Cai los Ntsuas Kev Ua Haujlwm:

Txoj Cai los Ntsuas Kev Ua Haujlwm
Txoj Cai los Ntsuas Kev Ua Haujlwm

Cia peb pib nrog cov lej me me tam sim no.

Thaum siv lub ntsuas qhov ntsuas nrog arduino, peb suav nrog application.h thiab lub tsev qiv ntawv spark_wiring_i2c.h. "application.h" thiab lub tsev qiv ntawv spark_wiring_i2c.h muaj cov haujlwm uas pab txhawb kev sib txuas lus i2c ntawm lub sensor thiab cov khoom me me.

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

#suav nrog

#suav nrog

// BMA250 I2C chaw nyob yog 0x18 (24)

#define Ntxiv 0x18

int xAccl = 0, yAccl = 0, zAccl = 0;

void teeb tsa ()

{

// Teem sib txawv

Particle.variable ("i2cdevice", "BMA250");

Particle.variable ("xAccl", xAccl);

Particle.variable ("yAccl", yAccl);

Particle.variable ("zAccl", zAccl);

// Pib I2C kev sib txuas lus li MASTER

Hlau.begin ();

// Pib kev sib txuas lus txuas, teeb tsa tus nqi = 9600

Serial.begin (9600);

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv thaj tsam xaiv sau npe

Hlau.write (0x0F);

// Teeb tsa ntau yam +/- 2g

Hlau.write (0x03);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv bandwidth rau npe

Hlau.write (0x10);

// Teeb bandwidth 7.81 Hz

Hlau.write (0x08);

// Nres I2C Kev Kis

Wire.endTransmission ();

ncua (300);}

void lub voj ()

{

unsigned int cov ntaub ntawv [0];

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv Cov Ntaub Ntawv Sau Npe (0x02 - 0x07)

Hlau.write (0x02);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 6 bytes

Wire.requestFrom (Addr, 6);

// Nyeem rau rau bytes

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

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 mus rau 10 khoom

xAccl = ((data [1] * 256) + (data [0] & 0xC0)) / 64;

yog (xAccl> 511)

{

xAccl -= 1024;

}

yAccl = ((data [3] * 256) + (data [2] & 0xC0)) / 64;

yog (yAccl> 511)

{

yAccl -= 1024;

}

zAccl = ((data [5] * 256) + (data [4] & 0xC0)) / 64;

yog (zAccl> 511)

{

zAccl -= 1024;

}

// Tso tawm cov ntaub ntawv rau dashboard

Particle.publish ("Acceleration in X-Axis:", String (xAccl));

ncua (1000);

Particle.publish ("Acceleration in Y-Axis:", String (yAccl));

ncua (1000);

Particle.publish ("Acceleration in Z-Axis:", String (zAccl));

ncua (1000);

}

Particle.variable () muaj nuj nqi tsim cov kev hloov pauv kom khaws cov zis tawm ntawm lub sensor thiab Particle.publish () muaj nuj nqi qhia cov zis ntawm lub dashboard ntawm lub xaib.

Cov zis sensor tau pom hauv daim duab saum toj no rau koj siv.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

Accelerometers zoo li BMA250 feem ntau pom nws daim ntawv thov hauv kev ua si thiab tso saib cov ntaub ntawv hloov pauv. Qhov ntsuas qhov ntsuas no tseem ua haujlwm hauv kev tswj hwm lub zog zoo rau kev siv mobile. BMA250 yog lub triaxial digital acceleration sensor uas tau koom nrog nrog kev txawj ntse ntawm-nti cov lus tsa suab cuam tshuam kev tswj hwm.

Pom zoo: