Cov txheej txheem:

Me Nyuam Kev Kawm Caij Nyoog: 6 Kauj Ruam (nrog Duab)
Me Nyuam Kev Kawm Caij Nyoog: 6 Kauj Ruam (nrog Duab)

Video: Me Nyuam Kev Kawm Caij Nyoog: 6 Kauj Ruam (nrog Duab)

Video: Me Nyuam Kev Kawm Caij Nyoog: 6 Kauj Ruam (nrog Duab)
Video: Tseem Ev Lub Kawm - Koos Loos 2024, Hlis ntuj nqeg
Anonim
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog
Me Nyuam Kev Kawm Tsaug Zog

Kuv xav tau lub moos los pab kuv tus menyuam hnub nyoog 4 xyoos kawm kom tsaug zog me ntsis ntxiv (Kuv tau muaj txaus kom sawv thaum 5:30 sawv ntxov thaum hnub Saturday), tab sis lawv tseem nyeem sijhawm tsis tau. Tom qab tshawb nrhiav los ntawm ob peb yam khoom ntawm lub vev xaib uas muaj neeg nyiam heev, kuv xav tias, "Yuav nyuaj npaum li cas thiaj li yuav tsum tau ua ib qho?!"

Yog li ntawm no yog qhov kuv xav tias kuv xav tau hauv qhov haujlwm no. Nws yuav siv qee qhov RGB LED's (feem ntau vim tias kuv muaj txog tsib caug ntawm lawv los ntawm lwm qhov haujlwm) los tso saib peb xim sib txawv. Liab yuav txhais tau tias rov qab mus pw, nws ntxov dhau rau sawv ntxov. Daj yuav txhais tau tias lawv tuaj yeem sawv thiab ua si ntsiag to hauv lawv chav. Ntsuab, tau kawg txhais tau tias koj tuaj yeem sawv. Kuv kuj xav kom tuaj yeem kho lub sijhawm, vim tias kuv xav pw ntev dua ntawm qee hnub (Hnub so/Hnub so vs Hnub Ua Haujlwm thiab lwm yam).

Khoom siv

Raspberry Pi Zero W.

Ob RGB LEDs

Rau 220 Ohm resistor's

Cov ntaub ntawv (.stl, nab hab sej, html) pom ntawm no

Ntau yam ntsia hlau me me, xov hlau, thiab ntu me me raws li xav tau.

Kauj Ruam 1: Luam Ntawv 3D

3D Luam Ntawv
3D Luam Ntawv
3D Luam Ntawv
3D Luam Ntawv
3D Luam Ntawv
3D Luam Ntawv

Kuv tus ntxhais zoo li unicorns tiag tiag, yog li rau qhov haujlwm no kuv tau kho dua Riven02's Unicorn Nightlight, uas yog nkauj tshiab ntawm Apachcreation's Unicorn Trophy, uas tuaj yeem pom ntawm Thingiverse.com thiab siv raws li Creative Commons Non-Commercial licence. Kuv hloov kho unicorn puag kom haum rau lub hwj chim qaum rau raspberry pi xoom. Kuv tau tshwm sim kom muaj qee qhov AMZ3D Liab PLA tso ncig, yog li lub hauv paus thiab lub taub hau yuav liab. Kuv siv PLA meej/txhais tau zoo rau lub suab raj. Cov ntaub ntawv.stl thiab cov chaw kuv siv yog:

Unicorn.stl

  • Txheej siab: 0.02
  • Phab ntsa Thickness:.8
  • Phab Ntsa Kab Suav: 2
  • Tus nqi: 15%
  • Txawv Txawv Txawv: Daim phiaj

UnicornBase.stl

  • Txheej siab: 0.02
  • Phab ntsa Thickness:.8
  • Phab Ntsa Kab Suav: 2
  • Tus nqi: 15%
  • Txawv Txawv Txawv: Daim phiaj

Horn.stl

  • Txheej siab: 0.02
  • Phab ntsa Thickness: 0.8
  • Phab Ntsa Kab Suav: 3
  • Cov ntaub ntawv: 0

Kauj ruam 2: Circuit Court

Qhov Circuit
Qhov Circuit
Qhov Circuit
Qhov Circuit
Qhov Circuit
Qhov Circuit

Lub voj voog yog yooj yim zoo nkauj. Kuv xaiv rau 6 tus GPIO sib txawv los tswj qhov qhib/tawm rau cov xim sib txawv ntawm RGB. Cov pins thiab cov xim sib xws LED yog:

  • Pin 11 rau RGB 1 RED
  • Pin 13 rau RGB 1 GREEN
  • Pin 15 rau RGB 1 XOV XWM
  • Pin 16 rau RGB 2 RED
  • Pin 18 rau RGB 2 GREEN
  • Pin 36 rau RGB 2 XIAV
  • Pin 39 rau hauv av

Txhua tus pin tau txuas rau tus tiv thaiv los ntawm 220 ohm tam sim no txwv kev tiv thaiv (nrog rau qhov tshwj xeeb hauv av ntawm chav kawm.) Kuv tau siv tus tiv thaiv kab hauv kab thiab npog nws nrog cua sov ntsws tubing.

Kauj Ruam 3: Npaj Raspberry Pi

Kuv xav kom tuaj yeem teev sijhawm rau tus kws qhia pw tsaug zog siv lub web interface. Yog li kuv xav tau teeb tsa Apache thiab PHP Server ntawm Raspberry Pi. Thawj qhov uas koj yuav tsum ib txwm ua thaum txhim kho software tshiab ntawm Raspberry Pi yog kom paub tseeb tias nws tau hloov kho tshiab los ntawm kev ntaus:

sudo apt-tau hloov tshiab

Tom qab ntawd, peb tuaj yeem nqis mus ua lag luam. Peb yuav ua qhov ntawd los ntawm kev txhim kho Apache2:

sudo apt -tau nruab apache2 -y

qhov no yuav tsum teeb tsa Apache web server. Koj tuaj yeem sim qhov no los ntawm kev siv browser ntawm Raspberry pi thiab mus rau:

zos/

lossis los ntawm kev tshawb nrhiav los ntawm lwm lub khoos phis tawj browser mus rau koj li Raspberry Pi tus IP chaw nyob. Txhawm rau nrhiav koj tus IP chaw nyob hom:

hostname -Ib

Ua cov no yuav ua rau lub neej ntawd Apache Web Server nplooj ntawv. Qhov no tuaj yeem hloov pauv los ntawm kev hloov pauv index.html nyob hauv/var/www/html/directory. Nws tuaj yeem hloov nws nrog kuv tus kheej cov ntawv index.html.

Tom ntej no peb yuav teeb tsa Apache lub web server kom tuaj yeem khiav cov ntaub ntawv PHP. Pib los ntawm kev ntaus ntawv:

sudo apt-tau nruab php libapache2-mod-php -y

koj yuav tsum tam sim no tuaj yeem tso cov ntaub ntawv sleepset.php hauv/var/www/html nrog cov ntawv index.html.

Txhawm rau kom nkag mus rau nplooj ntawv no hauv koj tus kheej lub network, koj yuav tsum teeb tsa koj li Raspberry Pi nrog tus IP chaw nyob zoo li qub (lossis koj tuaj yeem tsuas yog sim txiav txim siab tus IP tshiab thaum koj lub network txuas ntxiv nws tam sim no thiab tom qab ntawd). Koj yuav tsum tau kho ob peb cov ntaub ntawv kom qhov no ua haujlwm. Koj yuav tsum tau kho cov ntaub ntawv /etc/dhcpcd.conf nrog cov hauv qab no:

wb wl0

zoo li qub ip_address = 192.168.1.static routers = 192.168.1.1 zoo li qub domain_name_servers = 192.168.1.1

Hloov nrog koj cov ntaub ntawv network. Tib yam uas koj yuav tsum tau ua tam sim no yog rov pib dua.

sudo rov pib dua

Kev tso cov ntaub ntawv los ntawm Google txuas txuas yuav tsum yog raws li hauv qab no:

  • index.html thiab sleepset.php yuav tsum tau muab tso rau hauv/var/www/html directory
  • sleepset.txt thiab sleeptrainer1_1.py yuav tsum tau muab tso rau hauv/home/pi/pythoncode directory (hint: koj yuav tau tsim cov npe no)

Tom qab tso cov ntaub ntawv no rau hauv phau ntawv qhia raug, rc.local cov ntaub ntawv xav tau hloov kho kom ua haujlwm sleeptrainer1_1.py program thaum pib. Koj yuav xav tau cov hauv paus-qib nkag mus hloov rc.local cov ntaub ntawv, yog li ntaus:

sudo nano /etc/rc.local

Hauv tus khoos phis tawj, nqes mus, thiab tsuas yog ua ntej txoj kab 0 tawm, ntxiv:

nab hab sej /home/pi/pythoncode/sleeptrainer1_1.py &

Muaj ob yam yuav tsum nco ntsoov ntawm no:

  1. Siv cov ntaub ntawv tsis tseeb kom LINUX tsis xav tias cov ntaub ntawv sleeptraner1_1.py nyob hauv tib phau ntawv teev npe li rc.local.
  2. Tsis txhob hnov qab tus ampersand (&) thaum kawg. qhov no yuav tso cai rau LINUX los khiav cov ntaub ntawv no hauv keeb kwm yav dhau thiab txuas ntxiv mus.

Tam sim no, khaws cov ntawv los ntawm kev ntaus ctrl-x thiab tom qab ntawd y thaum hais kom txuag thiab tom qab ntawd nkag mus.

Tom qab ntawv ntaus sudo reboot.

Nws yuav tsum tau hais txog qee qhov ntawm no uas (tsawg kawg) koj yuav tsum hloov koj li Raspberry Pi lo lus zais siv tus passwd hais kom ua. Yog tias koj tseem tsis tau ua qhov no, tam sim no yuav yog lub sijhawm zoo.

Kauj ruam 4: Txoj Cai

Cov hauv qab no yog cov cai los ntawm cov ntaub ntawv sleeptrainer1_1.py. Kuv siv lub sijhawm kwv yees los sib piv lub sijhawm rau cov nyeem hauv cov ntaub ntawv sleepset.txt. Cov ntawv sau tsuas yog ob kab, thawj rau teev, thib ob rau feeb. sleeptrainer1_1.py pw rau ib feeb ntawm lub voj iterations kom tsis khi cov txheej txheem. Lub teeb ntsuab tau pib tawm los zoo li ci ntsa iab, yog li kuv siv qhov ntsuas qhov dav ntawm tes taws los piav kom dim thaum siv nrog liab los ua daj.

Nab hab sej code:

ntshuam RPi. GPIO ua GPIO

los ntawm hnub tim ntshuam datetime raws li dt lub sijhawm ntshuam GPIO.setmode (GPIO. BOARD) GPIO.setwarnings (Cuav) red1 = 11 red2 = 16 green1 = 13 green2 = 18 blue1 = 15 blue2 = 36 GPIO.setup (red1, GPIO. OUT) GPIO.setup (red2, GPIO. OUT) GPIO.setup (ntsuab 1, GPIO. OUT) GPIO.setup (ntsuab2, GPIO. OUT) GPIO.setup (blue1, GPIO. OUT) GPIO.setup (blue2, GPIO. OUT) p1 = GPIO. PWM (ntsuab1, 100) p2 = GPIO. PWM (ntsuab2, 100) def readset (): setfile = qhib ("/home/pi/pythoncode/sleepset.txt", 'r') a = setfile. readline () b = setfile.readline () a = int (a) b = int (b) rov qab a, b def coj teeb (xim): yog tias (xim == "liab"): GPIO.output (red1, GPIO. HIGH) GPIO.output (red2, GPIO. HIGH) p1.stop () p2.stop () GPIO.output (blue1, GPIO. LOW) GPIO.output (blue2, GPIO. LOW) elif (xim == "xiav"): GPIO.output (red1, GPIO. LOW) GPIO.output (red2, GPIO. LOW) p1.stop () p2.stop () GPIO.output (blue1, GPIO. HIGH) GPIO.output (blue2, GPIO. HIGH) elif (xim == "ntsuab"): GPIO.output (red1, GPIO. LOW) GPIO.output (red2, GPIO. LOW) p1.start (100) p2.start (100) GPIO.output (blue1, GPIO. LOW) GPIO.output (blue2, GPIO. LOW) elif (xim == "daj"): p1.start (60) p2.start (60) GPIO.output (red1, GPIO. HIGH) GPIO.output (red2, GPIO. HIGH) GPIO.output (blue1, GPIO. LOW) GPIO.output (blue2, GPIO. LOW) elif (color == "off"): GPIO.output (red1, GPIO. LOW) GPIO.output (red2, GPIO. LOW) GPIO.output (blue1, GPIO. LOW) GPIO.output (blue2, GPIO. LOW) p1.stop () p2.stop () thaum Muaj tseeb: settime = readset () teev, feeb = teev sijhawm yog feeb == 0: yog dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, teev -2) <dt.now () <dt (dt.now ().year, dt.now (). hli, dt.now (). hnub, teev-1, feeb+30): coj teeb ("liab") elif dt (dt.now (). xyoo, dt.now ().month, dt.now (). hnub, teev -1, feeb+30) <dt.now () <dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, teev, feeb): coj teeb ("daj") elif dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, teev, feeb) <dt.now () <dt (dt.now (). year, dt.now (). month, dt.now (). day, hour+1, minute): ledlight ("green") else: ledlight ("off") elif dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, ho ur-2) <dt.now () <dt (dt.now (). year, dt.now (). hli, dt.now (). hnub, teev, feeb -30): coj teeb ("liab") elif dt (dt.now (). year, dt.now (). hli, dt.now (). hnub, teev, feeb -30) <dt.now () <dt (dt.now (). dt.now (). hli, dt.now (). hnub, teev, feeb): ledlight ("daj") elif dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, teev, feeb) <dt.now () <dt (dt.now (). xyoo, dt.now (). hli, dt.now (). hnub, teev+1, feeb): coj teeb ("ntsuab") ntxiv: coj teeb ("tawm") sijhawm. tsaug zog (60)

Cov ntaub ntawv index.html yog daim ntawv yooj yim tsim hauv HTML. Nws siv cov ntsiab lus ntawm ob lub thawv ntawv thiab xa lawv mus rau cov ntaub ntawv sleepset.php rau kev tuav daim ntawv. Cov ntaub ntawv PHP yooj yim dua sau cov ntaub ntawv sleepset.txt nrog cov ntaub ntawv hloov tshiab.

Kauj Ruam 5: Muab Nws Txhua Qhov Ua Ke

Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke

Nrog cov lej ua tiav thiab txhua qhov ntu luam tawm, nws yog lub sijhawm los sib dhos. Kuv ua raws cov kauj ruam no rau muab txhua yam ua ke:

  1. Laum ob lub qhov me me mus rau RGB LED's hauv qab ntawm lub tshuab raj thiab tso cov LEDS hauv cov qhov no.
  2. Muab lub raj tso rau hauv lub qhov hauv lub taub hau unicorn thiab rub nws hla kom txog thaum nws nruj. Siv kua nplaum los sab hauv kom ruaj ntseg.
  3. Txuas Raspberry Pi Zero W rau sab hauv ntawm lub taub hau unicorn. (Siv Hot Glue Gun Tej zaum)
  4. Txuas lub taub hau unicorn rau lub hauv paus unicorn.
  5. Txuas lub hwj huam qaum, thiab txuas tag nrho lub rooj sib txoos rau ntawm phab ntsa.
  6. Plug hauv lub moos.

Txij ntawm No Mus Kuv muaj Tus Menyuam Tus Menyuam Tus Kws Qhia Kev Ua Haujlwm.

Kauj Ruam 6: Ib Xyoo Tom Qab …

Ib xyoos tom qab…
Ib xyoos tom qab…

Ib xyoos tom qab:

Kuv cov ntxhais tsaug zog me ntsis lawm. Peb tau siv los tsa cov menyuam yaus hauv peb chav hais tias, "Txiv, lub teeb ntsuab." thiab qhov ntawd zoo kawg. Zaj dab neeg luv luv, peb tsuas yog sawv thaum 5:30 sawv ntxov hnub Saturday thaum peb npaj nws ntxiv lawm.

Yam uas kuv npaj yuav txhim kho yav tom ntej:

  • Tej zaum ntxiv qee qhov ntsuas lossis lwm yam khoom zoo li lub mic thiab hais lus.
  • Tej zaum hloov cov cai los ua haujlwm nrog tus hais lus siv ua lub tswb nrov vim kuv cov menyuam yuav pib kawm ntawv sai sai no.

Pom zoo: