Cov txheej txheem:

Huab Cua Chaw Siv Raspberry Pi Nrog BME280 hauv Python: 6 Kauj Ruam
Huab Cua Chaw Siv Raspberry Pi Nrog BME280 hauv Python: 6 Kauj Ruam

Video: Huab Cua Chaw Siv Raspberry Pi Nrog BME280 hauv Python: 6 Kauj Ruam

Video: Huab Cua Chaw Siv Raspberry Pi Nrog BME280 hauv Python: 6 Kauj Ruam
Video: Lub Zog Nruab Nrog (Hmong Dubbed) 2024, Kaum ib hlis
Anonim
Image
Image
Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb

yog maith scéalaí lub hom phiaj (Huab cua yog Tus Dab Neeg Zoo)

Nrog rau kev ua kom sov hauv ntiaj teb thiab teeb meem huab cua hloov pauv, huab cua huab cua hauv ntiaj teb tau dhau mus tsis zoo thoob plaws peb lub ntiaj teb ua rau muaj huab cua cuam tshuam txog huab cua huab cua ib puag ncig (huab cua qhuav heev, kub heev, dej nyab, cua daj cua dub, thiab hluav taws kub), lub chaw nres tsheb huab cua zoo li yuav tsim nyog siab phem nyob tom tsev. Koj kawm tau ntau yam txog cov khoom siv hluav taws xob yooj yim los ntawm qhov chaw ua haujlwm huab cua siv cov khoom pheej yig thiab cov khoom siv. Nws yooj yim heev los teeb tsa thiab tsis muaj sijhawm koj tuaj yeem muaj nws.

Kauj Ruam 1: Cov Khoom Siv Tseem Ceeb

Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb
Nqi Khoom Siv Tseem Ceeb

1. Raspberry Pi

Tau txais koj txhais tes ntawm Raspberry Pi board. Raspberry Pi yog Linux siv lub tshuab computer ib leeg. Raspberry Pi yog qhov pheej yig tiag tiag, me me thiab muaj ntau yam tsim los ntawm lub khoos phis tawj uas siv tau thiab siv tau rau cov tub ntxhais kawm kom xyaum ua lub hauv paus ntawm lub cajmeem thiab txhim kho software.

2. I2C 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. Digital Humidity, Siab thiab Kub Sensor, BME280

BME280 yog cov av noo, siab thiab ntsuas kub uas muaj lub sijhawm teb sai thiab qhov raug siab tag nrho. Peb tau yuav lub ntsuas cua no los ntawm DCUBE Store.

4. I2C Txuas Txuas Cable

Peb siv I²C cable muaj nyob ntawm no 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 Txhais Kev Siv Internet ntawm EthernetCable/WiFi Adapter

Kev siv internet tuaj yeem siv tau los ntawm Ethernet cable txuas nrog lub network hauv zos thiab hauv internet. Xwb, koj tuaj yeem txuas rau lub wireless network siv USB wireless dongle, uas yuav xav tau kev teeb tsa.

7. HDMI Cable (Zaub & txuas txuas)

Ib qho HDMI/DVI saib thiab txhua lub TV yuav tsum ua haujlwm zoo li Pi. Xwb, koj tuaj yeem nkag mus rau Pi los ntawm SSH tsis pom zoo qhov xav tau rau tus saib xyuas (cov neeg siv siab xwb).

Kauj Ruam 2: Kev Sib Txuas Kho Vajtse rau Circuit

Kho vajtse sib txuas rau Circuit
Kho vajtse sib txuas rau Circuit
Kho vajtse sib txuas rau Circuit
Kho vajtse sib txuas rau Circuit

Ua qhov Circuit Court raws li qhov qhia pom hauv qhov dav, kev sib txuas yog yooj yim heev. Ua kom nyob ntsiag to thiab Ua raws cov lus qhia thiab cov duab saum toj no, thiab koj yuav tsum tsis muaj teeb meem. Thaum kawm, peb tau ua tiav nrog cov hauv paus ntawm cov khoom siv hluav taws xob hais txog kev paub kho vajtse thiab software. Peb xav kos cov txheej txheem hluav taws xob yooj yim rau txoj haujlwm no. Cov lej hluav taws xob zoo ib yam li cov phiaj xwm. Kos ib daim qauv thiab ua tib zoo tsim. Ob peb lub hauv paus ntsiab lus ntawm cov khoom siv hluav taws xob yuav muaj txiaj ntsig ntawm no!

Kev sib txuas ntawm Raspberry Pi thiab I2C Shield

Ua ntej, coj Raspberry Pi thiab tso I²C Shield rau nws. Nias Shield maj mam thiab peb tau ua tiav nrog cov kauj ruam no yooj yim li ncuav qab zib (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 tau ua raws rau Raspberry Pi nrog I²C daim ntaub thaiv npog nws GPIO pins. Peb pom zoo siv I²C cov xov tooj raws li nws tsis xav tau kev nyeem ntawv pinouts, soldering, thiab tsis zoo tshwm sim los ntawm txawm tias me ntsis plam-up. Nrog qhov yooj yim ntsaws thiab ua si cable, koj tuaj yeem teeb tsa, pauv cov laug cam, lossis ntxiv cov laug cam ntxiv rau daim ntawv thov yooj yim.

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 ob txoj kev xaiv ntawm no. Xwb Koj tuaj yeem txuas Raspberry Pi mus rau lub network siv cov ethernet cable lossis siv USB rau WiFi Adapter rau WIFI Kev Sib Txuas. Ua li cas los xij, tsuav nws txuas nrog internet uas koj tau npog.

Txhim kho lub Circuit Court

Txuas lub Micro USB cable rau hauv lub hwj chim nkaus ntawm Raspberry Pi. Punch up thiab voila! Peb pab pawg yog cov ntaub ntawv.

Kev Sib Txuas rau Screen

Peb tuaj yeem muaj HDMI cable txuas nrog tus saib lossis TV. Ib qho ntxiv, peb tuaj yeem nkag mus rau Raspberry Pi yam tsis txuas nws mus rau tus saib xyuas siv kev nkag mus deb. SSH yog cov cuab yeej siv tau yooj yim rau kev nkag mus tau nyab xeeb. Koj kuj tseem tuaj yeem siv PUTTY software rau qhov ntawd. Qhov kev xaiv no yog rau cov neeg siv siab heev yog li peb yuav tsis nthuav dav nws ntawm no.

Nws yog txoj hauv kev pheej yig yog tias koj tsis xav siv nyiaj ntau

Kauj Ruam 3: Raspberry Pi Programming hauv Python

Raspberry Pi Programming hauv Python
Raspberry Pi Programming hauv Python

Python Code rau Raspberry Pi thiab BME280 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. Tsuas yog lub sijhawm me me yuav ua rau koj npaj tau. A chaw nres tsheb huab cua yog qhov chaw, nyob rau thaj av lossis hiav txwv, nrog cov twj thiab cuab yeej ntsuas ntsuas huab cua los muab cov ntaub ntawv qhia txog huab cua thiab kawm txog huab cua thiab huab cua.

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. Tseem nug yog muaj (Txawm tias koj paub ntau txhiab yam, tseem nug ib tus neeg paub).

Koj tuaj yeem luam theej sej ua haujlwm rau tus lej 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. # BME280 # Txoj cai no yog tsim los ua haujlwm nrog BME280_I2CS I2C Mini Module muaj los ntawm ControlEverything.com. #

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# BME280 chaw nyob, 0x76 (118)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x88 (136), 24 bytes b1 = bus.read_i2c_block_data (0x76, 0x88, 24)

# Hloov cov ntaub ntawv

# Temp coefficients dig_T1 = b1 [1] * 256 + b1 [0] dig_T2 = b1 [3] * 256 + b1 [2] yog dig_T2> 32767: dig_T2 -= 65536 dig_T3 = b1 [5] * 256 + b1 [4] yog dig_T3> 32767: dig_T3 -= 65536

# Siab coefficients

dig_P1 = b1 [7] * 256 + b1 [6] dig_P2 = b1 [9] * 256 + b1 [8] yog dig_P2> 32767: dig_P2 -= 65536 dig_P3 = b1 [11] * 256 + b1 [10] yog dig_P3 > 32767: dig_P3 -= 65536 dig_P4 = b1 [13] * 256 + b1 [12] yog dig_P4> 32767: dig_P4 -= 65536 dig_P5 = b1 [15] * 256 + b1 [14] yog dig_P5> 32767: dig_P5 -= 65536 dig_P6 = b1 [17] * 256 + b1 [16] yog dig_P6> 32767: dig_P6 -= 65536 dig_P7 = b1 [19] * 256 + b1 [18] yog dig_P7> 32767: dig_P7 -= 65536 dig_P8 = b1 [21] * 256 + b1 [20] yog dig_P8> 32767: dig_P8 -= 65536 dig_P9 = b1 [23] * 256 + b1 [22] yog dig_P9> 32767: dig_P9 -= 65536

# BME280 chaw nyob, 0x76 (118)

# Nyeem cov ntaub ntawv rov qab los ntawm 0xA1 (161), 1 byte dig_H1 = bus.read_byte_data (0x76, 0xA1)

# BME280 chaw nyob, 0x76 (118)

# Nyeem cov ntaub ntawv rov qab los ntawm 0xE1 (225), 7 bytes b1 = bus.read_i2c_block_data (0x76, 0xE1, 7)

# Hloov cov ntaub ntawv

# Vaum coefficients dig_H2 = b1 [1] * 256 + b1 [0] yog dig_H2> 32767: dig_H2 -= 65536 dig_H3 = (b1 [2] & 0xFF) dig_H4 = (b1 [3] * 16) + (b1 [4] & 0xF) yog dig_H4> 32767: dig_H4 -= 65536 dig_H5 = (b1 [4] / 16) + (b1 [5] * 16) yog dig_H5> 32767: dig_H5 -= 65536 dig_H6 = b1 [6] yog dig_H6> 127: sib_H6 -= 256

# BME280 chaw nyob, 0x76 (118)

# Xaiv tswj cov av noo sau npe, 0xF2 (242) # 0x01 (01) Vaum Oversampling = 1 bus.write_byte_data (0x76, 0xF2, 0x01) # BME280 chaw nyob, 0x76 (118) # Xaiv Tswj kev ntsuas sau npe, 0xF4 (244) # 0x27 (39) Kev ntsuas thiab ntsuas ntsuas ntsuas kub = 1 # Hom tsheb npav.write_byte_data (0x76, 0xF4, 0x27) # BME280 chaw nyob, 0x76 (118) # Xaiv Kev teeb tsa rau npe, 0xF5 (245) # 0xA0 (00) Stand_by time = 1000 ms npav.write_byte_data (0x76, 0xF5, 0xA0)

sijhawm.s pw (0.5)

# BME280 chaw nyob, 0x76 (118)

# Nyeem cov ntaub ntawv rov qab los ntawm 0xF7 (247), 8 bytes # Siab MSB, Siab LSB, Siab xLSB, Kub MSB, Kub LSB # Kub xLSB, Kub MSB, Vaum LSB cov ntaub ntawv = bus.read_i2c_block_data (0x76, 0xF7, 8)

# Hloov cov ntaub ntawv ntsuas thiab ntsuas kub mus rau 19-ntsis

adc_p = ((data [0] * 65536) + (data [1] * 256) + (data [2] & 0xF0)) / 16 adc_t = ((data [3] * 65536) + (data [4] * 256) + (cov ntaub ntawv [5] & 0xF0)) / 16

# Hloov cov ntaub ntawv cov av noo

adc_h = cov ntaub ntawv [6] * 256 + cov ntaub ntawv [7]

# Kev ntsuas kub ntsuas kub

var 1 = ((adc_t) / 16384.0 - (dig_T1) / 1024.0) * (dig_T2) var2 = (((adc_t) / 131072.0 - (dig_T1) / 8192.0) * (adc_t) / 131072.0 - (dig_T1) /8192.0)) * (dig_T3) t_fine = (var1 + var2) cTemp = (var1 + var2) / 5120.0 fTemp = cTemp * 1.8 + 32

# Kev ntsuas qhov ntsuas siab

var1 = (t_fine / 2.0) - 64000.0 var2 = var1 * var1 * (dig_P6) / 32768.0 var2 = var2 + var1 * (dig_P5) * 2.0 var2 = (var2 / 4.0) + ((dig_P4) * 65536.0) var1 = ((dig_P3) * var1 * var1 / 524288.0 + (dig_P2) * var1) / 524288.0 var1 = (1.0 + var1 / 32768.0) * (dig_P1) p = 1048576.0 - adc_p p = (p - (var2 / 4096.0)) * 6250.0 / var1 var1 = (dig_P9) * p * p / 2147483648.0 var2 = p * (dig_P8) / 32768.0 siab = (p + (var1 + var2 + (dig_P7)) / 16.0) / 100

# Kev ntsuas qhov ntsuas av noo

var_H = ((t_fine) - 76800.0) var_H = (adc_h - (dig_H4 * 64.0 + dig_H5 / 16384.0 * var_H)) * (dig_H2 / 65536.0 * (1.0 + dig_H6 / 67108864.0 * var_H * (1.0 + dig_H3 / 67108864.0 * var_H))) av noo = var_H * (1.0 - dig_H1 * var_H / 524288.0) yog cov av noo> 100.0: av noo = 100.0 elif humidity <0.0: humidity = 0.0

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam tawm "Kub hauv Celsius: %.2f C" %cTemp luam ntawv "Kub hauv Fahrenheit: %.2f F" %fTemp luam "Siab: %.2f hPa" %siab sau "txheeb ze vaum: %.2f %%" %av noo

Kauj Ruam 4: Txoj Cai Khiav

Txoj Cai Khiav
Txoj Cai Khiav

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 ntawm lub davhlau ya nyob twg thiab pom cov khoom tso tawm ntawm Zaub. 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 tsim qee qhov ntxim nyiam dua.

Kauj Ruam 5: Kev Siv Hauv Ntiaj Teb Kawg

BME280 ua tiav qhov ua tau zoo hauv txhua daim ntawv thov xav tau cov av noo thiab ntsuas siab. Cov ntawv thov uas tshwm sim no yog Kev paub txog Cov ntsiab lus, xws li Kev Tshawb Pom Ntawm Daim tawv nqaij, Kev Tshawb Nrhiav Hloov Chaw, Kev Saib Xyuas Lub Cev / Nyob Zoo, Ceeb Toom Txog Kev Qhuav lossis Kub Kub, Kev Ntsuas Ntim thiab Huab Cua ntws, Kev Tswj Xyuas Lub Tsev Hauv Tsev, Tswj Cua Kub, Cua Txias, Cua Txias (HVAC), Internet ntawm Yam (IoT), Kev Txhim Kho GPS (piv txwv li Sijhawm-Rau-Thawj-Txhim Kho, Tuag Rov Los, Nrhiav Kom Pom), Kev Taw Qhia Sab Hauv Tsev (Hloov Kev Tshawb Fawb Hauv Pem Hauv Ntej, Kev Tshawb Fawb Hauv Tsev), Kev Taw Qhia Sab Nraud, Kev Ua Si & Kev Ua Si, Huab Cua Huab Cua Thiab Vertical Velocity Indication (Sawv/Dab Dej) Ceev).

Kauj Ruam 6: Xaus

Vam tias txoj haujlwm no txhawb nqa kev sim ntxiv. Ua kom lub chaw nres tsheb huab cua zoo tuaj yeem koom nrog qee qhov ntsuas ntau ntxiv xws li Rain Gauge, Lub teeb pom kev zoo, lub ntsuas cua sov (cua nrawm) thiab lwm yam Koj tuaj yeem ntxiv lawv thiab hloov kho txoj cai. Peb muaj cov vis dis aus qhia hauv YouTube muaj qhov ua haujlwm yooj yim ntawm I²C sensor nrog Rasp Pi. Nws yog qhov txaus siab tiag tiag los saib cov txiaj ntsig thiab ua haujlwm ntawm I²C kev sib txuas lus. Txheeb xyuas nws ib yam nkaus. Muaj kev lom zem hauv tsev thiab kawm! Thov qhia rau peb paub tias koj xav li cas txog cov lus qhia no. Peb yuav nyiam ua qee qhov kev txhim kho yog tias tsim nyog.

Pom zoo: