Cov txheej txheem:

Yuav Ua Li Cas Tsim Raspberry Pi Kev Ntsuas Kub: 9 Kauj Ruam
Yuav Ua Li Cas Tsim Raspberry Pi Kev Ntsuas Kub: 9 Kauj Ruam

Video: Yuav Ua Li Cas Tsim Raspberry Pi Kev Ntsuas Kub: 9 Kauj Ruam

Video: Yuav Ua Li Cas Tsim Raspberry Pi Kev Ntsuas Kub: 9 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Tsim Raspberry Pi Qhov Ntsuas Kub
Yuav Ua Li Cas Tsim Raspberry Pi Qhov Ntsuas Kub

Kub thiab av noo yog cov ntsiab lus tseem ceeb hauv kev lag luam niaj hnub no. Saib xyuas cov ntaub ntawv ib puag ncig rau chav neeg rau zaub mov, lub tub rau khoom txias, thiab cov kab tsim khoom tsim nyog kom ua kom cov khoom ua haujlwm tau zoo. Muaj ntau ntau cov kev daws teeb meem tawm ntawm qhov pib mus rau qhov nyuaj thiab nws tuaj yeem zoo li nyuaj rau yam koj xav tau kev lag luam thiab yuav pib qhov twg.

Peb yuav taug kev los saib xyuas qhov kub thiab txias nrog Raspberry Pi thiab qhov ntsuas kub sib txawv uas koj tuaj yeem siv tau. Nov yog qhov chaw zoo los pib txij li cov kev daws teeb meem no pheej yig, ua tau yooj yim, thiab muab lub hauv paus rau koj los tsim tawm ntawm lwm qhov kev saib xyuas ib puag ncig.

Khoom siv

  • Raspberry Pi (3, 4, lossis Zero WH)
  • Kub Sensor (DHT2, DSB18B20, BME280, lossis Hnov HAT)
  • 6 "40-Pin IDE Txiv neej rau Poj Niam Extension Cable (Sense HAT Solution)
  • 10K Resistor, Breadboard, 40-Pin Breakout Board + Ribbon Cable, Hlau (Rau DSB18B20 Tshuaj)

Kauj ruam 1: Raspberry Pi

Raspberry Pi yog lub khoos phis tawj pheej yig uas yuav tso cai rau koj txuas mus rau qhov ntsuas kub thiab xa cov ntaub ntawv mus rau cov ntaub ntawv pom software. Raspberry Pi tau pib ua qhov cuab yeej kawm thiab tau hloov pauv mus rau cov cuab yeej ua haujlwm hauv chaw ua haujlwm. Qhov yooj yim ntawm kev siv thiab muaj peev xwm los ua tus lej nrog Python, kev tsim cov lus yooj yim tshaj plaws, tau ua rau lawv mus daws teeb meem.

Koj yuav xav tau Raspberry Pi uas muaj WiFi ua hauv, uas yog cov qauv 3, 4, thiab xoom W/WH. Nruab nrab ntawm cov uas koj tuaj yeem xaiv raws tus nqi thiab cov yam ntxwv. Zero W/WH yog qhov pheej yig tshaj tab sis yog tias koj xav tau kev ua haujlwm ntau dua koj tuaj yeem xaiv ntawm 3 thiab 4. Koj tsuas tuaj yeem yuav ib Zero W/WH ib lub sijhawm vim muaj kev txwv los ntawm Raspberry Pi Foundation. Xijpeem Pi koj xaiv, nco ntsoov yuav lub roj teeb vim tias yog li cas koj thiaj yuav zog Pi thiab SD daim npav nrog Raspbian txhawm rau teeb tsa kev ua haujlwm yooj yim li sai tau.

Muaj lwm lub khoos phis tawj siv tib lub tshuab uas tuaj yeem ua haujlwm ib yam nkaus, tab sis qhov ntawd yog rau lwm lub sijhawm thiab lwm tsab xov xwm.

Kauj ruam 2: Sensors

Muaj peb lub ntsuas hluav taws xob peb pom zoo siv vim tias lawv pheej yig, txuas tau yooj yim, thiab muab nyeem tau raug; DSB18B20, DHT22, thiab Raspberry Pi Sense HAT.

DHT22 - Qhov ntsuas kub thiab av noo no muaj qhov ntsuas kub ntawm +/- 0.5 C thiab cov av noo los ntawm 0 txog 100 feem pua. Nws yog qhov yooj yim rau xaim mus rau Raspberry Pi thiab tsis xav tau ib qho rub tawm cov neeg tawm tsam.

DSB18B20 - Qhov ntsuas kub no muaj qhov tso tawm digital, uas ua haujlwm tau zoo nrog Raspberry Pi. Nws muaj peb lub xov hlau thiab xav tau lub khob cij thiab cov tiv thaiv rau kev txuas.

BME280 - Qhov ntsuas no ntsuas ntsuas kub, av noo, thiab ntsuas siab. Nws tuaj yeem siv tau ob qho tib si SPI thiab I2C.

Sense HAT - Qhov no yog ntxiv rau ntawm pawg thawj coj saib rau Raspberry Pi uas muaj LEDs, ntsuas, thiab me me joystick. Nws txuas ncaj qha rau GPIO ntawm Raspberry Pi tab sis siv cov hlua txuas ua rau koj nyeem tau qhov ntsuas kub ntau dua.

Kauj Ruam 3: Teeb Raspberry Pi

Yog tias qhov no yog thawj zaug teeb tsa koj li Raspberry Pi koj yuav tsum teeb tsa Raspbian Operating System thiab txuas koj Pi rau WiFi. Qhov no yuav xav tau tus saib xyuas thiab keyboard los txuas rau Pi. Thaum koj tau txais nws thiab khiav thiab txuas nrog WiFI, koj Pi tau npaj mus.

Kauj Ruam 4: Thawj Xeev Cov Nyiaj

Thawj Xeev Cov Nyiaj
Thawj Xeev Cov Nyiaj
Thawj Xeev Cov Nyiaj
Thawj Xeev Cov Nyiaj

Koj yuav xav tau qee qhov kom xa koj cov ntaub ntawv khaws cia keeb kwm cav thiab saib cov ntaub ntawv ntawm lub sijhawm tiag tiag yog li peb yuav siv Thawj Lub Xeev. Mus rau https://iot.app.initialstate.com thiab tsim tus as khauj tshiab lossis nkag mus rau hauv koj tus as khauj uas twb muaj lawm.

Tom ntej no, peb yuav tsum teeb tsa Lub Xeev Pib Python module rau koj tus Pi. Ntawm qhov hais kom ua sai sai (tsis txhob hnov qab SSH rau hauv koj tus Pi thawj), khiav cov lus txib hauv qab no:

$ cd/tsev/pi/

$ / curl -sSL https://get.initialstate.com/python -o -| sudo tsoo

Tom qab koj nkag mus rau kab lus curl hauv qhov hais kom ua sai sai koj yuav pom qee yam zoo ib yam li cov hauv qab no tso rau ntawm qhov screen:

pib@raspberrypi ~

$ / curl -sSL https://get.initialstate.com/python -o -| sudo bash Lo lus zais: Pib ISStreamer Python Kev teeb tsa yooj yim! Qhov no yuav siv ob peb feeb los teeb tsa, rub qee lub kas fes:) Tab sis tsis txhob hnov qab rov qab los, Kuv yuav muaj lus nug tom qab! Pom yooj yim_install: setuptools 1.1.6 Pom pip: pip 1.5.6 los ntawm /Library/Python/2.7/site-packages/pip-1.5.6- py2.7.egg (sej 2.7) pip loj version: 1 pip me me version: 5 ISStreamer pom, hloov kho… Yuav tsum tau hloov kho tshiab tas li: ISStreamer hauv /Library/Python/2.7/site-packages Tu tu… Koj puas xav tau automagically tau txais ib qho piv txwv tsab ntawv? [y/N] Koj xav khaws qhov piv txwv nyob qhov twg? [lub neej ntawd:./is_example.py] Thov xaiv qhov Xeev Lub Xeev app uas koj siv: 1. app.initialstate.com 2. [TSHIAB!] iot.app.initialstate.com Nkag mus xaiv 1 lossis 2: Nkag mus rau iot.app.initialstate.com tus neeg siv lub npe: Nkag mus rau iot.app.initialstate.com lo lus zais:

Thaum hais kom ua kom tau txais cov ntawv piv txwv, ntaus y. Qhov no yuav tsim cov ntawv xeem uas peb tuaj yeem ua haujlwm kom ntseeg tau tias peb tuaj yeem xa cov ntaub ntawv mus rau Lub Xeev Pib. Qhov txuas ntxiv tom ntej yuav nug qhov twg koj xav khaws cov piv txwv ntawv. Koj tuaj yeem xaiv hom kev cai hauv nroog lossis ntaus nkag mus lees txais qhov chaw nyob tsis raug. Thaum kawg, koj yuav raug nug tias Thawj Lub Xeev app twg koj tab tom siv. Yog tias koj nyuam qhuav tsim ib tus as khauj, xaiv qhov kev xaiv 2, sau koj lub npe siv thiab tus lej zais. Tom qab ntawd qhov kev teeb tsa yuav ua tiav.

Cia peb saib qhov piv txwv tsab ntawv uas tau tsim.

$ nano is_example.py

Ntawm kab 15, koj yuav pom kab uas pib nrog streamer = Streamer (bucket_…. Cov kab no tsim cov ntaub ntawv tshiab lub npe hu ua “Python Stream Piv txwv” thiab cuam tshuam nrog koj tus lej nyiaj. Qhov koom haum no tshwm sim vim yog access_key =”…” parameter ntawm kab ntawd tib yam. Cov kab ntawv ntev thiab cov lej yog koj li Thawj Lub Xeev tus lej nkag mus siv tus lej. Yog tias koj mus rau koj Lub Xeev Thawj tus lej hauv koj lub vev xaib, nyem rau koj lub npe siv nyob rau sab xis, tom qab ntawd mus rau "kuv qhov chaw", koj yuav pom tus yuam sij nkag tau zoo ib yam ntawm no hauv qab "Streaming Access Keys".

Txhua lub sijhawm koj tsim cov ntaub ntawv kwj, tus yuam sij nkag mus yuav ncaj qha cov ntaub ntawv xa mus rau koj tus lej nyiaj (yog li tsis txhob faib koj tus yuam sij rau leej twg).

Khiav cov ntawv xeem kom paub tseeb tias peb tuaj yeem tsim cov ntaub ntawv xa mus rau koj Tus Thawj Xeev tus as khauj. Khiav cov hauv qab no:

$ python is_example.py

Rov qab mus rau koj lub Xeev Thawj tus lej hauv koj lub vev xaib. Ib lub thoob cov ntaub ntawv tshiab hu ua "Python Stream Piv txwv" yuav tsum tau tshwm nyob rau sab laug hauv koj lub txee rau khoom (koj yuav tau rov ua nplooj ntawv tshiab). Nyem rau ntawm lub thoob no thiab tom qab ntawd nyem rau ntawm Waves icon kom pom cov ntaub ntawv ntsuas

Yog tias koj tab tom siv Python 3 koj tuaj yeem teeb tsa Initial State Streamer Module koj tuaj yeem teeb tsa siv cov lus txib hauv qab no:

pip3 nruab ISStreamer

Tam sim no peb tau npaj los teeb tsa qhov ntsuas kub nrog Pi kom ntws qhov kub mus rau lub dashboard.

Kauj Ruam 5: DHT22 Tshuaj

DHT22 Tshuaj
DHT22 Tshuaj

DHT22 yuav muaj peb tus pin - 5V, Gnd, thiab cov ntaub ntawv. Yuav tsum muaj daim ntawv lo pin rau lub zog ntawm DHT22 (piv txwv li '+' lossis '5V'). Txuas qhov no rau tus pin 2 (tus pin sab xis saum toj, 5V) ntawm Pi. Gnd tus pin yuav sau lo lus '-' lossis 'Gnd' lossis qee yam sib npaug. Txuas qhov no rau tus pin 6 Gnd (ob tus pin hauv qab 5V tus pin) ntawm Pi. Tus pin ntxiv ntawm DHT22 yog tus pin cov ntaub ntawv thiab yuav sau tias 'tawm' lossis 's' lossis 'cov ntaub ntawv'. Txuas qhov no mus rau ib qho ntawm GPIO tus pin ntawm Pi xws li GPIO4 (tus pin 7). Thaum qhov no tau xaim, lub zog ntawm koj Pi.

Nruab Adafruit DHT Python module ntawm qhov hais kom ua kom nyeem DHT22 sensor cov ntaub ntawv yooj yim heev:

$ sudo pip nruab Adafruit_DHT

Nrog peb cov txheej txheem ua haujlwm nruab nrog peb ob lub Python cov qauv rau nyeem cov ntaub ntawv sensor thiab xa cov ntaub ntawv mus rau Lub Xeev Pib, peb tau npaj sau peb tsab ntawv Python. Cov ntawv hauv qab no yuav tsim/txuas ntxiv mus rau Thawj Lub Xeev cov ntaub ntawv thoob, nyeem DHT22 cov ntaub ntawv ntsuas, thiab xa cov ntaub ntawv ntawd mus rau lub sijhawm tiag tiag dashboard. Txhua yam koj yuav tsum tau ua yog hloov kab 6–11.

ntshuam Adafruit_DHT

los ntawm ISStreamer. Streamer ntshuam lub sijhawm Streamer ntshuam# --------- Cov Chaw Siv --------- SENSOR_LOCATION_NAME = "Chaw Haujlwm" BUCKET_NAME = ": ib nrab_sunny: Chav Kub" BUCKET_KEY = "rt0129" ACCESS_KEY = "PLACE KOJ TUS NEEG NYOB HAUV TSEV KAWM NTAWV ACCESS KEY NTAWM NO" MINUTES_BETWEEN_READS = 10METRIC_UNITS = Cuav # --------------------------------- streamer = Streamer (bucket_name = BUCKET_NAME, bucket_key = BUCKET_KEY, access_key = ACCESS_KEY) thaum Muaj tseeb: av noo, temp_c = Adafruit_DHT.read_retry (Adafruit_DHT. DHT22, 4) yog METRIC_UNITS: streamer.log (SENSOR_LOCATION_NAME + "Kub dua): temp_f = format (temp_c * 9.0 / 5.0 + 32.0, ".2f") streamer.log (SENSOR_LOCATION_NAME + "Kub (F)", temp_f) humidity = format (humidity, ".2f") streamer.log (SENSOR_LOCATION_NAME +) "Vaum (%)", av noo) streamer.flush () time.sleep (60*MINUTES_BETWEEN_READS)

  • Kab 6 - Tus nqi no yuav tsum yog qhov tshwj xeeb rau txhua qhov ntsuas/ntsuas kub. Qhov no tuaj yeem yog koj lub cim ntsuas lub npe chav, qhov chaw nyob, tus cim tshwj xeeb, lossis ib yam dab tsi. Tsuas yog xyuas kom nws yog qhov tshwj xeeb rau txhua lub node kom ntseeg tau tias cov ntaub ntawv los ntawm qhov ntawm no mus rau nws tus kheej cov ntaub ntawv ntws hauv koj lub dashboard.
  • Kab 7 - Nov yog lub npe ntawm cov thoob cov ntaub ntawv. Qhov no tuaj yeem hloov pauv txhua lub sijhawm hauv Initial State UI.
  • Kab 8 - Nov yog koj lub thoob qhov tseem ceeb. Nws yuav tsum yog tib lub thoob qhov tseem ceeb rau txhua lub node koj xav pom hauv tib lub dashboard.
  • Kab 9 - Nov yog Koj Tus Thawj Xib Fwb nkag mus rau tus lej nkag. Luam thiab muab tus yuam sij no los ntawm koj lub Xeev Tus Thawj Kav Xwm.
  • Kab 10 - Nov yog lub sijhawm nruab nrab ntawm kev nyeem ntawv. Hloov raws li.
  • Kab 11 - Koj tuaj yeem hais qhia qhov ntsuas lossis ntsuas nyob hauv kab 11.

Tom qab koj tau teeb tsa kab 6–11 hauv koj tsab ntawv Python ntawm koj Pi, txuag thiab tawm ntawm cov ntawv sau. Khiav tsab ntawv nrog cov lus txib hauv qab no:

$ python tempsensor.py

Tam sim no koj yuav muaj cov ntaub ntawv xa mus rau Thawj Lub Xeev dashboard. Mus rau ntu kawg ntawm kab lus no kom paub meej txog yuav ua li cas hloov kho koj lub dashboard.

Kauj Ruam 6: DSB18B20 Tshuaj

DSB18B20 Tshuaj
DSB18B20 Tshuaj
DSB18B20 Tshuaj
DSB18B20 Tshuaj

Ribbon cable txuas rau GPIO pins ntawm Pi. DS18B20 muaj peb lub xov hlau. Cov hlau liab txuas rau 3.3V. Cov xaim xiav/dub txuas rau hauv av. Cov xaim daj txuas mus rau qhov rub tawm tus tiv thaiv/tus pin 4. Thaum qhov no tau txuas, txuas lub zog ntawm koj Pi.

Qhov tseeb version ntawm Raspbian (kernel 3.18) xav tau ntxiv rau koj /boot/config.txt cov ntaub ntawv rau Pi kom sib txuas lus nrog DS18B20. Khiav cov hauv qab no los kho cov ntaub ntawv no:

$ sudo nano /boot/config.txt

Yog tias kab hauv qab no tseem tsis tau nyob hauv cov ntawv no (yog tias nws yog, nws yuav zoo li hauv qab ntawm cov ntawv), ntxiv nws thiab khaws cov ntawv.

dtoverlay = w1-gpio, gpiopin = 4

Rov pib dua koj Pi rau qhov kev hloov pauv kom siv tau.

$ sudo rov pib dua

Txhawm rau pib ntsuas qhov ntsuas kub nyeem nyeem peb yuav tsum tau ua ob lo lus txib. Mus rau qhov hais kom ua sai sai ntawm koj Pi lossis SSH rau hauv koj Pi. Ntaus cov lus txib hauv qab no:

$ sudo modprobe w1-gpio $ sudo modprobe w1-therm

Qhov tso tawm ntawm koj qhov ntsuas kub tam sim no tau sau rau hauv cov ntawv ntawm koj Pi. Txhawm rau nrhiav cov ntawv ntawd:

$ cd/sys/bus/w1/khoom siv

Hauv cov npe no, yuav muaj cov npe me me uas pib nrog "28-". Dab tsi los tom qab "28-" yog tus lej ntawm koj lub sensor. cd rau hauv phau ntawv ntawd. Sab hauv cov npe no, cov ntaub ntawv npe w1_slave muaj qhov tso tawm ntawm koj lub sensor. Siv nano los saib cov ntsiab lus ntawm cov ntawv. Thaum koj tau nkag mus rau hauv cov ntawv, nws yuav zoo li qhov no:

a2 01 4b 46 7f ff 0e 10 d8: crc = d8 YESa2 01 4b 46 7f ff 0e 10 d8 t = 26125

Tus lej tom qab "t =" yog tus lej peb xav tau. Qhov no yog qhov kub hauv 1/1000 degrees Celsius (hauv qhov piv txwv saum toj no, qhov kub yog 26.125 C). Peb tsuas yog xav tau txoj haujlwm yooj yim uas nyeem cov ntawv no thiab cais tawm tus lej ntawd. Peb yuav mus txog qhov ntawd hauv ib pliag xwb.

Txhua yam tam sim no tau npaj rau peb kom pib tshaj tawm cov ntaub ntawv. Txhawm rau qhib cov ntawv nyeem ntaus cov hauv qab no hauv qhov hais kom ua:

$ nano temperature.py

Luam thiab paste cov cai hauv qab no rau hauv cov ntawv sau.

import os

ntshuam glob ntshuam sijhawm los ntawm ISStreamer. Streamer ntshuam Streamerstreamer = Streamer (bucket_name = "Kub Kub", bucket_key = "piot_temp_stream031815", access_key = "PUT_YOUR_ACCESS_KEY_HERE") os.system ('modprobe w1-gpio') os.system ('modprobe w1-gpio') os.system ('modprobe -therm ') base_dir ='/sys/bus/w1/devices/'device_folder = glob.glob (base_dir + '28*') [0] device_file = device_folder + '/w1_slave' def read_temp_raw (): f = qhib (device_file, 'r') kab = f.readlines () f.close () xa kab def read_temp (): kab = read_temp_raw () thaum kab [0].strip () [-3:]! = 'YOG': time.sleep (0.2) kab = read_temp_raw () equals_pos = kab [1].find ('t =') yog equals_pos! = -1: temp_string = kab [1] [equals_pos+2:] temp_c = ntab (temp_string) / 1000.0 xa rov qab temp_c thaum Tseeb: temp_c = read_temp () temp_f = temp_c * 9.0 / 5.0 + 32.0 streamer.log ("kub (C)", temp_c) streamer.log ("kub (F)", temp_f) time.sleep (.5)

Koj yuav tsum tso koj Thawj Lub Xeev nkag mus rau tus lej kab 6 ntawm PUT_YOUR_ACCESS_KEY_HERE (luam qhov tseem ceeb ntws mus rau koj daim ntawv los ntawm 'Kuv Tus Kheej' thiab muab nws tso rau hauv tus lej hauv nano hauv koj lub davhlau ya nyob twg).

Kab 6 yuav tsim lub thoob hu ua "Kub Kub" hauv koj li Xeev Lub Xeev Nyiaj Txiag (piv txwv tias koj tau teev meej meej koj tus lej nkag mus ntawm kab no tib yam). Kab 8 txog 30 ntawm tsab ntawv no yooj yim cuam tshuam nrog lub DS18B20 sensor los nyeem nws qhov ntsuas kub los ntawm w1_slave cov ntaub ntawv peb tau tham ua ntej. Read_temp_raw () ua haujlwm ntawm kab 15 nyeem cov ntaub ntawv raw w1_slave. Read_temp () ua haujlwm ntawm kab 21 cais tawm qhov ntsuas kub los ntawm cov ntawv ntawd. Kab 34 hu cov haujlwm no kom tau txais qhov ntsuas kub tam sim no. Kab 35 hloov qhov kub ntawm Celsius mus rau Fahrenheit. Kab 35 thiab 36 ntws qhov ntsuas kub mus rau koj Tus Thawj Xib Fwb Lub Xeev. Kab 37 ncua tsab ntawv rau 0.5 vib nas this, teev ntau npaum li cas qhov ntsuas kub yuav nyeem thiab ntws.

Peb npaj tau pib tshaj tawm. Khiav cov lus txib hauv qab no:

$ sudo nab hab sej temperature.py

Rov qab mus rau koj lub Xeev Thawj tus lej hauv koj lub vev xaib thiab saib rau lub thoob cov ntaub ntawv tshiab hu ua Kub Kub. Koj yuav tsum pom cov ntaub ntawv ntsuas kub nyob hauv. Hloov qhov ntsuas kub ntawm qhov ntsuas los ntawm tuav nws hauv koj txhais tes lossis muab tso rau hauv ib khob dej khov.

Tam sim no koj yuav muaj cov ntaub ntawv xa mus rau Thawj Lub Xeev dashboard. Mus rau ntu kawg ntawm kab lus no kom paub meej txog yuav ua li cas hloov kho koj lub dashboard.

Kauj Ruam 7: BME280 Tshuaj

Koj yuav xav tau cov hauv qab no tsim cov kev daws teeb meem no:

-BME280 Siab, Kub, & Vaum Sensor

Qhov ntsuas no los nrog tus pin uas koj yuav xav tau rau ntawm lub sensor. Kuv pom zoo siv lub khob cij nrog cov pins ntev sab rau hauv lub khob cij kom ua kom yooj yim dua. Thaum koj tau ua tiav qhov no peb yuav tsum xaim lub sensor mus rau Pi.

Txuas tus VIN tus pin ntawm lub sensor mus rau 3.3V tus pin 1 ntawm tus Pi. Txuas GND tus pin ntawm lub ntsuas phoo hauv av pin 6 ntawm Pi. Txuas tus SCK tus pin ntawm lub sensor mus rau SCL tus pin 5 ntawm tus Pi. Txuas SDI tus pin ntawm lub sensor mus rau SDA tus pin 3 ntawm Pi. Koj yuav tsum tau siv Python 3 rau qhov kev daws teeb meem no thiab teeb tsa Initial State Streamer module siv pip3 teeb tsa txoj hauv kev.

Koj kuj tseem yuav tsum tau teeb tsa ob peb lub tsev qiv ntawv Adafruit Python.

pip3 nruab adafruit-blinkapip3 nruab pureio pip3 nruab spidev pip3 nruab adafruit-GPIO pip3 nruab adafruit-circuitpython-bme280

Txhawm rau siv lub ntsuas peb xav tau los pab I2C ntawm Pi.

sudo raspi-teeb tsa

Qhov no yuav qhib Raspberry Pi Software Configuration Tool. Mus rau Qhov Kev Xaiv 5 Kev Xaiv Ua Ntej. Los ntawm no mus rau I2C. Nws yuav nug koj sai li sai tau yog tias koj xav kom qhib I2C, Xaiv Yog thiab Ua tiav. Tam sim no koj muaj I2C qhib kev sib tham nrog lub sensor.

Peb tuaj yeem sim qhov no los ntawm kev ua cov hauv qab no:

sudo i2cdetect -y 1

Qhov no yuav txheeb xyuas tias koj Pi pom lub sensor. Nyob rau hauv txoj kev uas nws txuas, nws yuav tsum qhia lub sensor ntawm qhov chaw nyob 77. Yog tias koj tsis pom lub sensor, rov pib dua koj Pi, rov qhib I2C interface xaiv ntawm koj Pi, thiab sim dua. los khiav peb cov cai tseem ceeb uas yuav xa cov ntaub ntawv mus rau Lub Xeev Pib. Tsim cov ntaub ntawv hu ua bme280sensor.py nrog nano hais kom ua. Luam thiab paste cov cai los ntawm cov ntsiab lus rau hauv kab ntawv sau. Koj yuav tsum tau hloov pauv kab 12-19.

lub sij hawm ntshuam

ntshuam pawg thawj coj ntshuam busio ntshuam adafruit_bme280 los ntawm ISStreamer. Streamer ntshuam Streamer # Tsim cov khoom siv tsev qiv ntawv siv peb Bus I2C porti2c = busio. I2C (board. SCL, board. SDA) bme280 = adafruit_bme280. Adafruit_BME280_I2C (i2c) # ------- -Cov Neeg Siv Khoom --------- SENSOR_LOCATION_NAME = "Chaw Ua Haujlwm" BUCKET_NAME = ": ib nrab_sunny: Kub Hauv Chav" BUCKET_KEY = "temp1" ACCESS_KEY = "KOJ YUAV TSHUAJ KEY NTAWM NO" # hloov qhov no kom phim qhov chaw qhov siab (hPa) ntawm qib dej hiav txwv bme280.sea_level_pressure = 1013.25 MINUTES_BETWEEN_READS = 10 METRIC_UNITS = Cuav # --------------------------------- # LOSSIS tsim lub tsev qiv ntawv cov khoom siv peb qhov chaw nres nkoj Bus SPI #spi = busio. SPI (board. SCK, board. MOSI, board. MISO) #bme_cs = digitalio. DigitalInOut (board. D10) #bme280 = adafruit_bme280. Adafruit_BME280_SPI (spi, bme_cs) streamer = Streamer (bucket_name = BUCKET_NAME, bucket_key = BUCKET_KEY, access_key = ACCESS_KEY) thaum muaj tseeb: humidity = format (bme280.humidity, ".1f") pressure = format (bme280.pressure, ".1f") temp_c = bme280.temperatu rov yog METRIC_UNITS: streamer.log (SENSOR_LOCATION_NAME + "Kub (C)", temp_c) lwm qhov: temp_f = format (temp_c * 9.0 / 5.0 + 32.0, ".1f") streamer.log (SENSOR_LOCATION_NAME + "Kub (F)", temp_f) streamer.log (SENSOR_LOCATION_NAME + "Vaum (%)", av noo) streamer.log (SENSOR_LOCATION_NAME + "Siab (hPA)", siab) streamer.flush () time.s pw (60*MINUTES_BETWEEN_READS)

  • Kab 12- Tus nqi no yuav tsum yog qhov tshwj xeeb rau txhua qhov ntsuas/ntsuas kub. Qhov no tuaj yeem yog koj lub cim ntsuas lub npe chav, qhov chaw nyob, tus cim tshwj xeeb, lossis ib yam dab tsi. Tsuas yog xyuas kom nws yog qhov tshwj xeeb rau txhua lub node kom ntseeg tau tias cov ntaub ntawv los ntawm qhov ntawm no mus rau nws tus kheej cov ntaub ntawv ntws hauv koj lub dashboard.
  • Kab 13- Nov yog lub npe ntawm cov thoob cov ntaub ntawv. Qhov no tuaj yeem hloov pauv txhua lub sijhawm hauv Initial State UI.
  • Kab 14- Nov yog koj lub thoob qhov tseem ceeb. Nws yuav tsum yog tib lub thoob qhov tseem ceeb rau txhua lub node koj xav pom hauv tib lub dashboard.
  • Kab 15- Qhov no yog koj li Xeev Thawj tus lej nkag mus siv tus lej. Luam thiab muab tus yuam sij no los ntawm koj lub Xeev Tus Thawj Kav Xwm.
  • Kab 17- Nov yog koj qhov chaw nyob siab (hPa) ntawm qib hiav txwv. Koj tuaj yeem nrhiav cov ntaub ntawv no ntawm ntau lub vev xaib huab cua.
  • Kab 18 - Nov yog lub sijhawm nruab nrab ntawm kev nyeem ntawv. Hloov kom haum. Line 19- Ntawm no koj tuaj yeem hais qhia qhov ntsuas lossis ntsuas chav nyob.

Tom qab koj tau teeb kab 12–19 hauv koj tsab ntawv Python ntawm koj Pi Zero WH, txuag thiab tawm ntawm cov ntawv sau. Khiav tsab ntawv nrog cov lus txib hauv qab no:

$ python3 bme280sensor.py

Tam sim no koj yuav muaj cov ntaub ntawv xa mus rau Thawj Lub Xeev dashboard. Mus rau ntu kawg ntawm kab lus no kom paub meej txog yuav ua li cas hloov kho koj lub dashboard.

Kauj Ruam 8: Soj Ntsuam HAT

Sense HAIS
Sense HAIS
Sense HAIS
Sense HAIS

Thawj kauj ruam hauv kev siv Sense HAT yog lub cev nruab nws rau koj Pi. Nrog Pi txhawb zog, txuas HAT raws li qhia hauv daim duab.

Yog tias koj txiav txim siab siv qhov kev daws teeb meem raws li tau hais los saum toj no koj yuav pom tias koj li kev paub HAT qhov ntsuas kub yuav siab me ntsis - qhov ntawd yog vim lawv yog. Tus neeg ua txhaum yog cua sov tsim los ntawm Pi lub CPU ua kom cua sov nyob ib puag ncig Sense HAT thaum nws zaum saum lub Pi. Txhawm rau ua kom ntsuas qhov ntsuas kub tau txais txiaj ntsig, peb yuav tsum tau txais HAT kom deb ntawm Pi lossis sim ntsuas qhov ntsuas kub ntsuas. Ib qho kev daws teeb meem zoo kom tau txais lub sensor tawm ntawm Pi yog txoj hlua uas tso cai rau Sense HAT dai ntawm tus Pi. A 6 , 40-pin IDE txiv neej rau poj niam txuas txuas txuas cable yuav ua qhov dag.

Thaum koj txiav txim siab ntawm ob txoj kev xaiv, lub zog ntawm koj Pi. Peb yuav tsum teeb tsa lub tsev qiv ntawv Python kom yooj yim nyeem qhov ntsuas qhov ntsuas los ntawm Sense HAT. Ua ntej, koj yuav tsum xyuas kom txhua yam hloov kho tshiab ntawm koj li Raspbian version:

$ sudo apt-tau hloov tshiab

Tom ntej no, nruab Sense HAT Python lub tsev qiv ntawv:

$ sudo apt-tau nruab kev nkag siab-lub kaus mom

Reboot koj Pi. Peb tau npaj los ntsuas Sense HAT los ntawm kev nyeem cov ntaub ntawv sensor los ntawm nws thiab xa cov ntaub ntawv ntawd mus rau Lub Xeev Pib.

Tsim cov ntaub ntawv hu ua sensehat thiab qhib nws hauv cov ntawv sau los ntawm kev nkag mus rau hauv qab hauv kab lus hais kom ua:

$ nano sensehat.py

Luam thiab paste cov cai hauv qab no hauv kab ntawv sau.

los ntawm sense_hat ntshuam SenseHat

ntshuam sijhawm ntshuam sys los ntawm ISStreamer. Streamer ntshuam Streamer # --------- Cov Chaw Siv --------- BUCKET_NAME = "Chaw Ua Haujlwm Huab Cua" BUCKET_KEY = "sensehat" ACCESS_KEY = "Your_Access_Key" SENSOR_LOCATION_NAME = " Chaw ua haujlwm "MINUTES_BETWEEN_SENSEHAT_READS = 0.1 # --------------------------------- streamer = Streamer (bucket_name = BUCKET_NAME, bucket_key = BUCKET_KEY, access_key = ACCESS_KEY) kev nkag siab = SenseHat () thaum muaj tseeb: # Nyeem cov ntsuas ntsuas temp_c = sense.get_temperature () humidity = sense.get_humidity () pressure_mb = sense.get_pressure () # Format cov ntaub ntawv temp_f = temp_c * 9.0 / 5.0 + 32.0 temp_f = float ("{0:.2f}". Format (temp_f)) humidity = float ("{0:.2f}". Format (humidity)) pressure_in = 0.03937008*(pressure_mb) pressure_in = ntab ("{ 0:.2f}. Siab (IN): " + str (pressure_in) streamer.log (": tshav ntuj: " + SEN SOR_LOCATION_NAME + "Kub (F)", temp_f) streamer.log (": sweat_drops:" + SENSOR_LOCATION_NAME + "Vaum (%)", av noo) streamer.log (": huab:" + SENSOR_LOCATION_NAME + "Siab (IN)", pressure_in) streamer.flush () time.sleep (60*MINUTES_BETWEEN_SENSEHAT_READS)

Daim ntawv ceeb toom ntawm thawj kab uas peb tab tom ntshuam lub tsev qiv ntawv SenseHat rau hauv tsab ntawv. Ua ntej koj pib sau tsab ntawv no, peb yuav tsum teeb tsa peb cov neeg siv khoom.

# --------- Neeg Siv Chaw ---------

BUCKET_NAME = "Office Weather" BUCKET_KEY = "sensehat" ACCESS_KEY = "Your_Access_Key" SENSOR_LOCATION_NAME = "Office" MINUTES_BETWEEN_SENSEHAT_READS = 0.1# ------------------------- --------

Tshwj xeeb, koj yuav tsum teeb tsa koj li ACCESS_KEY rau koj li Thawj Lub Xeev tus lej nkag mus siv tus lej. Koj tuaj yeem hloov BUCKET_NAME thiab SENSOR_LOCATION_NAME mus rau qhov tseeb sensor qhov chaw. Txuag thiab tawm ntawm cov ntawv sau.

Ntawm qhov hais kom ua sai sai ntawm koj Pi, khiav tsab ntawv:

$ sudo nab hab sej sensehat.py

Tam sim no koj yuav muaj cov ntaub ntawv xa mus rau Thawj Lub Xeev dashboard. Mus rau ntu kawg ntawm kab lus no kom paub meej txog yuav ua li cas hloov kho koj lub dashboard.

Kauj Ruam 9: Hloov Kho Koj Li Thawj Lub Xeev Dashboard

Customize Your Initial State Dashboard
Customize Your Initial State Dashboard

Mus rau koj Tus Thawj Xeev tus as khauj thiab saib koj cov ntaub ntawv. Koj tuaj yeem nyem rau ntawm Pobzeb los hloov hom kab ntawv thiab nyem Kho kom raug cov vuas kom hloov pauv thiab txav koj cov Vuas ib puag ncig. Kuv xav kom siv lub ntsuas cua ntsuas cua sov thiab ntsuas cov kua ntsuas rau cov av noo. Koj tuaj yeem tsim kab kab kab rau ob qhov kub thiab txias kom pom cov kev hloov pauv nyob rau lub sijhawm. Koj tseem tuaj yeem ntxiv cov duab keeb kwm yav dhau rau koj lub dashboard.

Koj tuaj yeem teeb tsa Kev ceeb toom kom koj tuaj yeem tau txais SMS lossis email yog tias qhov ntsuas kub qis dua hauv qab lossis nce siab dua qhov chaw pib. Mus rau koj lub thoob cov ntaub ntawv thiab nyem rau ntawm qhov chaw. Txij ntawd mus rau Triggers tab. Nkag mus rau tus kwj dej tseem ceeb koj xav tshuaj xyuas, tus neeg teb xov tooj koj xav siv, thiab tus nqi pib. Nyem rau lub cim ntxiv rau ntxiv Trigger. Tom qab ntawd koj yuav nkag mus rau koj tus email lossis tus lej xov tooj kom tau txais kev ceeb toom ntawm thiab nyem qhov cim ntxiv. Thaum koj tau teeb tsa tag nrho koj cov Triggers nyem lub pob Ua tiav hauv qab.

Tam sim no koj tau tsim lub ntsuas ntsuas ntsuas kub uas siv lub ntsuas kub thiab Raspberry Pi, koj tuaj yeem pib xav txog lwm yam ntaub ntawv ib puag ncig koj tuaj yeem saib xyuas tom ntej.

Pom zoo: