Cov txheej txheem:

Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Java Qhia: 4 Kauj Ruam
Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Java Qhia: 4 Kauj Ruam
Video: Raspberry Pi CPS120 Pressure & Temperature Sensor Java Tutorial 2024, Kaum ib hlis
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 raspberry pi siv java code.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. MPL3115A2

3. I²C Cable

4. I²C Shield rau Raspberry Pi

5. Ethernet Cable

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 raspberry pi thiab maj mam thawb nws hla gpio pins ntawm raspberry pi.

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

Kuj txuas Ethernet cable rau pi lossis koj tuaj yeem siv WiFi module.

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

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Tus lej java 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/tree/master/Java

Peb tau siv pi4j tsev qiv ntawv rau java code, cov kauj ruam rau nruab pi4j ntawm raspberry pi tau piav qhia ntawm no:

pi4j.com/install.html

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 muaj los ntawm

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice;

ntshuam com.pi4j.io.i2c. I2CFactory;

ntshuam java.io. IOException;

pej xeem chav kawm MPL3115A2

{

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, MPL3115A2 I2C chaw nyob yog 0x60 (96)

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

// Xaiv tswj sau npe

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

device.write (0x26, (byte) 0xB9);

// Xaiv cov ntaub ntawv teeb tsa sau npe

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

ntaus ntawv.write (0x13, (byte) 0x07);

// Xaiv tswj sau npe

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

device.write (0x26, (byte) 0xB9);

Xov.sleep (1000);

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

byte cov ntaub ntawv = tshiab byte [6];

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

// Hloov cov ntaub ntawv mus rau 20-ntsis

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

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

ob qhov siab = tHeight / 16.0;

ob cTemp = (temp / 16.0);

ob fTemp = cTemp * 1.8 + 32;

// Xaiv tswj sau npe

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

ntaus ntawv.write (0x26, (byte) 0x39);

Xov.sleep (1000);

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

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

device.read (0x00, cov ntaub ntawv, 0, 4);

// Hloov cov ntaub ntawv mus rau 20-ntsis

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

ob npaug siab = (pres / 4.0) / 1000.0;

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Siab: %.2f kPa %n", siab);

System.out.printf ("Qhov siab: %.2f m %n", qhov siab);

System.out.printf ("Kub hauv Celsius: %.2f C %n", cTemp);

System.out.printf ("Kub hauv Fahrenheit: %.2f F %n", fTemp);

}

}

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: