Cov txheej txheem:

Lub suab nrov tsaus ntuj nti: 11 Kauj Ruam (nrog Duab)
Lub suab nrov tsaus ntuj nti: 11 Kauj Ruam (nrog Duab)

Video: Lub suab nrov tsaus ntuj nti: 11 Kauj Ruam (nrog Duab)

Video: Lub suab nrov tsaus ntuj nti: 11 Kauj Ruam (nrog Duab)
Video: Tiam no swb koj rau luag by: Pob Tsuas Xyooj (2022 New Song) 2024, Kaum ib hlis
Anonim
Lub suab nrov tsaus ntuj
Lub suab nrov tsaus ntuj
Lub suab nrov tsaus ntuj
Lub suab nrov tsaus ntuj

Nov yog qhov haujlwm kuv tau ua rau kuv muaj 1 xyoos rau Christmas. Ua siab ncaj tab sis, nws yog qhov muaj txiaj ntsig zoo rau kuv thiab kuv tus poj niam. Nws yog lub tshuab suab nrov dawb uas tuaj yeem ua ntau lub suab sib txawv xaiv los ntawm lub vev xaib, thiab tseem suav nrog teeb uas hloov xim raws lub sijhawm (teeb liab txhais tau tias yog nyob hauv txaj, daj txhais tau tias koj tuaj yeem ua si hauv koj chav, thiab ntsuab txhais tau tias nws zoo. tawm los). Txij li thaum kuv tus tub tseem hluas dhau los qhia sijhawm, lub teeb pom kev hmo ntuj zoo li lub tswv yim zoo tiag tiag.

Nws yog txoj haujlwm yooj yim heev, thiab txij li kuv twb tau sau cov cai lawm, tej zaum nws yog 1 ntawm 5 ntawm qhov nyuaj. Yog tias koj muaj cov menyuam me uas thab thab thaub koj li thaum sawv ntxov ntxov, koj yuav xav ua ib qho.

Kauj Ruam 1: Daim Ntawv Teev Npe

Daim Ntawv Teev Npe
Daim Ntawv Teev Npe
Daim Ntawv Teev Npe
Daim Ntawv Teev Npe
Daim Ntawv Teev Npe
Daim Ntawv Teev Npe

1. Raspberry Pi Zero W.

2. Qee qhov xwm txheej (Kuv siv qhov no los ntawm Amazon)

3. Blinkt los ntawm Pimoroni

4. Hais lus Phat los ntawm Pimoroni (Koj kuj tseem tuaj yeem siv qee qhov DAC nrog tus hais lus pheej yig)

Koj yuav tsum muaj qee qhov txuj ci yooj yim los ua ke ua tus hais lus phat, muaj qhov txuas nrog cov lus qhia ib qib zuj zus los ntawm nplooj ntawv khoom, yog li koj tsis tuaj yeem ntsia nws.

5. [Xaiv tau] Vaj huam sib luag mount micro USB cable - los ntawm Adafruit

6. qee qhov txuas xov lossis cov dhia

Qhov ntawd yog nws!

Kauj Ruam 2: Hlawv Raspbian thiab Nqa Cov Rooj

Hlawv Raspbian thiab Hook Up the Boards
Hlawv Raspbian thiab Hook Up the Boards

Kuv tab tom siv Raspian Stretch lite rau qhov kev tsim no. Yog li hlawv qhov ntawd mus rau microSD nrog cov cuab yeej twg ua haujlwm rau koj, tom qab ntawd tua hluav taws. Yog tias koj xav tau kev pab kom tsis muaj lub taub hau pi txuas rau koj lub tsev wifi thiab pab tau ssh, muaj ntau cov kev qhia hauv online uas tuaj yeem qhia koj yuav ua li cas, tab sis koj yuav tsum tau ua kom ntseeg tau tias koj tau ua tiav tas ntawm qhov no mus ua hauj lwm

Siv https://pinout.xyz koj tuaj yeem rub ob lub laug cam thiab tau txais lawv cov pinouts ntawm lub xaib no. Blinkt cov laug cam tsuas xav tau 4 kev sib txuas, thiab Tus Hais Lus Phat xav tau 9.

Nws yuav tsum zoo li daim duab thaum ua tiav. Tam sim no peb yuav tsum sim tias txhua yam ua haujlwm.

Kauj Ruam 3: Txhim Kho Qhov Software Yuav Tsum Tau

Tam sim no uas peb tau txuas nrog, peb yuav tsum tau teeb tsa software uas yuav tsum tau ua rau Blinkt thiab Hais Lus Phaj laug. SSH hauv tus pi, thiab koj yuav pom koj tus kheej hauv cov npe hauv tsev. Nkag mus rau hauv qab no:

curl https://get.pimoroni.com/blinkt | tsoo

thiab tom qab ntawd thaum ua tiav, qhov no:

curl -sS https://get.pimoroni.com/speakerphat | tsoo

Qhov ntawd yuav teeb tsa txhua yam xav tau rau ob lub Pimoroni cov laug cam. Yog tias koj nkag mus rau lo lus txib, koj yuav tsum pom Pimoroni cov npe. Yog li tam sim no cia peb sau qee cov cai thiab sim Blinkt board.

Kauj Ruam 4: Sau qee Cov Cai thiab Xeem Nws

Ua cov npe hu ua "cov ntawv" los ntawm kev sau mkdir cov ntawv thiab peb yuav khaws txhua yam peb xav tau kom khiav hauv qhov ntawd. Yog li cd sau ntawv kom tau koj tus kheej rau hauv daim nplaub tshev ntawd.

Tam sim no, yam peb xav tau yog lub teeb liab liab rau hmo ntuj, teeb daj daj rau lub sijhawm ua si ntsiag to, thiab lub teeb ntsuab ntsuab me ntsis thaum nws tawm los. Rau kuv, Kuv xav tau lub teeb liab txij thaum 7:30 tsaus ntuj txog 6:15 teev sawv ntxov, thiab thaum 6:15 teev sawv ntxov lawv yuav tig daj rau ib teev, thiab thaum kawg ntsuab thaum 7:15 teev sawv ntxov. Kuv kuj xav kom lawv tua thaum 8:30 teev sawv ntxov thaum tsis muaj leej twg zoo li yuav nyob hauv chav.

Muaj ob txoj hauv kev los ua qhov no. Thawj zaug (txoj kev uas kuv xaiv ua nws) yog nrog plaub daim ntawv sib txawv, khiav los ntawm cov haujlwm cron. Lwm txoj hauv kev los ua nws, yog ib tsab ntawv, uas suav nrog lub sijhawm ua haujlwm uas tau pib thaum pib. Kuv tau sau tsab ntawv los ua qhov ntawd ua ntej, tab sis nws zoo li tsis muaj txiaj ntsig ntau dua li ua raws cron, yog li kuv hloov nws. Yog tias koj xav tau "ib tsab ntawv" txoj kev, qhia rau kuv paub thiab kuv tuaj yeem tshaj tawm nws hauv cov lus.

Yog li, cia pib nrog tsab ntawv liab. Ntaus kov red.py, tom qab ntawd nano red.py. Tom qab ntawd sau cov cai hauv qab no.

#!/usr/bin/env nab hab sej

ntshuam blinkt blinkt.set_clear_on_exit (Cuav) blinkt.set_brightness (0.3) blinkt.set_pixel (3, 128, 0, 0) blinkt.set_pixel (4, 128, 0, 0) #sets pixels 3 thiab 4 rau liab blinkt.show ()

Ua tib yam rau yellow.py thiab green.py.

daj.py:

#!/usr/bin/env nab hab sej

ntshuam blinkt blinkt.set_clear_on_exit (Cuav) blinkt.set_brightness (0.2) blinkt.set_pixel (2, 128, 128, 0) blinkt.set_pixel (3, 128, 128, 0) blinkt.set_pixel (4, 128, 128, 0) blinkt.set_pixel (5, 128, 128, 0) #sets pixels 2, 3, 4, thiab 5 rau daj blinkt.show ()

ntsuab.py:

#!/usr/bin/env nab hab sej

ntshuam blinkt blinkt.set_clear_on_exit (Cuav) blinkt.set_brightness (0.2) blinkt.set_all (0, 128, 0) #sets tag nrho cov pixels rau ntsuab blinkt.show ()

Thiab thaum kawg, peb xav kom tsab ntawv tshem tawm Blinkt thaum nws tsis xav tau (lightsout.py):

#!/usr/bin/env nab hab sej

ntshuam blinkt blinkt.set_clear_on_exit (Tseeb) blinkt.set_brightness (0.1) blinkt.set_all (0, 0, 0) #sets tag nrho cov pixels kom tawm blinkt.show ()

Qhov ntawd yog nws. Txhawm rau ntsuas hom nab hab sej red.py thiab pom yog ob lub nruab nrab pixels teeb liab. Tom qab ntawv ntaus nab hab sej lightsout.py kom tshem nws. Qhov ntawd yog nws! Tom ntej no peb yuav tsum teeb tsa cov ntawv hauv cron tab kom lawv ua haujlwm thaum peb xav kom lawv ua.

Kauj Ruam 5: Ntxiv Cov Ntawv Sau rau Cron

Hauv SSH lub davhlau ya nyob twg hom crontab -e

nqes mus rau qhov kawg ntawm cov ntawv thiab ntxiv cov kab hauv qab no:

15 6 * * * nab hab sej /home/pi/scripts/yellow.py15 7 * * * nab hab sej /home/pi/scripts/green.py 30 8 * * * nab hab sej /home/pi/scripts/lightsout.py 30 19 * * * nab hab sej /home/pi/scripts/red.py

Uas teeb tsa cov ntawv sau kom khiav ntawm lub sijhawm tau piav qhia hauv cov kauj ruam dhau los, mus tom ntej thiab kho cov no kom haum rau koj cov kev xav tau.

Qhov ntawd yog qhov tsaus ntuj! Yooj yim heev. Tam sim no cia peb txav mus rau teeb tsa Lub suab nrov dawb ntawm qhov kev tsim no.

Kauj Ruam 6: Xeem Tus Hais Lus Phaj

Txoj hauv kev yooj yim tshaj plaws (hauv kuv lub tswv yim) sim tawm Tus Hais Lus Phat yog los ntawm kev txhim kho sox thiab khiav qee qhov zoo li qub los ntawm kab hais kom ua.

sudo apt-tau nruab sox

Thaum uas tau teeb tsa, peb tuaj yeem sim qee qhov piv txwv ua si cov lus txib. Qhov no yuav tsum zoo li nthwv dej.

play -n synth brownnoise synth pinknoise mix synth 0 0 0 10 10 40 trapezium amod 0.1 30

Yuav ua li cas so! Ctrl+c yuav nres nws. Tab sis, yog dab tsi? Muaj ib pawg ntawm LEDs hla lub ntsej muag ntawm Tus Hais Lus Phat teeb pom kev zoo, thiab peb tsis tuaj yeem muaj qhov cuam tshuam nrog peb lub teeb Blinkt. Yog li cia tua cov ntawd.

Txhawm rau ua qhov no, peb yuav tsum hloov kho /etc/asound.conf cov ntaub ntawv thiab tshem tawm VU meter plugin, yog li nws yuav tsis txawm sim tsav lub LEDs hauv thawj qhov chaw. Kuv tau ua qhov no los ntawm kev hloov nws yooj yim. Ntaus cov lus txib no mv /etc/asound.conf /etc/asound.conf.bak Kuv pom qhov no dhau ntawm Googling me ntsis, yog li yuav muaj txoj hauv kev zoo dua.

Sox ua haujlwm, thiab qhov ntawd zoo heev, tab sis kuv tau npaj siv qee qhov txuas MP3s rau lub suab nrov dawb ib feem ntawm lub tshuab no, yog li kuv xav tau tus neeg siv sib txawv, nyiam dua ib yam uas hnyav heev. mpg123 yog qhov kuv nyob ntawm. Nruab qhov tam sim no nrog sudo apt-tau nruab mpg123

Ok, tam sim no peb paub Tus Hais Lus Phat ua haujlwm raws li xav tau, lub sijhawm los tsim lub interface thiab cov ntawv sau sib xws.

Kauj Ruam 7: Teeb tsa Lub Vev Xaib Me thiab Webapp

Flask yog lub vev xaib micro web sau hauv Python. Nws muab txhua txoj haujlwm peb xav tau rau lub vev xaib (uas yuav ua raws li app). Nruab nws nrog cov lus txib hauv qab no:

pip3 nruab lub raj mis

Qhov ntawd yuav siv qee lub sijhawm, yog li tos nws tawm. Thaum nws ua tiav, peb yuav xav tsim cov ntawv tais ceev tseg peb yuav xav rub los ntawm thaum lub vev xaib khiav, thiab cov ntawv no muaj cov npe tshwj xeeb. Cia peb pib nrog qhov chaw los tuav lub vev xaib. Los ntawm cov npe hauv tsev, ua cov npe tshiab hu ua www nrog mkdir www. Tam sim no cd www hauv phau ntawv ntawd. Hauv no peb xav tau ob phau ntawv teev npe ntxiv, ib qho hu ua zoo li qub thiab lwm qhov hu ua qauv.

Peb kuj xav tau ib qho chaw tso peb lub voj MP3. Kuv tau sau cov npe hauv cov npe hauv tsev hu ua "suab" rau qhov no. Kuv pom kuv MP3s los ntawm kev tshawb nrhiav rau loopable whitenoise MP3s hauv Google. Ntau qhov chaw pub dawb rub los ntawm. Kuv siv WinSCP txhawm rau upload cov ntawv.

Koj yuav xav sim lawv nrog omxplayer hais kom ua hauv qab no ua si nrog --vol -### ib feem los hu rau hauv qhov ntim ntim raug rau koj chav. Ib zaug ntxiv Ctrl+C yuav nres tus neeg ua si.

Tam sim no peb muaj txhua tus nyob hauv qhov chaw, cia sau qee tus nab nab los sawv ntawm lub vev xaib thaum lub pi pib. Rov qab mus rau www directory thiab pib ib daim ntawv tshiab hu ua webapp.py (nano webapp.py) thiab ntxig cov cai hauv qab no

webbapp.py: ua

#!/usr/bin/nab hab sej

los ntawm lub raj mis ntshuam Flask, render_template, thov, xa rov qab ntshuam os app = Flask (_ name_) @app.route ('/') def index (): return render_template ('index.html') @app.route ('/nag', txoj kev = ['POST']) def nag (): os.system ("mpg123 -f 8000 --loop -1 ~/scripts/sounds/rain.mp3") rov xa rov qab ('/') @app.route ('/wave', method = ['POST']) def def (): os.system ("mpg123 -f 20500 --loop -1 ~/scripts/sounds/waves.mp3") rov xa rov qab ('/') @app.route ('/whitenoise', method = ['POST']) def whitenoise (): os.system ("mpg123 --loop -1 ~/scripts/sounds/whitenoise.mp3") xa rov qab redirect (' /') @app.route ('/nres ', cov hau kev = [' POST ']) def nres (): os.system ("killall mpg123") rov xa rov qab ('/') yog _name_ ==' _main_ ': app.run (debug = Tseeb, host = '0.0.0.0')

Raws li koj tuaj yeem pom lub webapp no yuav muaj 5 nplooj ntawv, ib qho rau qhov ntsuas, 3 rau 3 lub suab sib txawv (yoj, nag thiab whitenoise) thiab 1 ntxiv kom nres. Txhua 4 nplooj ntawv tsis-ntsuas rov qab mus rau qhov ntsuas ('/') tom qab lawv ua raws cov lus txib xa mus rau omxplayer, yog li peb tsuas xav tsim ib qho index.html, thiab tsis muaj dab tsi ntxiv. Kuv tab tom siv killall ntawm no ua qhov kev ua haujlwm nres, vim tias kuv tsis tuaj yeem nrhiav txoj hauv kev zoo dua los xa qhov "nres" hais kom omxplayer. Yog tias koj paub txoj hauv kev zoo dua los ua qhov no, Kuv xav hnov nws!

Tam sim no cia peb ua ke index.html.

Kauj Ruam 8: Tsim Lub Vev Xaib

Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib

Cov no yog cov duab kuv siv rau kuv tsim, tab sis xav tias dawb los ua koj tus kheej. Lawv txhua tus yuav tsum tau txais kev cawmdim hauv cov ntawv zoo li peb tau ua dhau los. Cov ntawv index.html peb yuav ua rau ntawm no xav tau nyob hauv cov ntawv tais ceev tseg. Qhov ntawd tseem ceeb heev, txwv tsis pub nws yuav tsis ua haujlwm. Nov yog cov cai rau kuv qhov index.html (dua, qhov no tsuas yog html yooj yim, yog li hloov kho nws hauv txhua txoj kev ua haujlwm rau koj).

Txij li cov lus qhia yuav tsis cia kuv tshaj tawm HTML nyoos, ntawm no yog qhov txuas rau cov ntawv raws li nws muaj nyob ntawm kuv Dropbox:

www.dropbox.com/s/n5xf2btftk5sz9b/index.ht…

Tab sis nyob rau hauv rooj plaub uas puas tau tuag, HTML cov ntaub ntawv tsuas yog qee qhov zoo nkauj CSS, thiab yooj yim 2x2 lub rooj nrog cov 4 cim ua cov nyees khawm nrog cov ntsiab lus tshaj tawm zoo li:

daim ntawv txiav txim = "/whitenoise" method = "post"

input src = "/zoo li qub/whitenoise.png" tus nqi = "Lub suab nrov dawb"

Yuav tsum yooj yim zoo nkauj los ua koj tus kheej.

Kauj ruam kawg yog kom paub tseeb tias webapp.py khiav thaum pib, dua, kuv tau ua qhov no los ntawm kev ntxiv nws rau crontab. Yog li ib zaug ntxiv ntaus crontab -e thiab ntxiv cov hauv qab no mus rau qhov kawg:

@reboot python3 /home/pi/www/webapp.py

Tom qab ntawd rov pib dua pi, taw tes rau browser ntawm lwm lub tshuab (koj lub xov tooj) mus rau IP ntawm pi (zoo tshaj yog tias koj tuaj yeem ua qhov zoo li qub no) thiab pom tias nws ua haujlwm li cas. Nyem cov nyees khawm thiab pom yog tias koj tau txais lub suab nrov.

Hauv lub xov tooj Android koj tuaj yeem cim lub vev xaib rau koj lub vijtsam hauv tsev, uas yog qhov kuv tau ua nrog qhov no kom nws saib thiab zoo li lub app. Yog tias koj xav ua tiag tiag kom nws zoo li "pro" pom lossis tsim tsim.ico cov ntaub ntawv thiab muab lub vev xaib nws tus kheej lub cim uas yuav tshwm rau ntawm koj lub xov tooj lub vijtsam hauv tsev thiab zoo li ntau dua li app. Ntau ntau ntawm kev qhia online yuav ua li cas ntxiv lub cim (favicon) rau lub vev xaib.

Kauj Ruam 9: Jam Txhua Yam Hauv Ib Qhov Case

Jam Txhua Yam Hauv Qhov Case
Jam Txhua Yam Hauv Qhov Case
Jam Txhua Yam Hauv Qhov Case
Jam Txhua Yam Hauv Qhov Case
Jam Txhua Yam Hauv Qhov Case
Jam Txhua Yam Hauv Qhov Case

Tam sim no tias txhua yam tau raug sim thiab ua haujlwm, lub sijhawm los muab txhua yam rau hauv rooj plaub.

Kuv tau tsim qhov sawv ntsug rau Raspberry Pi Zero siv qee cov yas uas kuv tau nyob ib puag ncig lub tsev. Tom qab ntawd kuv tau laum qee qhov rau lub vaj huam sib luag mount micro USB, thiab siv qee cov ntaub ntawv cov hniav nyiaj hniav kub faib tawm ntawm lub qhov. Lub vaj huam sib luag mount cable yog tawv me ntsis, yog li kuv tuaj yeem yuav lub kaum sab xis haum rau lub micro USB chaw nres nkoj ntawm Pi qee zaum yav tom ntej.

Kuv txiav qhov qhib me me nyob rau sab saum toj ntawm rooj plaub rau tus hais lus ua si los ntawm kev drilling ob lub qhov thiab txuas lawv nrog Dremel. Tom qab ntawd laum lub qhov hauv lub hau kom nce tus hais lus Phat. Txog qhov nws tsim nyog, tom qab thaij daim duab no kuv rov qab los thiab ua ob peb qhov ntxiv vim tias lub suab nrov tau raug rau sab hauv tiag. Kuv tau teeb tsa Blinkt siv cov ntawv tso rau ntawd cov khoom vim tias qhov khoom tsis muaj qhov ntsia qhov, tab sis cov putty zoo li tuav tau zoo, yog li nws yuav ua.

Kauj ruam 10: Nws yog

Yog Nws!
Yog Nws!

Plug nws thiab koj ua tiav. Nov yog kuv li khiav tom qab 8 teev tsaus ntuj. Lub ntsuab LED ntawm tus pi nws tus kheej tsis zoo li lub yees duab no ua rau pom.

Qee qhov kev hloov kho tom qab kuv tau ua:

Kuv ntxiv 4 nplooj ntawv ntxiv rau webapp.py thiab cov ntawv index.html. Cov 4 yog "liab", "daj", "ntsuab", thiab "tawm". Zoo nkauj tus kheej piav qhia. Kuv xav tau lub peev xwm los hloov nws los ntawm ntsuab rov qab los rau daj yog tias tus poj niam thiab kuv tau hnov nkees ntxiv thiab tsis xav tau kev thab plaub.

@app.route ('/liab', cov hau kev = ['POST']) def liab (): os.system ("python ~/scripts/red.py") rov xa rov qab ('/')

Yeej yog 4 zaug, khiav 4 cov ntawv sib txawv, tom qab ntawd qee lub khawm ntxiv hauv qhov ntsuas uas hu cov nplooj ntawv ntawd.

Lwm qhov kev hloov pauv kuv twb tau sau tseg, tab sis kuv tau nqus qee qhov ntxiv thiab nthuav qhov qhib uas twb muaj lawm nyob ib puag ncig tus hais lus vim tias lub suab nrov tsis tau khiav ntawm lub qhov rooj zoo txaus.

Yog tias kuv hloov kho ntxiv, kuv yuav nco ntsoov rov los ntawm no thiab sau lawv.

Kauj ruam 11: Daim ntawv ntxiv

Tom qab tsim qhov no kuv pom tias kuv tus poj niam thiab kuv ob leeg nquag tso peb lub xov tooj hauv qab thaum tso tus menyuam pw lossis pw. Yog li kuv tau ntxiv ib lub sijhawm thawb khawm rau lub cev pin 36, thiab suav nrog cov cai hauv qab no (Kuv hu nws button.py) kom khiav thaum pib hauv rc.local:

#!/usr/bin/env nab hab sej

ntshuam RPi. GPIO li GPIO ntshuam lub sijhawm ntshuam os ntshuam subprocess ntshuam re GPIO.setmode (GPIO. BOARD) # Siv Lub Cev Tus lej Tus lej Tus lej khawm = 36 # Khawm txuas nrog lub cev tus lej 16 GPIO.setup (khawm, GPIO. IN, rub_up_down = GPIO. PUD_UP) # Ua lub pob kom nkag mus, Ua kom rub tawm Resistor thaum muaj tseeb: yog GPIO.input (khawm) == 0: # Tos rau khawm nias rov qab ua haujlwm = Tsis raug # Pib teeb tsa lub suab tawm s = subprocess. Popen (["ps", "ax"], stdout = subprocess. PIPE) rau x hauv s.stdout: yog re.search ("mpg123", x): returnprocess = Muaj tseeb yog returnprocess == Tsis tseeb: os.system ("mpg123 --loop -1 /home/pi/scripts/sounds/whitenoise.mp3 & ") os.system (" python /home/pi/scripts/red.py ") else: os.system (" killall mpg123 ") os.system ("nab hab sej /home/pi/scripts/lightsout.py")

Raws li koj tuaj yeem pom, kuv kuj hloov mus rau mpg123 los ntawm omxplayer vim tias nws hnyav dua thiab siv tau yooj yim dua.

YUAV UA LI CAS, rau qee qhov laj thawj thaum kuv tso cov ntawv no hauv rc.local nws yeej ua tiav thaum pib yam tsis muaj teeb meem. Tab sis lub suab yog tiag tiag choppy. Thaum kuv khiav tsab ntawv li ib txwm, hauv putty, tsis muaj teeb meem zoo li no. Kuv tab tom muaj lub sijhawm los daws qhov teeb meem no, yog li leej twg muaj tswv yim, thov qhia rau kuv paub! Ua tsaug.

Pom zoo: