Cov txheej txheem:

Particle Photon - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam
Particle Photon - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam

Video: Particle Photon - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam

Video: Particle Photon - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam
Video: Particle Photon - MPL3115A2 Precision Altimeter Sensor Tutorial 2024, Hlis ntuj nqeg
Anonim
Image
Image

MPL3115A2 ntiav MEMS lub siab ntsuas nrog I2C interface los muab cov ntaub ntawv Siab/Qhov Siab thiab Kub. Cov txiaj ntsig sensor tau digitized los ntawm kev daws teeb meem siab 24-ntsis ADC. Kev ua haujlwm sab hauv tshem tawm cov haujlwm them nyiaj los ntawm tus tswv tsev MCU. Nws muaj peev xwm txheeb xyuas qhov hloov pauv tsuas yog 0.05 kPa uas sib npaug rau 0.3m hloov pauv qhov siab. Nov yog nws qhov ua piv txwv nrog Particle photon.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Particle Photon

2. MPL3115A2

3. I²C Cable

4. I²C Shield rau Particle Photon

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

Nqa daim I2C daim ntaub thaiv rau cov photon me me thiab maj mam thawb nws hla cov pins ntawm cov khoom sib nqus.

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

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

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Cov lej me me rau MPL3115A2 tuaj yeem rub tawm los ntawm peb Github chaw cia khoom-DCUBE Store.

Nov yog qhov txuas.

Peb tau siv ob lub tsev qiv ntawv rau cov lej me me, uas yog application.h thiab spark_wiring_i2c.h. Spark_wiring_i2c lub tsev qiv ntawv xav tau los pab txhawb I2C kev sib txuas lus nrog lub sensor.

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.

NPE 31115A2

// Cov cai no tau tsim los ua haujlwm nrog MPL3115A2_I2CS I2C Mini Module

#suav nrog

#suav nrog

// MPL3115A2 I2C chaw nyob yog 0x60 (96)

#define Ntxiv 0x60

ntab cTemp = 0.0, fTemp = 0.0, siab = 0.0, qhov siab = 0.0;

int temp = 0, tHeight = 0; ntev pres = 0;

void teeb tsa ()

{

// Teem sib txawv

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

Particle.variable ("cTemp", cTemp);

Particle.variable ("siab", siab);

Particle.variable ("qhov siab", qhov siab);

// Pib I2C kev sib txuas lus

Hlau.begin ();

// Initialise Serial Communication, teeb baud tus nqi = 9600

Serial.begin (9600);

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv tswj sau npe

Hlau.write (0x26);

// Hom ua haujlwm, OSR = 128, hom ntsuas ntsuas

Hlau.write (0xB9);

// Nres I2C kev xa mus

Wire.endTransmission ();

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv teeb tsa sau npe

Hlau.write (0x13);

// Cov ntaub ntawv npaj cov xwm txheej tau qhib rau qhov siab, siab, kub

Hlau.write (0x07);

// Nres I2C kev xa mus

Wire.endTransmission ();

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [6];

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv tswj sau npe

Hlau.write (0x26);

// Hom ua haujlwm, OSR = 128, hom ntsuas ntsuas

Hlau.write (0xB9);

// Nres I2C kev xa mus

Wire.endTransmission ();

ncua (1000);

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv sau npe

Hlau.write (0x00);

// Nres I2C kev xa mus

Wire.endTransmission ();

// Thov 6 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 6);

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

// xwm txheej, tHeight msb1, tHeight msb, tHeight lsb, temp msb, tem 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 ();

}

// Hloov cov ntaub ntawv mus rau 20-ntsis

tHeight = (((ntev) cov ntaub ntawv [1] * (ntev) 65536) + (cov ntaub ntawv [2] * 256) + (cov ntaub ntawv [3] & 0xF0)) / 16);

temp = ((cov ntaub ntawv [4] * 256) + (data [5] & 0xF0)) / 16;

qhov siab = tHeight / 16.0;

cTemp = (temp / 16.0);

fTemp = cTemp * 1.8 + 32;

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv tswj sau npe

Hlau.write (0x26);

// Hom ua haujlwm, OSR = 128, hom ntsuas cua

Hlau.write (0x39);

// Nres I2C kev xa mus

Wire.endTransmission ();

// Pib I2C kis tau tus mob

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv sau npe

Hlau.write (0x00);

// Nres I2C kev xa mus

Wire.endTransmission ();

ncua (1000);

// Thov 4 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 4);

// Nyeem 4 bytes ntawm cov ntaub ntawv

// xwm txheej, pres msb1, pres msb, pres lsb

yog (Wire.available () == 4)

{

cov ntaub ntawv [0] = Wire.read ();

cov ntaub ntawv [1] = Wire.read ();

cov ntaub ntawv [2] = Wire.read ();

cov ntaub ntawv [3] = Wire.read ();

}

// Hloov cov ntaub ntawv mus rau 20-ntsis

pres = (((ntev) cov ntaub ntawv [1] * (ntev) 65536) + (cov ntaub ntawv [2] * 256) + (cov ntaub ntawv [3] & 0xF0)) / 16;

siab = (pres / 4.0) / 1000.0;

// Tso tawm cov ntaub ntawv rau dashboard

Particle.publish ("Qhov siab:", Txoj hlua (qhov siab));

Particle.publish ("Siab:", Txoj hlua (siab));

Particle.publish ("Kub hauv Celsius:", String (cTemp));

Particle.publish ("Kub hauv Fahrenheit:", String (fTemp));

ncua (1000);

}

Kauj Ruam 4: Cov ntawv thov:

Kev siv ntau yam ntawm MPL3115A2 suav nrog Kev Raug Siab Tshaj Plaws, Smartphones/Tablets, Kev Siv Hluav Taws Xob Tus Kheej thiab lwm yam.

Pom zoo: