Cov txheej txheem:

Ua tiav Raspberry Pi Huab Cua Chaw Nres Tsheb: 14 Cov Kauj Ruam (nrog Duab)
Ua tiav Raspberry Pi Huab Cua Chaw Nres Tsheb: 14 Cov Kauj Ruam (nrog Duab)

Video: Ua tiav Raspberry Pi Huab Cua Chaw Nres Tsheb: 14 Cov Kauj Ruam (nrog Duab)

Video: Ua tiav Raspberry Pi Huab Cua Chaw Nres Tsheb: 14 Cov Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station
Ua tiav Raspberry Pi Weather Station

Nyob zoo sawv daws, Nov yog kuv thawj zaug Qhia! Hauv qhov kev qhia no kuv yuav coj koj los ua Raspberry Pi huab cua chaw nres tsheb nrog nws tus kheej database thiab lub vev xaib. Kuv tau ua qhov chaw nres tsheb huab cua no raws li lub luag haujlwm hauv tsev kawm ntawv, Kuv tau txais kev tshoov siab ntawm Kev Qhia Ntawv. Chaw nres tsheb huab cua tuaj yeem ntsuas qhov ntsuas kub, av noo, ntsuas siab, ntsuas cua nrawm thiab teeb pom kev hauv feem pua. Txhua qhov piv txwv uas Raspberry Pi sib sau ua ke yuav muab khaws cia hauv MySQL server ntawm Pi nws tus kheej thiab yuav nthuav tawm ntawm lub vev xaib!

Kauj Ruam 1: Sau Koj Cov Khoom

Cov ntaub ntawv ntawm qhov chaw nres tsheb no yooj yim heev. Koj yuav xav tau txhua cov ntaub ntawv tsim nyog, ntsuas thiab tsev nyob.

Khoom siv

Raspberry Pi

Hom tsis muaj teeb meem ntau, koj tseem tuaj yeem siv Raspberry Pi Zero W tab sis nco ntsoov tsis txhob ua thawj qhov kev kho dua vim tias koj yuav xav tau kev sib txuas network rau lub vev xaib. Hauv Cov Lus Qhia Kuv yuav siv Raspberry Pi 3.

www.amazon.com/Raspberry-Model-A1-2GHz-64-…

Qee cov jumper cables

Koj yuav xav tau qee cov txuas txuas rau txhua lub ntsuas cua thiab nti nrog koj li Raspberry Pi. Muaj peb hom jumper cables: txiv neej rau poj niam, txiv neej rau txiv neej thiab poj niam rau poj niam. Koj yuav xav tau ib ncig ntawm 15 tus txiv neej rau poj niam thiab txiv neej rau txiv neej hom. Xijpeem nws yuav tsis ua mob kom tau txais peb ntawm lawv.

www.amazon.com/Elegoo-120pcs-Multicolored-…

Cov qhob cij

Ua cov khoom siv hluav taws xob yam tsis muaj lub khob cij yog qhov tsis zoo. Yog tias koj npaj yuav ua ntau dua DIY cov khoom siv hluav taws xob qhov no ib txwm tuaj yeem ua ke.

www.amazon.com/dp/B072FC35GT/ref=sxr_pa_cl…

Sensors

Kub thiab av noo: Grove Temp & Hum v1.0

www.seeedstudio.com/Grove-Temperature%26Hu..

Barometric siab: Grove - Barometer Sensor BMP280 (lub ntsuas no tseem ntsuas kub)

www.seeedstudio.com/Grove-Barometer-Sensor…

Cua ceev: Infrared Sensor Module (FC-03) LM393

www.amazon.com/LM393-Measuring-Sensor-Phot…

Lub teeb: Pom lub teeb pom kev zoo (ceeb toom: qhov no yog qhov ntsuas sib xws, sib piv rau cov hloov pauv digital xws li MCP3008 yog qhov tsim nyog)

www.seeedstudio.com/Grove-Light-Sensor-v1….

Vaj tse

Vaj tsev yog ib feem tseem ceeb heev ntawm koj qhov haujlwm. Ntawm no koj yuav tso tag nrho koj cov khoom siv hluav taws xob thiab cov ntsuas. Lub tsev tsis tas yuav zoo nkauj tab sis nws paub tseeb tias tuaj yeem ua tau. Hauv Cov Lus Qhia no Kuv yuav ua lub tsev noog nrog lub qhov nyob hauv qab uas kuv tuaj yeem khaws kuv li Raspberry Pi.

Koj tuaj yeem xaiv ib lub tsev tsis muaj zog xws li lub thawv hluav taws xob dawb. Qhov xwm txheej tsuas yog tias yuav tsum muaj lub qhov cua kom cua thiab cua tuaj yeem hla dhau lub ntsuas cua, txwv tsis pub koj yuav tsis tau txais cov qauv raug.

Kauj Ruam 2: Txuas Txhua Yam Khoom

Txuas Tag Nrho Cov Cheeb Tsam
Txuas Tag Nrho Cov Cheeb Tsam
Txuas Tag Nrho Cov Cheeb Tsam
Txuas Tag Nrho Cov Cheeb Tsam
Txuas Tag Nrho Cov Cheeb Tsam
Txuas Tag Nrho Cov Cheeb Tsam

Thaum koj muaj tag nrho koj cov khoom siv, koj tuaj yeem pib los ntawm kev teeb tsa kev xeem. Ntawm no koj txuas txhua yam ntawm koj cov khoom siv hluav taws xob rau koj li Raspberry Pi. Koj tuaj yeem pom Fritzing schematic hauv cov ntawv. Thaum txhua qhov kev sib txuas ua tiav koj tuaj yeem pib los ntawm teeb tsa koj li Raspberry Pi.

Kauj Ruam 3: Teeb Raspberry Pi

Teeb Raspberry Pi
Teeb Raspberry Pi

Yog tias qhov no yog koj thawj zaug ua haujlwm nrog Raspberry Pi Kuv pom zoo kom koj mus ntsib raspberrypi.org lub vev xaib, nws muaj qee cov ntaub ntawv zoo thiab qhia qhia rau cov pib tshiab.

www.raspberrypi.org

Nco ntsoov tias koj tab tom khiav qhov tseeb ntawm Debian. Koj tuaj yeem hloov kho los ntawm kev ntaus hauv lub davhlau ya nyob twg hauv Raspberry Pi lossis hauv ntu SSH:

sudo apt-tau hloov tshiab & sudo apt-tau hloov tshiab

Kauj Ruam 4: Nruab SPI thiab I2C

Nruab SPI thiab I2C
Nruab SPI thiab I2C
Nruab SPI thiab I2C
Nruab SPI thiab I2C

Thaum koj tau hloov kho tag nrho, peb yuav tau hloov qee qhov kev teeb tsa ntawm peb Raspberry Pi. Txhua qhov sib txawv sib txawv tshwj tsis yog lub teeb pom kev thiab lub ntsuas hluav taws xob nrawm siv I2C raws tu qauv. Yog tias koj xav siv cov txheej txheem no nrog rau SPI interface koj yuav xav tau kom ua tau qhov no hauv kev teeb tsa ntawm Raspberry Pi. Koj tuaj yeem teeb tsa SPI thiab I2C interface los ntawm kev ua raws cov lus txib no.

sudo raspi-teeb tsa

Pab kom SPI thiab I2C. Tom qab ntawd reboot siv:

sudo rov pib dua

Thaum rov pib dua, peb yuav tshuaj xyuas yog tias "dtparam = spi = on" thiab "dtsparam = i2C_arm = on" nyob hauv /boot /config file. Thaum koj tau pom cov kab no koj yuav tsum tsis pom zoo rau cov no.

sudo nano /boot /config.txt

Tawm tus editor siv ctrl + x thiab txuag.

Tam sim no peb tab tom yuav teeb tsa lub tsev qiv ntawv sib txawv rau kev tswj cov ntsuas.

sudo apt-tau nruab python3-spidev

sudo apt-tau nruab python-smbus sudo apt-tau nruab i2c-cuab yeej

Kauj ruam 5: Nruab MySQL

Nruab MySQL
Nruab MySQL
Nruab MySQL
Nruab MySQL
Nruab MySQL
Nruab MySQL

Thaum koj tau teeb tsa cov hauv paus ntawm Raspberry Pi xws li txuas rau internet thiab hloov kho software. Peb tuaj yeem pib teeb tsa peb cov txheej txheem database uas peb yuav khaws tag nrho peb cov ntaub ntawv huab cua. Peb yuav siv MySQL. Nov yog qhov yooj yim siv cov txheej txheem database uas peb tuaj yeem txuas ntau lub rooj sib tham nrog lwm tus siv kev sib raug zoo. Txhawm rau nruab MySQL hom hauv lub davhlau ya nyob twg:

sudo apt-tau nruab mysql-server

sudo apt-tau nruab mysql-client

Thaum lub sijhawm teeb tsa koj yuav tau txais kev tshoov siab kom sau tus password rau tus neeg siv hauv paus. Koj yuav xav tau tus password no tom qab. Thaum cov pob no tau teeb tsa koj tuaj yeem tshawb xyuas qhov xwm txheej ntawm koj MySQL server los ntawm kev ntaus ntawv:

mysql -root -p

xwm txheej

Kauj Ruam 6: Khiav Database Script

Khiav Database Script
Khiav Database Script
Khiav Database Script
Khiav Database Script

Thaum MySQL server ua haujlwm, peb tuaj yeem khiav cov ntawv sau. Tsab ntawv no yuav tsim tus qauv nrog cov ntxhuav sib txawv hauv nws. Ntawm no peb yuav khaws txhua hnub uas lub ntsuas ntsuas thiab txhua qhov sib txawv teeb tsa lub vev xaib siv.

Txhawm rau khiav MySQL tsab ntawv los ntawm Pi, peb yuav tsum xub luam tsab ntawv mus rau Raspberry Pi. FileZilla yog txoj hauv kev zoo rau luam cov ntaub ntawv ntawm koj lub PC thiab koj Pi. Nov yog cov lus qhia zoo yuav ua li cas.

www.raspberrypi.org/documentation/remote-a…

Thaum tsab ntawv nyob ntawm koj Pi koj tuaj yeem khiav nws los ntawm kev ntaus hauv lub davhlau ya nyob twg:

mysql -root -p

qhov chaw /path/to/script.sql

Kauj Ruam 7: Txhim Kho MySQL Txuas rau Python3

Txhim kho MySQL Connector rau Python3
Txhim kho MySQL Connector rau Python3

Peb xav txuas peb cov ntaub ntawv rau lub vev xaib uas khiav ntawm Python3. Txhawm rau nruab qhov txuas no koj ua qhov haujlwm no.

sudo apt-tau nruab python3-mysql.connector

Kauj Ruam 8: Txhim Kho Flask

Nruab Flask
Nruab Flask

Lub webserver siv Flask. Cov microframework no tau hloov kho tau yooj yim thiab siv tau yooj yim. Zoo meej rau peb qhov chaw nres tsheb huab cua. Txhawm rau nruab lub raj mis ntaus cov lus txib no hauv lub qhov rai davhlau ya nyob twg.

sudo apt-tau nruab python3-flask

Kauj Ruam 9: Luam lub vev xaib ntawm koj li Raspberry Pi

Luam lub vev xaib ntawm koj li Raspberry Pi
Luam lub vev xaib ntawm koj li Raspberry Pi

Txhua pob tau teeb tsa tam sim no thiab txhua yam tau teeb tsa. Tam sim no peb tuaj yeem luam qhov chaws los ntawm GitHub. Muaj ob txoj hauv kev koj tuaj yeem tau txais tus lej ntawm koj tus Raspberry Pi: koj tuaj yeem rub tawm tus tswv zip file thiab luam nws ntawm koj Pi nrog FileZilla lossis koj tuaj yeem clone lub chaw cia khoom ncaj qha ntawm koj Raspberry Pi. Txhawm rau clone qhov chaw cia koj ntaus cov lus txib no ntawm koj Pi.

cd/path/koj/nyiam/

git clone

Tam sim no koj yuav tsum muaj cov npe tshiab hu ua WeatherStation. Koj tuaj yeem tshawb xyuas qhov no nrog cov lus qhia hauv qab no:

ls ua

Kauj Ruam 10: Hloov kho Database Class

Kho cov Database Class
Kho cov Database Class
Kho cov Database Class
Kho cov Database Class

Tag nrho cov cai tam sim no ntawm koj li Raspberry Pi. Ua ntej peb tuaj yeem sim, peb yuav tsum teeb tsa MySQL-txuas. Cov teeb tsa ntawm qhov txuas tau muab khaws cia rau hauv phau ntawv teev npe tshiab. Txhawm rau mus rau cov ntaub ntawv peb yuav tsum hloov peb cov npe tam sim no. Thaum peb tau pom cov ntaub ntawv peb yuav nkag mus rau peb tus lej nkag hauv paus ntawm peb MySQL server hauv cov ntawv. Koj tuaj yeem ua qhov no los ntawm ua raws cov lus txib no.

cd WeatherStation/Flask/Database/

nano pswd.py

Tam sim no koj tuaj yeem hloov kho cov ntawv. Hloov "your_password" nrog koj lub hauv paus MySQL password. Tam sim no peb tau npaj los sim cov cai.

Kauj ruam 11: Xeem

Kev Xeem
Kev Xeem

Tam sim no txhua yam thaum kawg tau teeb tsa thiab txuas txuas, peb tuaj yeem pib ntsuas. Mus rau Flask directory thiab ntaus cov lus txib:

nab hab sej3 Flask.py

Txhua yam yuav tsum pib. Tam sim no koj tuaj yeem mus rau koj lub vev xaib los ntawm kev ntaus koj tus lej chaw nyob: http: IP_RASPBERRY: 5000/.

Kauj Ruam 12: Lub Vev Xaib

Lub Vev Xaib
Lub Vev Xaib

Thaum koj qhib lub xaib thawj zaug koj yuav pom lub vijtsam nkag. Koj tuaj yeem nkag mus rau hauv lub xaib yog tias koj siv lub npe siv 'Lander' thiab tus password 'Test12'. Lub vev xaib tau sau ua lus Dutch, koj tuaj yeem txhais lub vev xaib yog tias koj muaj kev paub txog kev txhim kho web.

Kauj Ruam 13: Muab txhua yam tso rau hauv qhov kaw

Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw
Muab txhua yam tso rau hauv daim ntawv kaw

Nqa koj lub tsev thiab tso cov khoom siv hluav taws xob kom muaj qhov sib nrug sib nrug. Kuv yuav siv kuv lub tsev ua noog tshiab, kuv suav nrog cov qauv tsim hauv qab no. Nws yog lub npov yooj yim nrog hauv qab tsis raug los khaws Raspberry Pi.

Nco tseg: ib txwm yuav tsum muaj cov kwj ntawm cov pa nkag mus rau qhov ntsuas cua kom ua haujlwm tau zoo. Thaum koj txaus siab rau qhov tshwm sim koj tuaj yeem kaw txhua yam thiab chaw nres tsheb huab cua tau ua tiav. Tam sim no koj tuaj yeem tso nws nyob qhov twg koj nyiam thiab khaws cov ntaub ntawv huab cua.

Kauj Ruam 14: Koj Lub Chaw Haujlwm Huab Cua Ua Haujlwm

Koj Lub Chaw Huab Cua Ua Haujlwm
Koj Lub Chaw Huab Cua Ua Haujlwm
Koj Lub Chaw Huab Cua Ua Haujlwm
Koj Lub Chaw Huab Cua Ua Haujlwm
Koj Lub Chaw Huab Cua Ua Haujlwm
Koj Lub Chaw Huab Cua Ua Haujlwm

Nrog koj zoo siab Raspberry Pi tam sim no ua haujlwm tau zoo. Muab nws tso rau qhov chaw qhib thiab khaws cov ntaub ntawv!

Pom zoo: