Cov txheej txheem:
- Khoom siv
- Kauj Ruam 1: Tsim Circuit Court
- Kauj Ruam 2: Nkag CPU Kub Nrog ThingSpeak
- Kauj Ruam 3: Tau Txais CPU Kub Los ntawm Raspberry Pi Siv Python
- Kauj Ruam 4: Tswj Tus Kheej Raws Li Kub
- Kauj Ruam 5: Kawg Python Code
- Kauj Ruam 6: Saib Xyuas Cov Ntaub Ntawv Ntawm Thingspeak Cloud
- Kauj Ruam 7: Khiav Python Script ntawm Startup
Video: Ntse Tswj ntawm Raspberry Pi Ntxuam Siv Python & Thingspeak: 7 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:26
Qhia me ntsis
Los ntawm lub neej ntawd, tus kiv cua tau txuas ncaj qha rau GPIO - qhov no cuam tshuam nws txoj haujlwm tsis tu ncua. Txawm hais tias tus txheeb ze ua haujlwm ntsiag to ntawm tus kiv cua, nws txoj haujlwm txuas ntxiv tsis yog siv tau zoo ntawm lub tshuab ua kom txias txias. Nyob rau tib lub sijhawm, kev ua haujlwm tas li ntawm tus kiv cua tuaj yeem ua rau muaj kev ntxhov siab xwb. Tsis tas li, yog tias Raspberry Pi raug kaw, tus kiv cua tseem yuav ua haujlwm yog tias lub zog txuas nrog.
Kab lus no yuav qhia yuav ua li cas, siv yooj yim thiab tsis cuam tshuam kev hloov pauv, ua kom lub tshuab txias uas twb muaj lawm dhau los ua qhov ntse, uas yuav tsuas yog qhib thaum tus txheej txheem xav tau tiag tiag. Lub kiv cua yuav tig rau tsuas yog thaum muaj kev siv hnyav, yog li txo cov kiv cua siv zog thiab suab nrov. Kuj txuas ntxiv lub neej kiv cua los ntawm kev ua kom nws tawm thaum tsis xav tau.
Yam Koj Yuav Kawm
Yuav ua li cas txhawm rau siv Python tsab ntawv los tswj tus kiv cua raws qhov ntsuas kub tam sim no ntawm Raspberry CPU siv On-Off tswj nrog kub hysteresis. Yuav ua li cas thauj cov ntaub ntawv los ntawm koj li RaspberryPi rau Yam Hais Lus Huab.
Khoom siv
Cov khoom koj yuav xav tau rau txoj haujlwm no yog raws li hauv qab no
- Raspberry Pi 4 Computer Qauv B 4GB
- NPN transistor S8050330ohms resistor
- Armor Aluminium Hlau Case nrog Dual Kiv cua rau Raspberry Pi
- Jumper cables
- Cov qhob cij
Kauj Ruam 1: Tsim Circuit Court
Lub voj voog yog yooj yim zoo nkauj. Lub zog rau kiv cua raug txiav tawm siv NPN transistor. Hauv qhov kev teeb tsa no, lub transistor ua lub luag haujlwm qis. Resistor tsuas yog yuav tsum tau txwv tam sim no los ntawm GPIO. Raspberry Pi's GPIO muaj qhov tso zis ntau tshaj tam sim no ntawm 16mA. Kuv siv 330 ohms uas muab rau peb lub hauv paus tam sim no txog (5-0.7)/330 = 13mA. Kuv xaiv NPN transistor S8050, yog li hloov 400mA load los ntawm ob tus kiv cua tsis muaj teeb meem.
Kauj Ruam 2: Nkag CPU Kub Nrog ThingSpeak
ThingSpeak yog lub platform rau cov haujlwm raws li Internet ntawm Yam Lub Tswv Yim. Lub platform no tso cai rau koj los tsim cov ntawv thov raws cov ntaub ntawv sau los ntawm cov ntsuas. Cov yam ntxwv tseem ceeb ntawm ThingSpeak suav nrog: khaws cov ntaub ntawv ntawm lub sijhawm, ua cov ntaub ntawv thiab pom kev. ThingSpeak API tsis tsuas yog tso cai rau koj xa, khaws thiab nkag tau cov ntaub ntawv, tab sis kuj tseem muab ntau txoj hauv kev txheeb cais los ua lawv.
ThingSpeak tuaj yeem ua ke cov khoom siv nrov thiab cov kev pabcuam xws li:
- Arduino
- Raspberry pib
- oBridge / RealTime.io
- Fais fab imp
- Mobile thiab Web applications
- Kev sib raug zoo
- Kev Txheeb Xyuas Cov Ntaub Ntawv hauv MATLAB
Ua ntej peb pib, koj xav tau tus as khauj ntawm ThingSpeak.
- Mus rau qhov txuas hauv qab no thiab kos npe rau ThingSpeak.
- Tom qab koj tus account qhib, nkag mus.
- Mus rau Channels -> Kuv Channels
- Nyem rau ntawm Tshiab Channel khawm.
- Nkag mus rau lub npe, piav qhia thiab thaj tsam ntawm cov ntaub ntawv koj xav tshaj tawm
- Nyem rau Txuag Channel khawm kom txuag tag nrho koj cov chaw.
Peb xav tau tus lej API, uas tom qab peb yuav ntxiv rau cov nab npawb nab npawb txhawm rau txhawm rau rub peb lub CPU kub mus rau Thingspeak huab.
Nyem rau ntawm API Keys tab kom tau txais Kev Sau API Key
Thaum koj muaj Tus Sau API Key, peb yuav luag npaj txhij xa peb cov ntaub ntawv.
Kauj Ruam 3: Tau Txais CPU Kub Los ntawm Raspberry Pi Siv Python
Tsab ntawv yog ua raws qhov ntsuas qhov ntsuas kub, uas tshwm sim txhua ob. Nws tuaj yeem tau txais los ntawm lub davhlau ya nyob twg los ntawm kev khiav vcgencmd hais kom ua nrog ntsuas_temp parameter.
vcgencmd ntsuas_temp
Subprocess.check_output () lub tsev qiv ntawv tau siv los ua qhov kev hais kom ua thiab tom qab ntawd siv qhov kev hais qhia ib txwm los rho tawm tus nqi tiag los ntawm txoj hlua rov qab.
los ntawm subprocess ntshuam check_output
los ntawm re import findalldef get_temp (): temp = check_output (["vcgencmd", "measure_temp"]). decode () temp = float (findall ('\ d+\. / d+', temp) [0]) return (temp) print (get_temp ())
Tom qab ntsuas qhov ntsuas kub, cov ntaub ntawv xav tau xa mus rau ThingSpeak huab. Siv koj Cov Ntawv Sau API los hloov pauv myApi hauv qab Python code hauv qab no.
los ntawm urllib ntshuam thov
los ntawm re import findall los ntawm lub sijhawm ntshuam pw los ntawm subprocess import check_output myAPI = '################' baseURL = 'https://api.thingspeak.com/update?api_key=% s ' % myAPIdef get_temp (): temp = check_output (["vcgencmd", "measure_temp"]). decode () temp = float (findall (' / d+\. / d+', temp) [0]) return (temp) sim: thaum Tseeb: temp = get_temp () conn = thov.urlopen (baseURL + '& field1 = % s' % (temp)) print (str (temp)) conn.close () pw (1) tshwj tsis yog KeyboardInterrupt: luam tawm ("Tawm tawm nias Ctrl+C")
Kauj Ruam 4: Tswj Tus Kheej Raws Li Kub
Python tsab ntawv qhia hauv qab no siv cov laj thawj uas tig rau lub kiv cua thaum qhov kub nce siab tshaj qhov ntsuas sov thiab tawm tsuas yog thaum qhov kub tau poob qis dua qhov pib. Txoj kev no, tus kiv cua yuav tsis qhib thiab tawm sai.
ntshuam RPi. GPIO ua GPIO
ntshuam sys los ntawm re import findall los ntawm lub sijhawm ntshuam pw ntawm subprocess ntshuam check_output def get_temp (): temp = check_output (["vcgencmd", "measure_temp"]). decode () temp = float (findall ('\ d+\. / d+ ', temp) [0]) rov (temp) sim: GPIO.setwarnings (Cuav) tempOn = 50 threshold = 10 controlPin = 14 pinState = False GPIO.setmode (GPIO. BCM) GPIO.setup (controlPin, GPIO. OUT, pib = 0) thaum Tseeb: temp = get_temp () yog temp> tempOn thiab tsis pinState lossis temp <tempOn - threshold thiab pinState: pinState = tsis pinState GPIO.output (controlPin, pinState) luam tawm (str (temp) + "" + str (pinState)) pw tsaug zog (1) tshwj tsis yog KeyboardInterrupt: luam tawm ("Tawm nias Ctrl+C") tshwj tsis yog: luam tawm ("Lwm Yam Kev zam") luam tawm ("--- Pib Cov Ntaub Ntawv Tsis Pub:") traceback.print_exc (txwv = 2, file = sys.stdout) print ("--- End Exception Data:") thaum kawg: print ("CleanUp") GPIO.cleanup () print ("End of program")
Kauj Ruam 5: Kawg Python Code
Tus nab npawb nab npawb loj tuaj yeem pom ntawm kuv tus GitHub tus lej hauv qhov txuas hauv qab no. Nco ntsoov muab koj tus kheej Sau API Key.
- Nkag mus rau hauv koj lub Raspberry PI board
- Khiav cov lus txib hauv qab no ntawm lub davhlau ya nyob twg
python3 cpu.py ua
Kauj Ruam 6: Saib Xyuas Cov Ntaub Ntawv Ntawm Thingspeak Cloud
Tom qab ib pliag, qhib koj cov channel ntawm ThingSpeak thiab koj yuav tsum pom qhov ntsuas kub nce mus rau Thingspeak huab hauv lub sijhawm tiag.
Kauj Ruam 7: Khiav Python Script ntawm Startup
Txhawm rau ua qhov no, thaum kawg ntawm /etc/rc.local cov ntaub ntawv:
sudo nano /etc/rc.local
Koj yuav tsum tso cov ntawv pib hais kom ua ntej ntawm kab tawm 0:
sudo nab hab sej /home/pi/cpu.py &
Lub xub ntiag ntawm & cim ntawm qhov kawg ntawm cov lus txib yog qhov yuav tsum tau ua, vim nws yog tus chij kom pib txheej txheem hauv keeb kwm yav dhau. Thaum tom qab rov pib dua, tsab ntawv yuav cia li khiav thiab tus kiv cua yuav qhib thaum lub sijhawm tshwj xeeb tau ntsib.
Pom zoo:
Yuav Ua Li Cas Tus Kheej Mini Ntxuam Ntxuam Tawm ntawm Lub Khoos Phis Tawj Qub - Haum rau hauv Koj Lub Hnab Hnab: 6 Kauj Ruam
Yuav Ua Li Cas Tus Kheej Mini Ntxuam Ntxuam Tawm ntawm Lub Khoos Phis Tawj Qub - Haum rau hauv Koj Lub Hnab Hnab: Kuv yuav qhia koj yuav ua li cas thiaj ua tau tus kheej lub rooj mini kiv cua tawm ntawm lub khoos phis tawj qub. Ib qho ntxiv yog tias nws txawm haum hauv koj lub hnab ris. Nov yog txoj haujlwm yooj yim heev, yog li tsis xav tau kev paub ntau ntxiv lossis kev txawj ntse. Yog li cia pib
Ntxuam Ntxuam Ua Ntse: 7 Kauj Ruam
Dumb Ntxuam Ua Ntse: Kuv xav ua tus kiv cua zoo li lub ntsej muag ntse, vim tias kuv tau dhuav uas tau qhib nws thiab tawm ntawm tus kheej, thaum nws hla mus rau lwm sab ntawm chav thiab kuv nyob ntawm lub rooj zaum lossis hauv txaj. Kuv kuj xav kom tuaj yeem ncua sijhawm thaum kuv mus pw. Qee tus kiv cua
Arduino Neeg Hlau Nrog Kev Nyob, Kev Qhia thiab Qib Kev Sib Hloov (Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) Tswj los ntawm Lub Suab Siv Bluetooth Module thiab Kev Siv Tus Neeg Siv Hluav Taws Xob: 6 Kauj Ruam
Arduino Neeg Hlau Nrog Kev Nyob, Kev Qhia thiab Qib Kev Sib Hloov (Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) Tswj los ntawm Lub Suab Siv Bluetooth Module thiab Kev Siv Tus Neeg Siv Hluav Taws Xob: Cov lus qhia no piav qhia yuav ua li cas thiaj tsim tau Arduino Robot uas tuaj yeem txav mus raws qhov xav tau (Forward, Backward) , Sab laug, Txoj Cai, Sab Hnub Poob, Sab Hnub Poob, Sab Qaum Teb, Sab Qab Teb) xav tau Kev nrug deb hauv Centimeters siv lub suab hais kom ua. Neeg hlau kuj tseem tuaj yeem txav tau tus kheej
Kev tswj hwm tus kheej ntawm RPM ntawm Lub Cav Siv Lub Tswv Yim Los Ntawm IR Raws Li Tachometer: 5 Cov Kauj Ruam (nrog Duab)
Kev Tswj Tus Kheej ntawm RPM ntawm Lub Cav Siv Lub Tswv Yim Los Ntawm IR Raws Lub Tachometer: Muaj ib txwm xav tau rau kev siv tshuab txheej txheem, ua nws yooj yim/tsis txaus ntseeg. cov txheej txheem rau dej/siv dej rau peb daim av me me.Qhov teeb meem ntawm tsis muaj kab khoom siv tam sim no
Txo Kev Ntxuam Ntxuam ntawm NAS Ntaus: 6 Kauj Ruam
Txo Kev Ntxuam Ntxuam ntawm NAS Ntaus.: Wow, kuv thawj qhov kev qhia yog li thov ua siab mos siab muag.Kuv lub tsev network muaj, ntawm lwm yam, NAS ntaus ntawv. Nov yog lub cuab yeej uas koj yuav khiav 24x7 rau qhov muaj nyob rau qhov yog? Txawm li cas los xij kuv nyiam khaws cov cuab yeej no hauv chav nyob, vim tias