Cov txheej txheem:

Arduino Nano - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam
Arduino Nano - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam

Video: Arduino Nano - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam

Video: Arduino Nano - MPL3115A2 Precision Altimeter Sensor Tutorial: 4 Kauj Ruam
Video: MS5611 Barometer/Altimeter Tutorial with Arduino || BME280 vs MS5611 Comparison 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 qauv qhia nrog Arduino Nano.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Arduino Nano

2. MPL3115A2

3. I²C Cable

4. I²C Shield rau Arduino Nano

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

Siv daim I2C daim thaiv rau Arduino Nano thiab maj mam thawb nws hla tus pin ntawm Nano.

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

Tus lej arduino rau MPL3115A2 tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github-DCUBE Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/MPL3115A2/blob/master/Arduino/MPL3115A2.ino

Peb suav nrog tsev qiv ntawv Wire.h los pab txhawb I2c kev sib txuas lus ntawm lub sensor nrog Arduino board.

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

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

#define Ntxiv 0x60

void teeb tsa ()

{

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

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

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

ntab qhov siab = tHeight / 16.0;

ntab cTemp = (temp / 16.0);

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

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

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

ntab siab = (pres / 4.0) / 1000.0;

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("Qhov siab:");

Serial.print (qhov siab);

Serial.println ("m");

Serial.print ("Siab:");

Serial.print (siab);

Serial.println ("kPa");

Serial.print ("Kub hauv Celsius:");

Serial.print (cTemp);

Serial.println ("C");

Serial.print ("Kub hauv Fahrenheit:");

Serial.print (fTemp);

Serial.println ("F");

ncua (500);

}

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: