Cov txheej txheem:

Pheej Yig thiab Ua Tau Lub Tsev Zoo Nrog Raspberry Pi: 11 Cov Kauj Ruam (nrog Duab)
Pheej Yig thiab Ua Tau Lub Tsev Zoo Nrog Raspberry Pi: 11 Cov Kauj Ruam (nrog Duab)

Video: Pheej Yig thiab Ua Tau Lub Tsev Zoo Nrog Raspberry Pi: 11 Cov Kauj Ruam (nrog Duab)

Video: Pheej Yig thiab Ua Tau Lub Tsev Zoo Nrog Raspberry Pi: 11 Cov Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi
Pheej Yig thiab Ua Tau Tsev Zoo Nrog Raspberry Pi

Kuv ib txwm xav kom tuaj yeem tswj lub teeb wireless, tab sis kev xaiv kev lag luam feem ntau kim. Philips Hue teeb nyob ib puag ncig $ 70, thiab WiFi txuas nrog lub teeb tseem kim heev. Phau ntawv qhia no yuav qhia koj yuav ua li cas tswj tau txog tsib lub teeb/teeb/Christmas teeb pom kev zoo rau ib puag ncig $ 50, thiab tuaj yeem nthuav dav kom suav nrog ntau lub teeb ib yam.

Kauj Ruam 1: Yam Koj Yuav Tsum Tau

Koj Yuav Tsum Tau Dab Tsi
Koj Yuav Tsum Tau Dab Tsi

Cov ntaub ntawv:

Raspberry Pi Zero W (Wireless tsab)

Micro SD daim npav (Yam tsawg kawg 4gb)

Mini HDMI rau HDMI cable/hloov pauv (Muaj qhov sib txawv ntawm mini thiab micro, nco ntsoov kom tau txais txoj cai!)

Micro USB rau USB cable/hloov pauv

USB Keyboard

Nco tseg: Kuv tau txais Raspberry Pi Zero W cov khoom siv pib los ntawm Amazon uas tuaj nrog Raspberry Pi Zero W, daim npav SD, rooj plaub, lub xov tooj hluav taws xob, HDMI hloov pauv, thiab USB hloov pauv. Tsuas yog $ 30, nws yog qhov kev xaiv zoo nkauj (txuas)

Koj tuaj yeem siv tus qauv sib txawv ntawm Raspberry Pi, tab sis Raspberry Pi yuav tsum muaj qee hom kev sib txuas hauv is taws nem, thiab Pi Zero W yog qhov kev xaiv pheej yig tshaj.

Cov Chaw Taws Teeb - Kuv tau siv cov no

RF Transmitter thiab tus txais (Faj seeb: zaus ntawm lub transmitter/receiver yuav tsum phim qhov zaus ntawm cov chaw taws teeb) - Kuv tau siv cov no

Hlau rau kav hlau txais xov (Kuv siv 22 ntsuas cov khoom tseem ceeb tooj liab hlau, lwm cov hlau tuaj yeem ua haujlwm)

Breadboard, Jumper xov hlau, 40 tus pin txiv neej-rau-txiv neej header

Software:

Raspberry Pi OS (Rub Raspbian Desktop)

Etcher disk imager (Rau kev sau Pi OS rau SD Card)

Cov Cuab Yeej:

Soldering Hlau

Khoos phis tawj rau rub tawm Pi OS thiab Etcher

Kauj Ruam 2: Teeb Lub Qhov Hluav Taws Xob

Teem Cov Outlets
Teem Cov Outlets
Teeb Lub Qhov Hluav Taws Xob
Teeb Lub Qhov Hluav Taws Xob

Pib los ntawm ntsaws koj lub qhov hluav taws xob rau hauv lub qhov (socket). Ua raws cov lus qhia suav nrog txhawm rau teeb tsa lawv, thiab ntsaws koj lub teeb/khoom siv. Xyuas kom tseeb tias koj cov chaw taws teeb tau ua khub kom raug thiab tswj hwm lub qhov (socket).

Kauj Ruam 3: Teeb Tus PubNub Account

PubNub yog tus pub dawb hauv internet uas tso cai rau koj sib tham ntawm cov khoom siv, nyob txhua qhov chaw hauv ntiaj teb. Tsab ntawv nab nab tau txais cov lus los ntawm lub vev xaib, thiab siv cov ntaub ntawv hauv kab lus los teeb lossis qhib lub teeb. Koj tuaj yeem tso npe rau koj tus as khauj dawb ntawm no. Thaum koj tau kos npe, nkag mus rau koj tus account. Qhov no yuav coj koj mus rau nplooj ntawv tswj hwm app. Nyem rau ntawm "Tsim app tshiab". Muab koj lub npe app, tom qab ntawv xaiv nws los ntawm cov npe app (Yog tias qhov no yog koj thawj app, nws yuav yog tib qho nkaus xwb) Qhov no yuav coj koj mus rau nplooj ntawv app. Nyem rau ntawm "Demo Keyset", thiab koj yuav tsum pom peb tus yuam sij sib txawv. Khaws nplooj ntawv no, koj yuav xav tau cov yuam sij no tom qab. Tam sim no koj muaj koj tus lej PubNub, koj tuaj yeem teeb tsa koj li raspberry pi.

Kauj Ruam 4: Npaj Raspberry Pi

Rub tawm Etcher thiab Raspberry Pi OS rau hauv koj lub computer (txuas hauv ntu ntu)

Nruab Etcher rau hauv koj lub computer, thiab unzip (yog tias tsim nyog) Raspberry Pi OS. Ntxig koj daim npav Micro SD rau hauv koj lub computer, thiab qhib Etcher. Nyem "Xaiv Duab" thiab taw mus rau unzipped Raspberry Pi OS cov ntaub ntawv. Xaiv nws, tom qab ntawd nyem "Xaiv Tsav" thiab xaiv koj daim npav micro SD los ntawm cov npe. Nyem "Flash", thiab tos kom Etcher ua tiav. Thaum Etcher tau ua tiav, tshem koj daim npav SD ntawm koj lub khoos phis tawm (Etcher txiav tawm nws) thiab ntxig nws rau hauv koj li Raspberry Pi. Txij ntawm no mus, koj yuav tsum txuas koj li Raspberry Pi mus rau tus saib nrog lub HDMI hloov pauv. Txuas lub keyboard (thiab nas yog tias koj muaj ntau lub USB hub) thiab ntsaws rau hauv lub hwj chim cable. Muaj ob lub micro USB chaw nres nkoj. Ib qho yog rau lub zog, lwm qhov yog qhov chaw nres nkoj USB tiag tiag. Ib qho ze rau qhov kawg ntawm Pi yog lub zog, thaum ib qho ze rau nruab nrab yog USB. Koj tus raspberry pi yuav tam sim no pib khau raj. Nws yuav rov pib dua ob peb zaug thaum thawj zaug khau raj, tab sis qhov ntawd yog qhov ib txwm muaj. Thaum koj pib raspberry pi, txuas nws rau koj li WiFi. Tom qab txuas nws mus rau WiFi, koj tuaj yeem siv SSH server, tab sis kuv pom nws yooj yim dua siv GUI rau tam sim no. Qhib lub davhlau ya nyob twg qhov rai thiab sau cov lus txib no:

sudo pip3 nruab 'pubnub == 3.9.0'

cd git clone git: //git.drogon.net/wiringPi git clone

sudo git clone

sudo chown root.root/var/www/rfoutlet/codesend sudo chmod 4755/var/www/rfoutlet/codesend

cd kab w

./tsim

Tam sim no, qhib Raspberry Pi cov ntaub ntawv browser, thiab koj yuav tsum pom daim nplaub tshev pi-home-automation. Nyem ob npaug rau nws, thiab koj yuav tsum pom cov ntawv hu ua RFControl.py. Luam nws (piv txwv li nyem thiab xaiv "Luam"), tom qab ntawd rov qab mus rau pi nplaub tshev thiab muab nws tso rau ntawd.

Kaw koj lub raspberry pi (Ib qho los ntawm cov ntawv qhia zaub mov lossis los ntawm kev khiav sudo poweroff los ntawm kab hais kom ua), thiab tshem nws ib zaug thaum lub teeb ntsuab nres ntsais muag.

Kauj Ruam 5: Tsim Circuit Court

Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court
Tsim Circuit Court

Tam sim no nws yog lub sijhawm los tsim lub Circuit Court. Kuv siv daim ntawv qhia zaub mov, tab sis koj tuaj yeem ua nws raws li qhov koj nyiam.

Ua ntej tshaj, peb yuav tsum tsim lub kav hlau txais xov rau lub tshuab xa xov RF. Cov ntawv qhia qhia no qhia yuav ua li cas thiaj ua tus kav hlau txais xov rau tus xa xov hluav taws xob RF. Ua raws li cov lus qhia, tom qab ntawd muab nws txuas rau lub transmitter tus pin tus kav hlau txais xov (Ntawm qhov kuv tau siv nws tau sau tias ANT) nrog rau sab luv uas ze tshaj plaws rau lub transmitter

Hlau tus transmitter

Tus transmitter siv cov pins no:

Cov ntaub ntawv: GPIO 17, Tus pin lub cev 11

VCC: Raspberry Pi 5v, Lub cev pin 2

GND: Raspberry Pi GND, tus pin lub cev 6

Hlau tus txais

Tus txais siv cov pins no:

GND: Raspberry Pi GND, Tus pin lub cev 9

VCC: Raspberry Pi 5v, Lub cev pin 4

DATA: GPIO 27, Tus pin lub cev 13 (Muaj ob tus lej xov tooj ntawm tus txais kuv siv, thiab kuv siv qhov ze tshaj rau VCC)

Kauj Ruam 6: Tau Koj Tus lej RF

Tau koj cov lej RF
Tau koj cov lej RF

Tom qab koj lub xov tooj txuas nrog koj li Raspberry Pi, kos nws ob zaug kom paub tseeb tias txhua yam nyob hauv qhov chaw thiab tom qab ntawd rov ua haujlwm dua. Thaum nws tau qhib, qhib lub davhlau ya nyob twg thiab hom

sudo/var/www/rfoutlet/RFSniffer

Tom ntej no, qhib RFControl program. Muab lub qhov rai davhlau ya nyob twg thiab lub qhov rai qhib ib sab tuaj yeem pab tau hauv cov kauj ruam tom ntej.

Koj yuav xav tau cov chaw taws teeb uas tau suav nrog hauv cov khoom siv hluav taws xob tam sim no. Tuav nws ze rau tus txais, thiab nias txhua tus khawm. Thaum koj nias lub pob, koj yuav pom ob tus lej luam rau lub vijtsam. Ib ntawm lawv yuav yog tus lej lossis rau tus lej lej, thiab lwm qhov yog tus lej 3 tus lej. Koj yuav tsum tau hloov kho phau ntawv txhais lus txhais lus hauv qhov program. Nkag mus rau 7 tus lej lej rau hauv qhov hloov pauv sib xws qhov chaw hauv qhov haujlwm, thiab rau txhua tus rau/tawm khawm, ntxig 3-tus lej lej (qhov no yog qhov ntev) rau hauv qhov hloov pauv sib xws hauv lub program.

Piv txwv li, yog tias hloov 1 ntawm muaj tus lej 1234567, tus lej tawm ntawm 7654321, thiab qhov ntev ntawm 890, tus lej yuav zoo li no:

chaws = {

'switch1': {'on': 1234567, #This is switch 1 on 'off': 7654321, #this yog hloov 1 tawm 'len': 890, #this yog hloov 1 code length}, 'switch2': {… }, Ib …}

Rov ua qhov no rau txhua lub pob. Thaum koj tab tom kho cov ntawv no, hloov cov hlua uas hais tias "KOJ-SUB-KEY" rau koj tus PubNub tso npe yuam sij, thiab "KOJ-PUB-KEY" rau koj tus lej tshaj tawm.

Thaum txhua lub pob tau raug kaw, koj tuaj yeem txuas ntxiv mus rau ntu tom ntej.

Kauj ruam 7: Khiav qhov program

Khiav qhov Program
Khiav qhov Program

Tam sim no koj muaj tag nrho koj cov lej, mus rau nplooj ntawv GitHub no (Ntawm koj lub khoos phis tawj, tsis yog raspberry pi) thiab nyem rau ntawm lub pob ntsuab uas hais tias "Clone lossis rub tawm", tom qab ntawv nyem "Download ZIP". Thaum cov ntaub ntawv no rub tawm, unzip nws thiab qhib daim nplaub tshev. Qhib cov ntaub ntawv npe main.js. Koj yuav tsum tau sau koj cov npe thiab tshaj tawm cov yuam sij hauv qhov haujlwm los ntawm kev hloov "KOJ-PUB-KEY" nrog koj tus lej tshaj tawm thiab "KOJ-SUB-KEY" nrog koj tus lej tso npe.

Tom ntej no, rov qab mus rau koj li Raspberry Pi thiab nkag mus

sej3 RFControl.py

Thaum nws luam tawm "Npaj", rov qab mus rau koj lub computer thiab qhib qhov index.html cov ntaub ntawv hauv lub vev xaib los ntawm kev ua nyem nyem, xaiv "Qhib nrog", thiab xaiv qhov browser koj nyiam. Koj yuav tsum pom 2 kab ntawm 5 cov nyees khawm, nrog rau cov npe ntawm cov hloov ntawm lawv. Nias ib yam ntawm cov nyees khawm. Yog tias nws raug tswj lub qhov (socket) kom raug, zoo heev! Yog tias tsis yog, ntawm no yog qee yam sim:

  1. Nco ntsoov tias Raspberry Pi tau txais cov lus. Nws yuav tsum luam tawm mus rau lub vijtsam thaum twg nws tau txais cov lus los ntawm lub vev xaib. Yog tsis yog, xyuas kom koj cov npe/tshaj tawm cov yuam sij raug.
  2. Yog tias Raspberry Pi tau txais cov lus, xyuas kom tseeb tias koj li lej RF raug. Nco ntsoov tias koj lub qhov hluav taws xob tau ua ke nrog koj lub chaw taws teeb, koj lub chaw taws teeb tuaj yeem tswj hwm lawv, thiab cov lej uas koj nkag mus rau hauv txoj haujlwm yog qhov raug.
  3. Yog tias RF cov lej raug, ua kom ntseeg tau tias koj Raspberry Pi nyob hauv thaj tsam ntawm cov chaw muag khoom. Yog tias lawv pib ua haujlwm tom qab txav nws ze dua, koj yuav xav tau rov ua koj lub kav hlau txais xov.
  4. Yog tias lawv tseem tsis ua haujlwm, thov qhia kuv qhov teeb meem hauv cov lus thiab kuv yuav sim thiab pab nrog nws.

Kauj ruam 8: Khiav ntawm Startup

Txhawm rau ua kom koj qhov kev pabcuam nab nab pib thaum pib, nkag mus rau hauv koj li raspberry pi davhlau ya nyob twg:

crontab -e

Tom ntej no, mus rau hauv qab ntawm cov ntawv thiab sau qhov no:

@reboot python3 /home/pi/RFControl.py &

Qhov no yuav ua rau koj cov ntawv Python khiav thaum pib txhua lub sijhawm. Tam sim no rov pib dua koj li Raspberry Pi.

Kauj Ruam 9: Ntxiv Cov Hloov Mus Ntxiv

Ntxiv Ntau Hloov
Ntxiv Ntau Hloov

Yog tias koj xav ntxiv ntau qhov chaw tawm, ua raws cov lus qhia no:

Qhib RFControl.py ntawm koj li Raspberry Pi, thiab ntxiv qhov hloov tshiab rau qhov hloov phau ntawv txhais lus.

Piv txwv:

hloov = {

… Lwm qhov hloov pauv… 'NAME-OF-SWITCH': {'on': xxxxxxx, 'off': yyyyyyy, 'len': zzz,},}

Tom ntej no, ntxiv khawm tshiab hauv koj lub vev xaib app los ntawm kev kho qhov hloov pauv hloov pauv hauv main.js ntawm koj lub computer.

Piv txwv:

var hloov = [… Qub keyboards… ['NAME-TO-DISPLAY', 'NAME-OF-SWITCH'],];

Hloov NAME-TO-DISPLAY nrog lub npe koj xav kom nws tshwm ntawm lub vev xaib, thiab NAME-OF-SWITCH ntawm ob daim ntawv nrog txhua yam uas koj nyiam. Nws yuav tsum yog qhov tshwj xeeb los ntawm lwm tus txawm tias!

Kauj Ruam 10: Ua Nws Ntxiv

Coj Nws Ntxiv
Coj Nws Ntxiv

PubNub tau txais kev txhawb nqa ntawm ntau lub platform sib txawv, uas txhais tau tias koj tuaj yeem xa lus los ntawm yuav luag txhua lub cuab yeej! Kuv siv Raspberry Pi AIY Lub suab khoom thiab PubNub xa cov lus txib nrog kuv lub suab, tab sis qhov ntawd yuav yog lub ncauj lus ntawm kev qhia tom qab. Ua tsaug rau koj nyeem Kuv Cov Lus Qhia, Kuv vam tias nws yuav pab tau!

Kauj ruam 11: Khab nias

Ua tsaug rau Tim Leland rau kev qhia qhia teeb tsa RF transmitter: qhia

Ua tsaug rau diy_bloke rau kev qhia ntawm kev tsim lub kav hlau txais xov: qhia

Ua tsaug rau lwm tus uas tshaj tawm cov ntawv qhia online uas kuv tau saib rau kev pab!

Pom zoo: