Cov txheej txheem:

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

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

Video: Raspberry Pi - MPL3115A2 Precision Altimeter Sensor Python Qhia: 4 Kauj Ruam
Video: Raspberry Pi MPL3115A2 Precision Altimeter Sensor Python 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 raspberry pi siv tus lej nab npawb.

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 nab npawb nab npawb rau MPL3115A2 tuaj yeem rub tawm los ntawm peb Github chaw cia khoom- DCUBE Store Community.

Nov yog qhov txuas

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

pypi.python.org/pypi/smbus-cffi/0.5.1

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 sib txuam.

# MPL3115A2

# Txoj cai no yog tsim los ua haujlwm nrog MPL3115A2_I2CS I2C Mini Module

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv tswj npe, 0x26 (38)

# 0xB9 (185) Hom ua haujlwm, OSR = 128, Hom Altimeter

bus.write_byte_data (0x60, 0x26, 0xB9)

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv cov ntaub ntawv teeb tsa sau npe, 0x13 (19)

# 0x07 (07) Cov ntaub ntawv npaj tau tshwm sim qhib rau qhov siab, siab, kub

bus.write_byte_data (0x60, 0x13, 0x07)

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv tswj npe, 0x26 (38)

# 0xB9 (185) Hom ua haujlwm, OSR = 128, Hom Altimeter

bus.write_byte_data (0x60, 0x26, 0xB9)

sijhawm.sleep (1)

# MPL3115A2 chaw nyob, 0x60 (96)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x00 (00), 6 bytes

# xwm txheej, lub siab MSB1, lub siab MSB, lub siab LSB, lub sijhawm MSB, lub sijhawm LSB

cov ntaub ntawv = bus.read_i2c_block_data (0x60, 0x00, 6)

# Hloov cov ntaub ntawv mus rau 20-ntsis

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

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

qhov siab = tHeight / 16.0

cTemp = qhov kub / 16.0

fTemp = cTemp * 1.8 + 32

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv tswj npe, 0x26 (38)

# 0x39 (57) Hom ua haujlwm, OSR = 128, Hom ntsuas cua

bus.write_byte_data (0x60, 0x26, 0x39)

sijhawm.sleep (1)

# MPL3115A2 chaw nyob, 0x60 (96)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x00 (00), 4 bytes

# xwm txheej, pres MSB1, pres MSB, pres LSB

cov ntaub ntawv = bus.read_i2c_block_data (0x60, 0x00, 4)

# Hloov cov ntaub ntawv mus rau 20-ntsis

pres = ((data [1] * 65536) + (data [2] * 256) + (data [3] & 0xF0)) / 16

siab = (pres / 4.0) / 1000.0

# Cov ntaub ntawv tso tawm rau lub vijtsam

sau "Siab: %.2f kPa" %siab

luam "Qhov siab: %.2f m" %qhov siab

luam tawm "Kub hauv Celsius: %.2f C" %cTemp

luam tawm "Kub hauv Fahrenheit: %.2f F" %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: