Cov txheej txheem:

Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2: 6 Cov Kauj Ruam
Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2: 6 Cov Kauj Ruam

Video: Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2: 6 Cov Kauj Ruam

Video: Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2: 6 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2
Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2
Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2
Qhov siab, Siab thiab Kub Siv Raspberry Pi Nrog MPL3115A2

Suab nthuav. Nws muaj peev xwm ua tau nyob rau lub sijhawm no thaum peb txhua tus tab tom mus rau IoT tiam. Raws li cov khoom siv hluav taws xob tsis zoo, peb tau ua si nrog Raspberry Pi, thiab txiav txim siab los ua cov phiaj xwm nthuav dav siv qhov kev paub no. Hauv txoj haujlwm no, peb yuav ntsuas qhov siab, huab cua siab, ntsuas kub siv Raspberry Pi. Yog li ntawm no mus cov ntaub ntawv (ib txwm raug hloov kho, thiab nthuav dav). Peb pom zoo kom pib nrog ua raws cov lus qhia thiab theej cov cai. Koj tuaj yeem sim tom qab. Yog li cia peb pib.

Kauj Ruam 1: Cov Khoom Siv Tseem Ceeb Peb Xav Tau

Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau
Cov Khoom Siv Tseem Ceeb Peb Xav Tau

1. Raspberry Pi

Thawj kauj ruam yog tau txais Raspberry Pi board. Peb tau yuav peb li thiab yog li koj tuaj yeem ua tau. Pib kawm los ntawm cov lus qhia, peb nkag siab cov ntawv sau thiab cov ntsiab lus sib txuas thiab kawm tom qab. Qhov kev txawj ntse me me no muaj ntau rau cov nyiam ua haujlwm, cov kws qhia ntawv thiab hauv kev tsim kho ib puag ncig ib puag ncig.

2. I²C Shield rau Raspberry Pi

INPI2 (I2C adapter) muab Raspberry Pi 2/3 ib qho I²C chaw nres nkoj rau siv nrog ntau I2C khoom siv. Nws muaj nyob ntawm Dcube Store

3. Altimeter, Siab thiab Kub Sensor, MPL3115A2

MPL3115A2 yog MEMS lub siab ntsuas nrog I²C interface los muab Cov ntaub ntawv Siab/Qhov Siab thiab Kub. Qhov ntsuas no siv I²C cov txheej txheem rau kev sib txuas lus. Peb tau yuav qhov ntsuas no los ntawm Dcube Store

4. Txuas Cable

Peb muaj I2C txuas txuas muaj nyob ntawm Dcube Store

5. Micro USB cable

Lub micro USB cable Lub hwj chim muab yog qhov kev xaiv zoo tshaj plaws rau lub zog Raspberry Pi.

6 Txhim Kho Kev Siv Internet - Ethernet Cable/WiFi Adapter

Hauv lub sijhawm no, nkag mus rau txhua yam xav tau kev sib txuas hauv is taws nem (yuav luag zoo li muaj lub neej nyob offline ib yam nkaus). Yog li peb mus coj cov lus qhia ntawm LAN cable lossis Wireless Nano USB Adapter (WiFi) los tsim kev sib txuas hauv is taws nem kom peb tuaj yeem siv peb Rasp Pi tau yooj yim thiab tsis muaj teeb meem hlo li.

7. HDMI Cable (Yeem, Koj Xaiv)

Nws yog qhov nyuaj me ntsis. Koj tuaj yeem muaj lub zog txuas lwm Tus Saib Xyuas yog tias koj xav tau lossis nws muaj txiaj ntsig zoo rau koj tus kheej los ntawm kev ua lub taub hau Pi txuas nrog koj lub PC/Laptop.

Kauj Ruam 2: Khoos Phis Tawj Sib Txuas los Muab Ua Ke Hauv Circuit

Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit

Ua qhov Circuit Court raws li qhov qhia pom hauv qhov dav, kev sib txuas yog yooj yim heev. Ua raws cov lus qhia thiab cov duab, thiab koj yuav tsum tsis muaj teeb meem.

Thaum npaj, peb tau saib xyuas kho vajtse thiab coding nrog rau cov khoom siv hluav taws xob pib. Peb xav tsim cov txheej txheem hluav taws xob yooj yim rau txoj haujlwm no. Hauv daim duab, koj tuaj yeem pom qhov sib txawv, cov khoom siv hluav taws xob thiab I²C sensor tom qab I²C cov txheej txheem kev sib txuas lus. Vam tias, qhov no qhia qhov yooj yim ntawm cov khoom siv hluav taws xob rau txoj haujlwm no.

Kev sib txuas ntawm Raspberry Pi thiab I2C Shield

Ua ntej tshaj plaws coj Raspberry Pi thiab tso I²C Shield rau nws. Nias lub Shield maj mam (Saib daim duab).

Kev sib txuas ntawm Sensor thiab Raspberry Pi

Coj lub sensor thiab Txuas I²C cable nrog nws. Nco ntsoov tias I²C Cov Zis Ib Leeg txuas rau I²C Cov Tswv Yim. Tib yam yuav tsum ua raws los ntawm Raspberry Pi nrog I²C daim ntaub thaiv npog nws. Peb muaj I²C Shield thiab I²C txuas cov xov hluav taws xob ntawm peb sab raws li qhov txiaj ntsig zoo heev raws li peb tau tsuas yog ntsaws thiab ua si xaiv. Tsis muaj tus pin thiab qhov teeb meem txuas ntxiv thiab yog li, tsis meej pem ploj mus. Dab tsi yog kev nplij siab tsuas yog xav txog koj tus kheej hauv lub vev xaib ntawm xov hlau thiab nkag mus rau qhov ntawd. Tsuas yog cov txheej txheem yooj yim uas peb tau hais txog.

Nco tseg: Cov xaim xim av yuav tsum ib txwm ua raws hauv av (GND) kev sib txuas ntawm cov khoom siv ntawm ib lub cuab yeej thiab cov tswv yim ntawm lwm lub cuab yeej

Kev Sib Txuas Internet yog qhov tseem ceeb

Koj muaj kev xaiv ntawm no tiag. Koj tuaj yeem Txuas Raspberry Pi nrog LAN cable lossis wireless Nano USB Adapter rau WiFi Txuas. Txawm li cas los xij, nws tau ua lub hom phiaj tseem ceeb uas yog txuas rau internet.

Kev ua kom muaj zog ntawm Circuit Court

Txuas lub Micro USB cable rau hauv lub hwj chim nkaus ntawm Raspberry Pi. Teeb nws thiab peb zoo mus.

Kev Sib Txuas rau Screen

Peb tuaj yeem muaj HDMI cable txuas nrog tus saib tshiab lossis peb tuaj yeem ua rau peb lub taub hau Pi uas muaj tswv yim thiab muaj txiaj ntsig zoo siv kev nkag mus deb xws li-SSH/PuTTY. (Kuv paub peb tsis tau pab nyiaj zoo li lub koom haum zais cia)

Kauj Ruam 3: Raspberry Pi Programming hauv Python

Raspberry Pi Programming hauv Python
Raspberry Pi Programming hauv Python

Python code rau Raspberry Pi thiab MPL3115A2 Sensor. Nws muaj nyob hauv peb Github chaw cia khoom.

Ua ntej mus rau txoj cai, nco ntsoov koj tau nyeem cov lus qhia muab hauv Readme cov ntaub ntawv thiab teeb tsa koj li Raspberry Pi raws li nws. Nws yuav siv sijhawm ib pliag los ua li ntawd.

Qhov siab yog xam los ntawm kev siab siv cov zauv hauv qab no:

h = 44330.77 {1 - (p / p0) ^ 0.1902632} + OFF_H (Sau Tus Nqi)

Qhov twg p0 = qib siab hiav txwv (101326 Pa) thiab h yog hauv meters. MPL3115A2 siv tus nqi no txij li cov npe offset tau txhais tias yog 2 Pascals ib LSB.

Txoj cai tau hais meej nyob rau hauv pem hauv ntej ntawm koj thiab nws nyob hauv daim ntawv yooj yim tshaj plaws uas koj tuaj yeem xav txog thiab koj yuav tsum tsis muaj teeb meem.

Koj tuaj yeem luam qhov ua haujlwm Python code rau lub ntsuas no los ntawm no ib yam nkaus.

# Faib nrog daim ntawv tso cai yuav dawb.# Siv nws txhua txoj hauv kev koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm ua haujlwm. # MPL3115A2 # Txoj cai no yog tsim los ua haujlwm nrog MPL3115A2_I2CS I2C Mini Module muaj los ntawm ControlEverything.com. #

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv tswj kev sau npe, 0x26 (38) # 0xB9 (185) Hom ua haujlwm, OSR = 128, Altimeter hom bus.write_byte_data (0x60, 0x26, 0xB9) # MPL3115A2 chaw nyob, 0x60 (96) # Xaiv cov ntaub ntawv sau npe, 0x13 (19)) # 0x07 (07) Cov ntaub ntawv npaj tau qhib rau qhov siab, siab, ntsuas kub.write_byte_data (0x60, 0x13, 0x07) # MPL3115A2 chaw nyob, 0x60 (96) # Xaiv tswj npe, 0x26 (38) # 0xB9 (185) Hom ua haujlwm, OSR = 128, Altimeter hom 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, tHeight MSB1, tHeight MSB, tHeight LSB, temp MSB, temp LSB data = bus.read_i2c_block_data (0x60, 0x00, 6)

# Hloov cov ntaub ntawv mus rau 20-ntsis

tHeight = ((cov ntaub ntawv [1] * 65536) + (data [2] * 256) + (data [3] & 0xF0)) / 16 temp = ((data [4] * 256) + (data [5] & 0xF0)) / 16 qhov siab = tHeight / 16.0 cTemp = temp / 16.0 fTemp = cTemp * 1.8 + 32

# MPL3115A2 chaw nyob, 0x60 (96)

# Xaiv tswj kev sau npe, 0x26 (38) # 0x39 (57) Hom nquag, OSR = 128, Barometer hom 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

print "Siab: %.2f kPa" %siab sau "Qhov siab: %.2f m" %qhov siab tshaj sau "Kub hauv Celsius: %.2f C" %cTemp luam "Kub hauv Fahrenheit: %.2f F" %fTemp

Kauj Ruam 4: Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Xeem)

Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Xeem)
Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Xeem)

Tam sim no, rub tawm (lossis git rub) cov cai thiab qhib nws hauv Raspberry Pi.

Khiav cov lus txib kom Sib Sau thiab Tshaj Tawm cov cai hauv lub davhlau ya nyob twg thiab pom cov khoom tso tawm ntawm Saib. Tom qab ob peb feeb, nws yuav tso tawm txhua qhov ntsuas. Tom qab ua kom ntseeg tau tias txhua yam ua haujlwm tau zoo, koj tuaj yeem coj txoj haujlwm no mus rau hauv qhov haujlwm loj dua.

Kauj Ruam 5: Cov ntawv thov thiab Nta

Kev siv ntau ntawm MPL3115A2 Precision Altimeter I²C sensor yog siv hauv daim ntawv thov xws li Daim Ntawv Qhia (Daim Ntawv Qhia Kev Pabcuam, Kev Taw Qhia), Sib Nqus Sib Nqus, lossis GPS (GPS Tuag Txheeb Xyuas, GPS Txhim Kho Rau Kev Pabcuam Thaum Muaj Xwm Ceev), Siab Zoo Tshaj Plaws, Smartphone/Ntsiav Tshuaj, Tus Kheej Siv Hluav Taws Xob thiab Satellites (Cov Khoom Siv Chaw Huab Cua/Huab Cua).

Rau xws li ib txoj haujlwm los ua Tus Kheej Cov Hluav Taws Xob Altimeter uas ntsuas qhov siab, huab cua, ntsuas kub siv Raspberry Pi. Tus Kheej Cov Hluav Taws Xob Altimeter yog tag nrho txoj haujlwm zoo nkauj tsim los. Nws yuav siv sijhawm me ntsis yog tias koj muaj txhua ntu thiab tsis tsim kho (tau kawg koj tuaj yeem!). Lub ntsuas siab siab yog qhov ntsuas pom nyob hauv ntau lub dav hlau, thiab skydivers siv lub dab teg-txhim kho cov qauv rau lub hom phiaj zoo sib xws. Cov neeg taug kev thiab cov neeg nce toj siab siv lub dab teg los yog tes tuav qhov siab.

Kauj Ruam 6: Xaus

Vam tias txoj haujlwm no txhawb nqa kev sim ntxiv. Qhov ntsuas I²C no muaj ntau yam tsis txaus ntseeg, pheej yig thiab siv tau. Txij li nws yog txoj haujlwm hloov pauv tsis tau, muaj ntau txoj hauv kev koj tuaj yeem txuas ntxiv txoj haujlwm no thiab ua kom nws zoo dua. Piv txwv li, lub ntsuas qhov siab yog ib qho cuab yeej xaiv tau hauv cov tsheb uas tsis yog txoj hauv kev los pab hauv kev taw qhia. Qee lub tsheb zoo ua tau zoo uas tsis tau npaj siab yuav tawm ntawm txoj hauv kev, siv cov thev naus laus zis no. Txhawm rau kom yooj yim rau koj, peb muaj cov vis dis aus nthuav qhia hauv YouTube uas tuaj yeem qiv tes rau koj qhov kev tshawb nrhiav. Vam tias txoj haujlwm no txhawb nqa kev sim ntxiv.

Pom zoo: