Cov txheej txheem:

Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi: 5 Kauj Ruam
Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi: 5 Kauj Ruam

Video: Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi: 5 Kauj Ruam

Video: Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi: 5 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi
Lub Teeb Ua Ntej Tswj los ntawm Raspberry Pi

Qhov "Ua Pa Ua Pa Lub Teeb" piav qhia ntawm no yog qhov yooj yim thiab tus nqi pheej yig pulsing lub teeb uas tuaj yeem txhawb koj hauv koj txoj kev ua pa thiab pab koj kom ua pa tsis tu ncua. Nws kuj tseem yuav siv tau piv txwv. raws li lub teeb hmo ntuj so rau cov menyuam yaus. Hauv theem tam sim no nws yog qhov ua haujlwm ntau dua.

Koj kuj tseem tuaj yeem siv nws ua qhov pheej yig thiab yooj yim los tsim piv txwv rau "kev suav lub cev" nrog Raspberry Pi, piv txwv li kom siv los ua txoj haujlwm kev kawm ntawm cov pib qib, Ntawm no koj muaj qhov sib piv (potentiometer teb) thiab cov tswv yim digital (thawb khawm) nrog rau digital (LED) thiab PWM tso tawm (LED saw), thiab cov txiaj ntsig ntawm kev hloov pauv tau pom ncaj qha.

Lub teeb khiav los ntawm cov voj voog rov ua dua uas suav nrog plaub theem: ntsuab (sab saud) mus rau liab (qis dua) kev hloov pauv, theem liab-tsuas yog, hloov liab-rau-ntsuab thiab theem ntsuab-tsuas yog. Qhov ntev ntawm cov theem no tau piav qhia los ntawm qhov hloov pauv uas tuaj yeem hloov kho los ntawm potentiometers. Cov txheej txheem tuaj yeem pib, ncua, rov pib dua thiab nres los ntawm kev nias lub pob. LEDs yog qhia txog theem tam sim no. Nws yog raws li "Firefly Light" piv txwv los ntawm Pimoroni (saib ntawm no). Zoo ib yam li "Firefly Light" nws xav tau Raspberry Pi (Xoom), Pimoroni Explorer pHAT (lossis HAT) thiab ob IKEA SÄRDAL LED teeb saw. Tom qab txuas nrog ob lub PMW/lub cev muaj zog chaw nres nkoj ntawm pHAT. Hloov chaw ntawm kev siv lub thawv, Kuv tau tso cov LEDs hauv IKEA daim duab thav duab. Kuv tau sim ua kom zoo dua qub "cov kab npauj npaim lub teeb" cov nab hab sej tsab ntawv me ntsis, siv qhov ua haujlwm tsis ua haujlwm sinus rau qhov ci ci/ mem tes dav hloov pauv thiab tau qhia ob "tuav" theem nruab nrab ntawm cov dimming. Thaum hloov kho qhov ntsuas kom pom lub teeb pom kev uas zoo li xis nyob, Kuv pom tias lub cuab yeej tuaj yeem pab txhawb nqa qhov kev piav qhia meej heev, ua pa tsis tu ncua. Yog li, qee tus ntawm koj yuav pom qhov "Ua pa Lub Teeb" muaj txiaj ntsig zoo rau kev xav lossis kev qhia lub hom phiaj. Raws li Explorer pHAT muaj plaub qhov digital thiab plaub qhov sib piv nkag, nws yooj yim heev los tswj txog plaub qhov sib txawv uas siv swb lossis lub zog ntsuas hluav taws xob teb, thiab los qhia pib/rov pib dua/nres cov haujlwm rau lub teeb uas siv cov nyees khawm. Qhov no yuav tso cai rau koj siv lub cuab yeej thiab ua kom zoo dua qhov ntsuas rau koj cov kev xav tau yam tsis muaj lub ntsuas saib yuav tsum txuas nrog Pi.

Ntxiv rau qhov Explorer pHAT los nrog plaub lub chaw tawm digital, uas tso cai ntxiv LEDs lossis buzzers, ntxiv rau ob 5V thiab ob qhov av hauv av thiab ob PWM tawm chaw nres nkoj rau lub cav lossis cov cuab yeej zoo sib xws. Thov ua kom ntseeg tau tias koj siv cov tshuaj tiv thaiv raug kom txo qhov hluav taws xob rau koj cov LEDs.

Pimoroni's Explorer pHAT nab hab sej tsev qiv ntawv ua rau nws yooj yim heev los tswj tag nrho cov I/O chaw nres nkoj.

Hauv cov lus qhia no ntawm cov cuab yeej nrog 0, 2 thiab 4 lub zog thiab cov nyees khawm tau piav qhia. Xaiv qhov uas haum rau koj xav tau.

Txhawm rau khiav lub cuab yeej tsis siv neeg, ib tus tuaj yeem siv lub hwj chim pob, lossis ua ke ntawm Pimoroni LiPo shim thiab LiPo roj teeb, raws li tau piav qhia rau "Firefly Light".

Hloov kho dua Lub Kaum Ob Hlis 28, 2018: 'plaub lub hwj chim thiab plaub lub laub khawm' version ntxiv. Dec. 30: code rau 4-poti version thiab fritzing cov duab ntxiv.

Kauj Ruam 1: Cov Khoom Siv / Yuav Tsum Tau

Cov Khoom Siv / Yuav Tsum Tau
Cov Khoom Siv / Yuav Tsum Tau
Cov Khoom Siv / Yuav Tsum Tau
Cov Khoom Siv / Yuav Tsum Tau
Cov Khoom Siv / Yuav Tsum Tau
Cov Khoom Siv / Yuav Tsum Tau

- Raspberry Pi Zero (4.80 GBP ntawm Pimoroni, UK), thiab daim npav micro SD (> = 8 GB) w/ Raspian

- Pimoroni Explorer pHAT (10 GBP ntawm Pimoroni, UK). Yeem tau: ib kab ib kab lus, jumper cables

- IKEA SÄRDAL LED saw teeb w/ 12 LEDs (2 x, 3.99 € txhua ntawm IKEA Lub Tebchaws Yelemees), lossis ib qho zoo sib xws 3-5V LED saw.- IKEA RIBBA duab thav duab (13 x 18 cm, 2.49 € ntawm IKEA Lub Tebchaws Yelemees).

- Ib daim ntawm PU ua npuas ncauj (2 x 18 x 13.5 cm), los tuav cov LEDs. Lwm txoj hauv kev tuaj yeem siv styro ua npuas ncauj.

- Ib daim yas uas tsis pom kev (18 x 13.5 cm), ua tus diffusor.

- Ob daim ntawv ntawm cov ntawv dawb (9 x 13.5 cm txhua). Kuv siv liab thiab ntsuab.

- Ib daim nyias nyias, cov ntawv yas tsis zoo (18 x 13.5 cm), ua raws li lub vijtsam sab nraud. Kuv siv daim ntawv dawb polycarbonate nyias. Yeem, rau qhov tunable version:

Txhawm rau kho lub sijhawm nce toj thiab lub sijhawm toj siab, lossis hloov lwm yam tsis xws li ci ntsa iab.- 10, 20 lossis 50 kOhm potentiometers (txog plaub, Kuv siv ob 10 kOhm feem plaub plaub 50 Ohm).

Raws li pib/nres/ncua/ncua khawm:- Nias khawm (txog plaub, Kuv siv plaub lossis ob)

Raws li qhov ntsuas rau theem ntawm lub voj voos:- Cov xim LEDs thiab cov tiv thaiv tsim nyog (yuav nyob ntawm tus yam ntxwv ntawm LEDs koj yuav siv).

  1. txog 140 Ohm rau 5.2 -> 2, 2 V (daj, txiv kab ntxwv, liab; qee qhov LED ntsuab),
  2. txog 100 Ohm rau 5.3 -> 3.3 V (qee qhov ntsuab; xiav, dawb LEDs)

- Jumper cables thiab daim ntawv qhia zaub mov

Yeem, rau lub roj teeb uas tau tsav version:

  • 5V Micro-USB fais fab pob, lossis
  • Pimoroni Zero LiPo shim thiab roj teeb LiPo

Kauj ruam 2: Lazout thiab Assembly

Lazout thiab Assembly
Lazout thiab Assembly
Lazout thiab Assembly
Lazout thiab Assembly
Lazout thiab Assembly
Lazout thiab Assembly

Sib sau ua ke Explorer pHAT raws li tau piav qhia los ntawm cov khw. Kuv tau ntxiv ib kab poj niam header rau qhov yooj yim txuas ntawm jumper cables rau pHATs I/O chaw nres nkoj. Teem koj tus Pi thiab nruab Pimoroni lub tsev qiv ntawv rau Explorer HAT/pHAT, raws li tau piav los ntawm Pimoroni. Tua tawm Pi thiab txuas pHAT mus rau Pi. Tshem tawm cov roj teeb pob los ntawm cov hlua LED los ntawm kev txiav cov xov hlau thiab tin kawg ntawm cov xov hlau. Txiav ob 2x txiv neej jumper cables ntawm nruab nrab, tin kawg ntawm cov xov hlau. Muab cov hlua txuas txuas txuas rau cov hlua LED, thiab cais cov ntsiab lus siv uas siv cov kab xev nplaum lossis cov tubing. Ua ntej yuav tshuaj xyuas, xyuas seb cov xov hlau twg yuav tsum txuas nrog rau ntxiv lossis hauv av chaw nres nkoj, thiab kos lawv raws li. Kuv siv cov xov hluav taws xob sib txuas nrog cov xim sib txawv. Cut ua npuas dej los tuav cov LEDs, cov diffusor thiab cov ntawv tshuaj ntsuam kom haum rau qhov loj me. Ntawm LED tuav phaj cim cov haujlwm uas LEDs yuav tsum tau muab thiab xuas 3-5 hli qhov rau hauv ua npuas ncauj. Tom qab ntawd ntxig 24 LEDs ntawm txoj haujlwm. Muab cov ntawv xim thiab cov phaj diffusor tso rau ntawm daim phaj LED (saib cov duab), lawv tso tus thav duab sab saud. Txhim kho cov txheej ua npuas dej hauv tus ncej, piv txwv. siv daim kab xev nplaum. Txuas cov kab hluav taws xob LED txuas mus rau "lub cev muaj zog" cov chaw nres nkoj ntawm Explorer pHAT. Rau qhov hloov pauv tau qhov chaw potentiometers, thawb cov nyees khawm, tswj LEDs (thiab/lossis buzzers) thiab tiv thaiv ntawm lub khob cij thiab txuas lawv nrog cov chaw nres nkoj sib xws ntawm Explorer pHAT.

Pib koj Pi thiab teeb tsa cov tsev qiv ntawv xav tau, raws li tau piav qhia hauv Pimoroni lub vev xaib, tom qab ntawv khiav cov ntawv Python 3 uas tau muab. Yog tias ib qho ntawm cov saw LED tsis ua haujlwm nws yuav txuas nrog qhov tsis raug. Tom qab ntawd koj tuaj yeem hloov pauv ntxiv/rho tawm kev sib txuas ntawm pHAT lossis hloov pauv hauv txoj haujlwm, piv txwv li hloov "eh.motor.one.backwards ()" rau "… forwards ()".

Txuas nrog koj pom cov ntawv nrog cov chaw teeb tsa koj tuaj yeem hloov pauv hauv qhov haujlwm thiab piv txwv uas koj tuaj yeem hloov kho qee qhov kev teeb tsa nrog lub zog ntsuas, thiab pib thiab nres lub voj voog lub teeb siv cov nyees khawm. Nws yuav tsum tsis txhob nyuaj rau kho cov ntawv kom haum rau koj tus kheej teeb tsa ntawm "lub teeb ua pa".

Kauj Ruam 3: Python Scripts

Pimoroni's Python library rau Explorer HAT/pHAT ua rau nws yooj yim heev rau adress cov khoom txuas nrog rau HATs 'I/O chaw nres nkoj. Ob qho piv txwv: "eh.two.motor.backwards (80)" tsav lub cuab yeej txuas rau PWM/lub cev muaj zog chaw nres nkoj 2 nrog 80% kev siv ntau tshaj nyob rau sab nraum qab, "eh.output.three.flash ()" ua rau LED txuas nrog mus rau qhov chaw nres nkoj tus lej peb nyem kom txog thaum nws tau nres. Kuv tau tsim ob peb qhov kev hloov pauv ntawm lub teeb, ib txwm ntxiv kev nce qib ntawm kev tswj hwm los ntawm kev ntxiv txog plaub lub laub khawm thiab lub zog ntsuas..py "qhov twg tag nrho plaub qhov kev teeb tsa yuav tsum tau hloov pauv hauv qhov haujlwm. Ib qho ntxiv hu ua "Ua pa lub teeb var lin cosin.py" qhov twg qhov ntev ntawm ob theem qis zuj zus tuaj yeem hloov kho siv ob lub zog thiab ntau qhov kev piav qhia tshaj "Ua pa lub teeb var lin cosin3.py" rau plaub lub zog potentiometer & laub khawm khawm. Cov kev zov me nyuam tau sau hauv Python 3.

Hauv txhua qhov xwm txheej txheej txheem kev caij tsheb kauj vab tuaj yeem tshwm sim thiab nres siv ob lub khawm thawb, hauv plaub lub khawm version koj kuj tuaj yeem cuam tshuam thiab rov pib ua cov txheej txheem. Ntxiv rau plaub (xim) LEDs tuaj yeem txuas nrog cov chaw tso tawm digital, qhia txog cov theem tshwj xeeb. Lub voj voog ntawm lub cuab yeej muaj plaub theem:

- theem "nqus", qhov twg LEDs sab saud qis dua thiab qis LEDs nce kev siv zog

- theem "tuav koj cov pa", qhov twg LEDs sab saud raug kaw thiab qis LEDs tau teeb tsa kom siab tshaj plaws

- "exhale" theem, qhov qis LEDs qis dua qhov qis thiab LEDs sab saud nce ntxiv

- theem "nyob twj ywm exhaled", qhov twg qis LEDs tau muab tua thiab LEDs sab saud pom ntawm qhov siab tshaj plaws.

Qhov ntev ntawm tag nrho plaub theem tau txhais los ntawm tus lej tus lej ntsuas, uas tej zaum yuav raug kho hauv qhov haujlwm thiab/lossis tuaj yeem hloov kho siv lub zog ntsuas.

Qhov ntsuas thib tsib qhia txog qhov siab tshaj plaws. Nws tso cai rau koj los teeb qhov siab tshaj plaws ntawm LEDs, uas tuaj yeem siv tau yog tias koj xav siv nws ua hmo ntuj. Ib qho ntxiv nws yuav tso cai rau koj txhim kho cov txheej txheem dimming, raws li kuv muaj lub tswv yim tias nws nyuaj rau pom qhov sib txawv ntawm 80 thiab 100% kev siv.

Kuv tau ntxiv qhov kev xaiv (co-) sinus ua haujlwm rau kev nce/txo qhov ci ci, vim nws muab kev sib txuas zoo dua ntawm cov theem. Ua siab dawb sim ua lwm yam haujlwm. Piv txwv li koj tuaj yeem tshem tawm qhov so thiab siv ob qhov sib txawv (ua haujlwm) sinus ua haujlwm rau ob txoj hlua LED thiab kho qhov zaus thiab qhov dav los ntawm cov zog.

# Lub teeb "ua pa": ob lub pob & ob lub zog ntsuas qhov ntsuas

# ib qho kev hloov pauv ntawm cov piv txwv ntawm cov kab npauj npaim rau Pimoroni Explorer pHAT # ntawm no: sinoid nce/txo qis lub cev muaj zog/PWM qhov tseem ceeb # rau kev ua haujlwm tsis siv neeg tawm suab tsis ua haujlwm thiab ntsiag to cosin ua haujlwm # No version "var" puas tau nyeem cov lus qhia sib xws, overrides kev teeb tsa ua ntej # nyeem cov tswv yim digital, cov nyees khawm kom pib thiab nres "" "pib thaum hloov pauv ntawm Pi koj tuaj yeem siv Cron: Cron yog Unix program uas tau siv los teem sijhawm ua haujlwm, thiab nws muaj qhov yooj yim @reboot muaj nuj nqi uas tso cai rau koj los sau tsab ntawv Thaum twg los xij koj lub Pi khau raj. /home/pi/firefly.py): @reboot sudo python /home/pi/filename.py & Kaw thiab txuag koj cov crontab (yog tias koj siv nano ces nias tswj -x, y thiab nkag mus tawm thiab txuag). "" "ntshuam sijhawm ntshuam tshawb xyuas raws li eh ntshuam lej lej qhov tseem ceeb #sinus xmax = 316 kauj ruam = 5 # qib dav, piv txwv li 315/5 muab 63 cov kauj ruam/lub voj voog pib_button = 0 # qhov no txhais lub xeev ntawm lub laub khawm txuas nrog rau qhov chaw nres nkoj nkag tsis muaj 1 nres_button = 0 # qhov no piav qhia lub xeev ntawm lub laub khawm txuas nrog rau qhov chaw nres nkoj nkag tsis tau 3 pause_1 = 0.02 # teeb tsa ntev ntawm kev so hauv cov kauj ruam hauv "nqus" theem, yog li nce tus nqi thiab lub sijhawm ncua pus_2 = 0.04 # teeb tsa "nqus" ramping tus nqi pause_3 = 1.5 # so ntawm nqus pa thiab nqus pa theem (khaws nqus) pause_4 = 1.2 # so ntawm qhov kawg ntawm qhov nqus theem (khaws exhaled) max_intens = 0.9 # qhov siab tshaj plaws/ci ci max_intens_100 = 100*max_intens # zoo ib yam hauv % # Yuav tso cai rau ua kom zoo dua "ua pa" kev xav ntawm LEDs thiab txo qhov muag. l_cosin = # daim ntawv teev npe nrog cosinus muab qhov tseem ceeb (100> = x> = 0) l_lin = # daim ntawv teev npe nrog cov txiaj ntsig tawm (100> = x> = 0) # tsim cov npe cosinus ua haujlwm rau kuv hauv ntau (0, 316, 3): # 315 ze rau Pi*100, 105 cov kauj ruam # luam tawm (i) n_cosin = [(((lej.cos (i/100))+1)/2)*100] # tsim tus nqi # luam tawm (n_cosin) l_cosin = l_cosin + n_cosin #add tus nqi rau daim ntawv # luam tawm (l_cosin) # tsim cov npe kab rau kuv hauv ntau (100, -1, -1): # suav sau los ntawm 100 rau xoom n_lin = l_lin = l_lin + n_lin # luam tawm (l_lin) # qhia cov npe tsis txaus sau () luam tawm ("" "Txhawm rau pib lub teeb pom kev, nyem lub pob" Pib "(Nkag Mus Ib)" "") luam tawm () luam tawm "" " lub teeb, nias thiab tuav lub "Nres" Khawm (Kev Nkag Mus Rau Peb) "" ") luam tawm () # tos kom txog thaum Start Button raug nias thaum (start_button == 0): start_button = eh.input.one.read () # nyeem khawm tus naj npawb ib eh.output.one.blink () # ntsais muag LED tus naj npawb ib zaug.sleep (0.5) # nyeem ob zaug ib pliag #run teeb thaum (stop_button == 0): # nyeem analog inputs ib thiab TWO, txhais cov teeb tsa set_1 = ehh alog.one.read () # txhais liab-> ntsuab nce tus nqi paug_1 = set_1*0.02 # qhov tseem ceeb yuav nyob nruab nrab ntawm 0 thiab 0.13 sec/qib luam tawm ("set_1:", set_1, " -> ncua _1:", pause_1) set_2 = eh.analog.two.read () # txiav txim siab ntsuab -> liab nce tus nqi pause_2 = set_2*0.02 # qhov tseem ceeb yuav nyob nruab nrab ntawm 0 thiab 0.13 sec/qib luam tawm ("set_2:", set_2, " -> ncua _2: ", pause_2) #" nqus pa "theem eh.output.one.on () # yuav tsav lub LED lossis beeper '' 'rau x hauv kab (len (l_lin)): fx = max_intens*l_lin [x] # txoj kab nkhaus eh.motor.one.backwards (fx) eh.motor.two.backwards (max_intens_100-fx) time.sleep (pause_1) eh.output.one.off () `` '' rau x hauv kab (len (l_cosin)): fx = max_intens*l_cosin [x] # kab nkhaus eh.motor.one.backwards (fx) eh.motor.two.backwards (max_intens_100-fx) time.sleep (pause_1) eh.output.one.off () # xyuas yog Nres Nias Nias yog nias stop_button = eh.input.three.read () # "Ua kom koj ua tsis taus pa" ncua ntawm qhov kawg ntawm qhov nqus pa theem eh.output.two.on () # qhib LED ob lub eh.motor.one.backwards (0) eh.motor.two.backwards (max_intens_100) time.sleep (pause_3) eh.output.two.off () # xyuas yog tias Nias Nias yog nias stop_button = eh.input.three.read () # "exhale" theem eh.output.three.on () # tig LED peb '' 'rau x hauv ntau (len (l_lin)): fx = max_intens*l_lin [x] # kab nkhaus eh.motor.one.backwards (max_intens_100-fx) eh.motor.two.backwards (fx) time.sleep (pause_2) '' 'rau x hauv kab (len (l_cosin)): fx = max_intens*l_cosin [x] # kab nkhaus eh.motor.one.backwards (max_intens_100-fx) eh.motor.two. thim rov qab (fx) time.sleep (pause_2) eh.output.three.off () #check yog Nias Nias Nias yog nias stop_button = eh.input.three.read () # ncua ntawm "nqus" thiab "nqus tau" theem eh. output.four.on () eh.motor.one.backwards (max_intens_100) eh.motor.two.backwards (0) time.sleep (pause_4) eh.output.four.off () #xyuas yog tias Nres Nias yog nias stop_button = eh.input.three.read () # kaw, tig ntawm txhua qhov chaw nres nkoj tso tawm eh.motor.one.stop () eh.motor.two.stop () eh.output.one.off () eh.output.two.off () eh.output.three.off () eh.output.four.off () luam tawm () luam tawm ("Bye bye")

Yog tias koj xav siv lub teeb ua khoom siv ib leeg, piv txwv li zoo li tsaug zog lossis sawv ntxov, koj tuaj yeem ntxiv lub zog siv hluav taws xob rau Pi thiab muaj qhov haujlwm pib tom qab pib thiab siv "Cron" los hloov lossis qhib lub sijhawm. Yuav siv "Cron" tau piav qhia ntxaws nyob rau lwm qhov.

Kauj Ruam 4: Piv Txwv Video

Hauv cov kauj ruam no koj yuav pom cov vis dis aus qhia pom lub teeb nyob hauv ib txwm muaj (piv txwv li txhua qhov muaj txiaj ntsig> 0, #1) thiab cov xwm txheej hnyav, raws li txhua qhov txiaj ntsig tau teeb tsa rau xoom (#2), ramping only (#3 ), thiab tsis muaj ramping (#5 ).;

Kauj Ruam 5: Qee Cov Lus Cim

Thov zam txim rau txhua nqe lus tsis raug, ua yuam kev thiab ua tsis raug. Kuv tsis yog tus neeg hais lus Askiv ib txwm, lossis kuv tsis tau piav qhia kev paub txog hluav taws xob, hluav taws xob lossis programing. Uas txhais tau tias kuv tabtom sim sau cov lus Askiv qhia txog yam uas kuv tsis tshua paub cov ntsiab lus raug hauv kuv tus kheej cov lus. Yog li cov lus qhia, kev kho lossis tswv yim rau kev txhim kho tau txais tos. H

Pom zoo: