Cov txheej txheem:

Pas Pi Guy - AI Tsav Tswb System thiab Kev Saib Xyuas Pas Dej Siv Raspberry Pi: 12 Cov Kauj Ruam (nrog Duab)
Pas Pi Guy - AI Tsav Tswb System thiab Kev Saib Xyuas Pas Dej Siv Raspberry Pi: 12 Cov Kauj Ruam (nrog Duab)

Video: Pas Pi Guy - AI Tsav Tswb System thiab Kev Saib Xyuas Pas Dej Siv Raspberry Pi: 12 Cov Kauj Ruam (nrog Duab)

Video: Pas Pi Guy - AI Tsav Tswb System thiab Kev Saib Xyuas Pas Dej Siv Raspberry Pi: 12 Cov Kauj Ruam (nrog Duab)
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Hlis ntuj nqeg
Anonim
Pas Pi Guy - AI Tsav Tswb System thiab Pas Dej Saib Xyuas Siv Raspberry Pi
Pas Pi Guy - AI Tsav Tswb System thiab Pas Dej Saib Xyuas Siv Raspberry Pi

Muaj pas dej hauv tsev yog kev lom zem, tab sis los nrog lub luag haujlwm zoo. Kuv qhov kev txhawj xeeb tshaj plaws yog saib xyuas yog tias leej twg nyob ze ntawm lub pas dej tsis muaj neeg saib xyuas (tshwj xeeb yog menyuam yaus). Kuv qhov kev tsis txaus siab tshaj plaws yog ua kom ntseeg tau tias cov kab dej hauv pas dej tsis poob qis dua qhov nkag nkag, uas yuav ua rau lub twj tso kua mis qhuav thiab ua kom nws raug nqi $$$ hauv kev kho.

Tsis ntev los no kuv tau txiav txim siab yuav siv Raspberry Pi li cas nrog OpenCV thiab TensorFlow, nrog rau lub ntsuas dej ntsuas dej thiab lub solenoid valve los daws ob qho teeb meem - thiab muaj kev lom zem ua nws!

Nws hloov tawm kuj tseem yog lub tswb nrov zoo ib yam - cov lus tsa suab qhib, AI -tswj, tsis tuaj yeem hloov kho.

Cia peb dhia dej hauv.

Kauj Ruam 1: Txoj Kev Npaj Loj

Hauv cov lus qhia no peb yuav qhia yuav ua li cas:

  1. Teeb Raspberry Pi nrog OpenCV thiab TensorFlow
  2. Txuas lub Webcam los ntawm USB cable ntev
  3. Sau OpenCV algorithm txhawm rau txheeb xyuas cov lus tsa suab
  4. Siv TensorFlow txhawm rau txheeb xyuas qhov khoom
  5. Teeb tsa lub web server ntawm Raspberry Pi los qhia cov duab nthuav
  6. Koom ua ke nrog IFTTT txhawm rau ua rau ceeb toom mobile yog tias tus neeg raug kuaj pom
  7. Txuas tus HAT txuas mus rau Raspberry Pi thiab txuas nws mus rau lub solenoid valve uas yuav ntxiv dej rau hauv pas dej.
  8. Txuas lub ntsuas dej ntsuas mus rau Raspberry Pi thiab cuam tshuam nrog nws siv Pi's GPIO
  9. Sau qee cov cai los lo nws txhua qhov ua ke

Kauj Ruam 2: Daim Ntawv Khw Muag Khoom

Daim Ntawv Khw
Daim Ntawv Khw

Txhua qhov khoom siv tau npaj tau los ntawm Amazon. Xav tias dawb los sim thiab pauv cov khoom sib xyaw - qhov ntawd yog ib nrab ntawm kev lom zem!

  1. Raspberry Pi
  2. Raspberry Pi Power Supply (tsis txhob hla ntawm no)
  3. Daim npav nco (loj dua yog qhov zoo dua)
  4. Case (qhov no yog qhov loj txaus los nyob hauv tsev Pi thiab HAT)
  5. USB Webcam (txhua lub webcam yuav ua, tab sis koj xav tau ib qho uas tau txais cov duab zoo thiab sib npaug teeb pom kev zoo)
  6. USB txuas txuas txuas (yog xav tau - ntsuas qhov nrug nruab nrab ntawm Pi thiab qhov chaw koj yuav tso lub koob yees duab)
  7. Relay board HAT (qhov no muaj 3 qhov xa tawm thiab peb tsuas xav tau ib qho, tab sis koj yuav pom siv rau lwm qhov sai sai!)
  8. Solenoid
  9. Solenoid haum 1 thiab Haum 2 (uas tiag tiag nyob ntawm qhov koj haum solenoid rau, tab sis cov no ua haujlwm rau kuv)
  10. Solenoid Power Supply (ib qho 24V AC yuav ua)
  11. Cable (dua, yuav luag txhua 2 txoj hlua hluav taws xob yuav ua - tam sim no tsawg heev)
  12. Dej Qib Ntab Hloov (qhov no tsuas yog piv txwv, txheeb xyuas dab tsi tuaj yeem txuas nrog koj lub pas dej tau yooj yim)
  13. Qee qhov Jumper xov hlau thiab Cov txuas hlau

Kauj Ruam 3: Teeb Koj Raspberry Pi

Teeb Koj Raspberry Pi
Teeb Koj Raspberry Pi

Raspberry Pi yog lub khoos phis tawj me me zoo kawg. Nws raug nqi tsuas yog $ 35, ua haujlwm tas li, thiab muaj ntau yam software thiab kho vajtse sib xws. Teeb nws yog qhov yooj yim heev:

  1. Format koj daim npav SD. Qhov no xav tau kev saib xyuas tshwj xeeb - Raspberry Pi tuaj yeem tsuas yog khau raj los ntawm FAT formatted SD card. Ua raws li cov lus qhia no.
  2. Txuas Raspberry Pi mus rau USB keyboard thiab nas, ntxiv rau HDMI zaub, thiab ua raws cov lus qhia hauv Raspberry Pi NOOBS nyeem. Nco ntsoov teeb tsa WiFi thiab qhib kev nkag mus rau SSH. Tsis txhob hnov qab teeb tus password rau lub neej ntawd pi account.
  3. Ntawm koj lub tsev network teeb tsa tus IP zoo li qub rau Raspberry Pi - nws yuav ua rau nws yooj yim dua rau SSH rau.
  4. Nco ntsoov tias koj muaj tus neeg siv ssh teeb tsa ntawm koj lub desktop/laptop. Txog lub PC Kuv xav kom Putty, uas koj tuaj yeem teeb tsa los ntawm no.
  5. Tshem lub USB thiab HDMI los ntawm Raspberry Pi, rov pib dua nws, thiab ssh rau hauv nws - yog tias txhua yam ua haujlwm koj yuav tsum pom qee yam zoo li no:

Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Lub Ob Hlis 12 20: 27: 48 GMT 2019 armv7l

Cov phiaj xwm suav nrog Debian GNU/Linux system yog software dawb; cov ntsiab lus faib khoom meej rau txhua qhov haujlwm tau piav qhia hauv cov ntaub ntawv ib leeg hauv/usr/share/doc/*/copyright. Debian GNU/Linux los nrog ABSOLUTELY NO WARRANTY, raws li kev tso cai los ntawm txoj cai lij choj. Nkag mus zaum kawg: Mon Tsib Hlis 13 10:41:40 2019 los ntawm 104.36.248.13 pi@raspberrypi: ~ $

Kauj ruam 4: Teeb OpenCV

Teeb OpenCV
Teeb OpenCV

OpenCV yog qhov sau tau zoo ntawm cov duab ua haujlwm rau lub zeem muag hauv computer. Nws yuav tso cai rau peb nyeem cov duab los ntawm Webcam, tswj lawv kom pom thaj chaw ntawm cov lus tsa suab, txuag lawv thiab ntau ntxiv. Teeb ntawm Raspberry Pi tsis nyuaj tab sis xav tau kev saib xyuas qee yam.

Pib los ntawm kev txhim kho virtaulenvwrapper: peb yuav siv nab nab los ua txhua yam ntawm peb cov phiaj xwm, thiab virtualenv yuav pab peb khaws kev cia siab sib cais rau OpenCV thiab TensorFlow vs. Flask lossis GPIO:

pi@raspberrypi: ~ $ sudo pip nruab virtualenvwrapper

Tam sim no koj tuaj yeem ua "mkvirtualenv" los tsim ib puag ncig tshiab, "ua haujlwm" los ua haujlwm rau nws, thiab ntau ntxiv.

Yog li, cia peb tsim ib puag ncig rau peb cov duab siv, nrog nab nab 3 ua tus txhais lus tsis raug (nws yog 2019, tsis muaj laj thawj los ua ke nrog tus nab npawb qub 2):

pi@raspberrypi: ~ $ mkvirtualenv cv -p nab hab sej3

… (Cv) pi@raspberrypi: ~

Tam sim no peb tau npaj rau nruab OpenCV. Peb feem ntau yuav ua raws cov ntawv qhia tau zoo hauv Kawm OpenCV. Tshwj xeeb ua raws lawv qib 1 thiab 2:

sudo apt -y hloov tshiabudo apt -y hloov kho ## Txhim kho kev vam khom sudo apt-tau -y nruab tsim-qhov tseem ceeb tshawb xyuas cmake pkg-teeb tsa yasm sudo apt-tau -y nruab git gfortran sudo apt-tau -y nruab libjpeg8-dev libjasper- dev libpng12-dev sudo apt-tau -y nruab libtiff5-dev sudo apt-tau -y nruab libtiff-dev sudo apt-tau -y nruab libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev sudo apt-tau- y nruab libxine2-dev libv4l-dev cd/usr/suav nrog/linux sudo ln -s -f../libv4l1-videodev.h videodev.h sudo apt-get -y nruab libgstreamer0.10-dev libgstreamer-plugins-base0. 10-dev sudo apt-tau -y nruab libgtk2.0-dev libtbb-dev qt5-default sudo apt-get -y install libatlas-base-dev sudo apt-get -y install libmp3lame-dev libtheora-dev sudo apt-get -y nruab libvorbis-dev libxvidcore-dev libx264-dev sudo apt-tau -y nruab libopencore-amrnb-dev libopencore-amrwb-dev sudo apt-get -y nruab libavresample-dev sudo apt-tau -y nruab x264 v4l-utils sudo apt -tau -y nruab libprotobuf -dev protobuf-compiler sudo apt-get -y nruab libgoogle-glog-dev libgflags-dev sudo apt-tau -y nruab libgphoto2-dev libeigen3-dev libhdf5-dev doxygen sudo apt-tau nruab libqtgui4 sudo apt-tau nruab libqt4- xeem

Tam sim no peb tsuas tuaj yeem teeb tsa OpenCV nrog nab hab sej khi hauv cv virtualenv (koj tseem nyob hauv nws, puas yog?) Siv

pip nruab opencv-contrib-python

Thiab qhov ntawd yog nws! Peb tau OpenCV teeb tsa ntawm peb Raspberry Pi, npaj txhij los ntes cov duab thiab yeeb yaj kiab, tswj lawv thiab ua kom txias.

Txheeb xyuas qhov ntawd los ntawm kev qhib tus neeg txhais lus nab nab thiab ntsaws rau hauv opencv thiab tshawb xyuas tias tsis muaj qhov yuam kev:

(cv) pi@raspberrypi: ~ $ nab hab sej

Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] ntawm linux Hom "pab", "cai lij choj", "khab nias" lossis "ntawv tso cai" kom paub ntau ntxiv. >>> ntshuam cv2 >>>

Kauj Ruam 5: Teeb TensorFlow

Teeb TensorFlow
Teeb TensorFlow

TensorFlow yog lub tshuab kev kawm / AI tus qauv tsim thiab tswj hwm los ntawm Google. Nws muaj kev txhawb nqa dav rau cov qauv kev kawm tob rau ntau yam haujlwm xws li nrhiav cov khoom hauv cov duab, thiab tam sim no yooj yim rau nruab rau ntawm Raspberry Pi. Kev ua tau zoo ntawm nws cov qauv hnyav ntawm Pi me me nyob ib puag ncig 1 thav duab ib pliag, uas zoo txaus rau daim ntawv thov zoo li peb.

Peb yuav ua raws qhov kev qhia zoo los ntawm Edje Electronics, nrog kev hloov kho ua tau los ntawm TensorFlow kev faib tawm tsis ntev los no:

pi@raspberrypi: ~ $ ua haujlwm cv

(cv) pi@raspberrypi: ~ $ pip install tensorflow (cv) pi@raspberrypi: ~ $ sudo apt-get install libxml2-dev libxslt-dev (cv) pi@raspberrypi: ~ $ pip install pillow lxml jupyter matplotlib cython (cv)) pi@raspberrypi: ~ $ sudo apt-tau nruab python-tk

Tam sim no peb yuav tsum tau suav ua Google lub protobuf. Tsuas yog ua raws cov lus qhia hauv qib 4 ntawm tib qho kev qhia zoo

Thaum kawg, clone thiab teeb tsa TensorFlow tus qauv txhais - ua raws qib 5 hauv Edje Electronics qhia

Xav tias dawb ua raws lawv cov piv txwv hauv qib 6 ib yam nkaus, nws yog ib qho kev qhia zoo rau kev txheeb xyuas qhov khoom ntawm Raspberry Pi.

Kauj Ruam 6: Kev Tshawb Fawb Siv OpenCV

Cia peb pib los ntawm kev sim uas OpenCV tuaj yeem cuam tshuam nrog peb lub vev xaib: ssh rau hauv Raspberry Pi, txav mus rau cv virtualenv (workon cv), qhib tus neeg txhais lus nab nab (tsuas yog ntaus nab nab), thiab nkag mus rau hauv qab nab nab cov lus txib:

ua cv2

cap = cv2. VideoCapture (0) cap.set (cv2. CAP_PROP_FRAME_WIDTH, 1920) cap.set (cv2. CAP_PROP_FRAME_HEIGHT, 1080) ret, thav duab = cap.read () luam tawm ('Nyeem cov duab loj: {} x {}'.format (frame.shape [1], frame.shape [0])

Nrog qhov muaj hmoo koj yuav pom tias OpenCV tuaj yeem nyeem HD thav duab los ntawm lub koob yees duab.

Koj tuaj yeem siv cv2.imwrite (txoj hauv kev, thav duab) los sau cov kab ntawv ntawd rau disk thiab sftp nws rov qab los saib qhov tseeb.

Lub tswv yim txhawm rau txheeb xyuas cov lus tsa suab yog ncaj ncaj rau pem hauv ntej:

  1. Ua haujlwm ntawm cov kev daws teeb meem qis dua - tsis tas yuav tsum ua haujlwm puv HD ntawm no
  2. Ntxiv mus, plooj cov duab kom ntseeg tau tias muaj suab nrov me ntsis.
  3. Khaws qhov nruab nrab khiav ntawm N thav duab kawg. Rau daim ntawv thov no, qhov twg tus lej nyob ib puag ncig 1 FPS (tsuas yog vim TensorFlow siv sijhawm qee lub sijhawm ntawm tus ncej), Kuv pom tias N = 60 rov qab tau cov txiaj ntsig zoo. Thiab txij li kev ua tib zoo siv tsis siv CPU ntau nrog cov thav duab uas zoo dua (nws siv lub cim xeeb ntau dua - tab sis qhov tsis muaj txiaj ntsig thaum peb ua haujlwm nrog cov kab lus qis dua)
  4. Rho tawm cov duab tam sim no los ntawm qhov nruab nrab khiav (tsuas yog ceev faj nrog kev ntaus ntawv - koj yuav tsum tso cai rau qhov zoo thiab qhov tsis zoo [-255.. 255], yog li cov ncej yuav tsum tau hloov pauv mus rau int)
  5. Koj tuaj yeem ua qhov kev rho tawm ntawm qhov hloov pauv ntawm cov xim grey ntawm tus ncej (thiab qhov nruab nrab), lossis ua nws cais rau txhua qhov ntawm RGB raws thiab tom qab ntawd ua ke cov txiaj ntsig (uas yog lub tswv yim kuv tau xaiv, ua rau nws hloov pauv xim)
  6. Siv qhov chaw pib ntawm lub delta thiab tshem suab nrov los ntawm kev yaig thiab nthuav dav
  7. Thaum kawg saib mus rau qhov contours ntawm cov cheeb tsam nrog lub delta - cov cheeb tsam no yog qhov uas cov lus tsa suab tau tshwm sim thiab cov duab tam sim no txawv ntawm qhov nruab nrab ntawm cov duab yav dhau los. Peb tuaj yeem nrhiav cov thawv txuas rau cov kab ntawv no yog xav tau.

Kuv tau kaw cov cai los ua qhov no hauv DeltaFinder sej chav kawm uas koj tuaj yeem pom hauv kuv github ntawm no

Kauj Ruam 7: Txheeb Cov Khoom Siv TensorFlow

Yog tias koj tau ua raws TensorFlow txheej txheem teeb tsa, koj twb tau sim lawm tias koj tau TensorFlow teeb tsa thiab ua haujlwm.

Rau lub hom phiaj txhawm rau txheeb xyuas tib neeg nyob rau qhov xwm txheej sab nraum zoov, cov qauv uas tau kawm ua ntej ntawm COCO cov ntaub ntawv teeb tsa ua tau zoo heev - uas yog tus qauv uas peb tau rub tawm thaum kawg ntawm TensorFlow kev teeb tsa. Peb tsuas yog xav siv nws rau kev pom!

Ib zaug ntxiv, Kuv tau kaw cov qauv kev thauj khoom thiab kev suav hauv TFClassify chav nab nab los ua kom yooj yim dua, uas koj tuaj yeem pom ntawm no.

Kauj Ruam 8: Teeb Web Server ntawm Raspberry Pi

Teeb Tus Web Server ntawm Raspberry Pi
Teeb Tus Web Server ntawm Raspberry Pi

Txoj hauv kev yooj yim tshaj plaws txhawm rau nkag mus rau qhov ntsuas pom qhov tshwm sim yog lub vev xaib, yog li cia teeb tsa lub web server ntawm Raspberry Pi. Peb tuaj yeem teeb tsa nws los ua cov duab los ntawm cov npe qhia.

Muaj ntau txoj kev xaiv rau lub vev xaib server server. Kuv xaiv Flask Nws yog teeb tsa tau yooj yim heev thiab txuas ntxiv nrog Python. Txij li thaum "nplai" peb xav tau yog qhov tsis tseem ceeb, nws tau ntau tshaj li txaus.

Kuv hais kom txhim kho nws hauv virtualenv tshiab, yog li:

pi@raspberrypi: ~ $ mkvirtualenv webserv

(webserv) pi@raspberrypi: ~ $ pip nruab Flask

Nco ntsoov tias nrog lub network teeb tsa ib txwm nws yuav tsuas yog siv tau thaum koj lub browser nyob ntawm tib lub wireless LAN ib yam li koj li Raspberry Pi. Koj tuaj yeem tsim qhov chaw teeb tsa chaw teeb tsa / NAT teeb tsa ntawm koj lub Internet router kom tso cai nkag sab nraud - tab sis kuv pom zoo tawm tsam qhov ntawd. Cov cai kuv sau tsis tau sim muab kev nyab xeeb uas koj xav tau thaum tso cai siv Internet nkag mus rau koj li Raspberry Pi.

Ntsuam xyuas koj kev teeb tsa los ntawm kev ua raws li Flask phau ntawv qhia pib sai

Kauj Ruam 9: Kev Ceeb Toom Txawb Los Ntawm Raspberry Pi Siv IFTTT

Kev Ceeb Toom Txawb Los Ntawm Raspberry Pi Siv IFTTT
Kev Ceeb Toom Txawb Los Ntawm Raspberry Pi Siv IFTTT

Kuv yeej xav tau txais ntawv ceeb toom mobile thaum muaj xwm txheej tshwm sim. Hauv qhov no, thaum ib tus neeg raug kuaj pom thiab thaum qib dej mus qis. Txoj hauv kev yooj yim tshaj plaws uas kuv pom ua qhov ntawd, yam tsis tas yuav sau cov kev cai mobile app, yog siv IFTTT. IFTTT sawv rau "Yog Qhov No Yog Qhov ntawd" thiab ua rau ntau hom xwm txheej ua rau muaj ntau hom kev nqis tes ua. Hauv peb qhov xwm txheej, peb txaus siab rau IFTTT Maker Webhook trigger. Qhov no tso cai rau peb txhawm rau ua IFTTT los ntawm kev thov HTTP POST thov mus rau IFTTT server nrog tus yuam sij tshwj xeeb muab rau peb tus as khauj, nrog rau cov ntaub ntawv qhia meej tias muaj dab tsi tshwm sim. Kev nqis tes ua peb tuaj yeem yooj yim xws li tsim kev ceeb toom ntawm peb lub xov tooj ntawm tes siv IFTTT mobile app, lossis txhua yam nyuaj dua li qhov ntawd.

Nov yog yuav ua li cas:

  1. Tsim tus lej IFTTT ntawm ifttt.com
  2. Thaum nkag mus, mus rau Webhook cov kev pabcuam teeb tsa nplooj ntawv thiab nkag mus rau URL hauv koj tus browser (qee yam xws li https://maker.ifttt.com/use/. Qhov web page ntawd yuav qhia koj tus yuam sij thiab URL kom siv los ua qhov kev ua..
  3. Tsim IFTTT applet uas yuav tsim kev ceeb toom mobile thaum Webhook raug cuam tshuam nrog cov ntsiab lus ntawm qhov xwm txheej:

    1. Nyem "Kuv Applets" thiab tom qab ntawd "Applet Tshiab".
    2. Nyem "+qhov no" thiab xaiv "webhooks". Nyem "Tau txais lub vev xaib thov" txhawm rau txuas mus rau cov ntsiab lus
    3. Muab koj lub npe tshwm sim, piv txwv. "PoolEvent" thiab nyem "Tsim txhais"
    4. Nyem "+ntawd" thiab xaiv "ceeb toom". Tom qab ntawv xaiv "Xa cov ntawv ceeb toom nplua nuj los ntawm IFTTT app"
    5. Rau "npe" xaiv qee yam xws li "PoolPi"
    6. Rau "lus" sau "Pool Pi kuaj pom:" thiab nyem "ntxiv cov khoom".. "Value1".
    7. Rov qab mus rau qhov URL koj tau theej hauv kauj ruam 2. Nws yuav qhia qhov URL siv los hu rau koj li applet uas tau tsim tshiab. Luam qhov URL ntawd, hloov qhov chaw tso {xwm txheej} nrog lub npe txheej xwm (hauv qhov piv txwv PoolEvent)
  4. Rub tawm, nruab thiab nkag mus rau IFTTT app rau koj lub xov tooj ntawm tes
  5. Khiav cov ntawv nab nab no ntawm koj Raspberry Pi kom pom nws ua haujlwm (nco ntsoov nws yuav siv ob peb feeb lossis feeb los ua rau koj lub xov tooj ntawm tes):

ntshuam thov

thov.post ('https://maker.ifttt.com/trigger/PoolEvent/with/key/', json = {"value1": "Nyob Zoo Cov Lus Qhia"})

Kauj Ruam 10: Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve

Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve
Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve
Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve
Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve
Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve
Ntxiv Relay HAT rau Raspberry Pi thiab txuas nws mus rau Solenoid Valve

Ua ntej mus txuas ntxiv nrog cov kauj ruam no Tua koj tus Raspberry Pi: ssh rau nws thiab ntaus "sudo kaw tam sim no", tom qab ntawd txiav nws los ntawm lub zog

Peb lub hom phiaj yog tig thiab tua lub hwj chim rau lub solenoid valve - lub valve uas tuaj yeem qhib lossis kaw cov khoom siv dej raws li 24V AC lub zog nws tau txais los ntawm lub hwj chim. Kev xa tawm yog cov khoom siv hluav taws xob uas tuaj yeem qhib lossis kaw lub Circuit Court raws li lub teeb liab digital uas peb Raspberry Pi tuaj yeem muab tau. Peb ua dab tsi ntawm no yog sib txuas ib qho txuas mus rau cov teeb liab digital ntawm Raspberry Pi, thiab kom nws kaw qhov Circuit Court ntawm 24V AC fais fab mov thiab lub solenoid valve.

Cov pins ntawm Raspberry Pi uas tuaj yeem ua raws li cov tswv yim digital lossis tso tawm tau hu ua GPIO - Lub Hom Phiaj Tawm Tswv Yim/Tawm Tawm thiab lawv yog kab ntawm 40 tus pin ntawm sab ntawm Pi. Nrog tus Pi tua tawm thiab ntxig rau relay HAT khov kho rau hauv nws. HAT Kuv tau xaiv muaj 3 qhov xa tawm hauv nws, thiab peb yuav siv ib qho ntawm lawv xwb. Xav txog txhua yam koj tuaj yeem ua nrog ob qho ntxiv:)

Tam sim no tig lub Raspberry Pi rov qab. Liab "hwj chim" LED ntawm lub HAT relay yuav tsum qhib, qhia tias nws tau txais lub zog los ntawm Pi los ntawm GPIO. Cia peb sim tias peb tuaj yeem tswj hwm nws: ssh rau hauv Pi dua, sau sej thiab ntaus:

ntshuam gpiozero

dev = gpiozero. DigitalOutputDevice (26, initial_value = Tseeb) dev.off ()

Koj yuav tsum hnov lub suab "nyem", qhia tias kev xa xov tau koom nrog, thiab pom LED tig los qhia tias thawj qhov kev xa xov nyob hauv txoj haujlwm sib txuas. Tam sim no koj tuaj yeem ntaus ntawv

dev.on ()

Uas yuav tig qhov txuas mus rau "tawm" txoj haujlwm (khib, Kuv paub …) thiab tawm () los ntawm nab hab sej.

Tam sim no siv jumper cables thiab ntev dua cable txuas qhov txuas ntawm 24V cov khoom siv hluav taws xob thiab solenoid valve. Saib daim duab. Thaum kawg, txuas lub solenoid valve mus rau tus kais dej siv lub adapters thiab npaj txhij los ntsuas nws txhua qhov los ntawm kev rov ua cov lus txib saum toj no - lawv yuav tsum tig thiab tso dej tawm.

Txuas lub hose rau lub solenoid valve thiab muab lwm qhov kawg sib sib zog nqus hauv pas dej. Tam sim no koj muaj lub khoos phis tawj tswj hwm lub pas dej ua ke saum toj kawg nkaus, thiab nws yog lub sijhawm los txuas lub sensor los qhia nws thaum yuav khiav.

Kauj Ruam 11: Txuas Tus Dej Qib Sensor

Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor
Txuas tus Dej Qib Sensor

Lub ntsuas dej theem tsuas yog ntab uas txuas cov hluav taws xob hluav taws xob thaum ntab ntog, thiab tsoo nws thaum nws ntab. Yog tias koj ntxig nws rau hauv pas dej ntawm qhov siab raug ntab yuav nce thaum cov dej txaus tab sis poob qis thaum tsis muaj dej txaus.

Rau Raspberry Pi kom paub qhov xwm txheej ntsuas dej theem peb xav tau Pi kom nkag siab qhov qhib lossis kaw Circuit Court. Hmoov zoo uas yog qhov yooj yim heev: tib lub GPIO cov khoom sib txuas uas peb siv los ua cov digital los tswj cov kev xa tawm tuaj yeem ua raws li cov tswv yim (li no kuv hauv GPIO). Tshwj xeeb, yog tias peb txuas ib lub xov tooj ntawm lub ntsuas hluav taws xob mus rau +3.3V ntawm GPIO txuas thiab lwm lub xov tooj sensor mus rau tus pin uas peb teeb tsa raws li rub tawm cov tswv yim (txhais tau tias nws yuav ib txwm nyob ntawm GND voltage theem), tus pin yuav ntsuas digital "siab" lossis "ntawm" qhov hluav taws xob tsuas yog thaum ntsuas qib dej kaw qhov Circuit Court - thaum cov dej qis. Kuv siv GPIO tus pin 16 raws li kev tawm tswv yim, uas kuv cim hauv daim duab saum toj no.

Python code txhawm rau teeb tsa tus pin ua tswv yim thiab sim nws lub xeev tam sim no yog:

ntshuam gpiozero

level_input = gpiozero. Button (16) dej_low = level_input.is_pressed

Ib qho kev sib tw muaj peev xwm yog tias thaum lub ntsuas ntsuas tsuas yog hloov pauv lub xeev nws yuav oscillate nrawm ntawm nruab nrab ntawm thiab hauv xeev. Kev daws rau qhov ntawd hu ua "debouncing" thiab nrhiav kev hloov pauv hauv lub xeev ua ntej yuav nqis tes ua. GPIOZERO lub tsev qiv ntawv muaj cov cai los ua qhov ntawd, tab sis vim qee qhov chaws tsis ua haujlwm zoo rau kuv. Kuv tau sau lub voj yooj yim kom ua rau IFTTT ceeb toom thaum pom lub xeev hloov pauv zoo ib yam, uas koj tuaj yeem pom hauv kuv lub chaw cia khoom ntawm no.

Kauj Ruam 12: Sau Code kom Tie It All Together

Sau Code los khi nws tag nrho ua ke
Sau Code los khi nws tag nrho ua ke

Qhov ntawd yog nws. Peb teeb tsa tiav. Koj tuaj yeem sau koj tus kheej txoj cai los khi cov khoom ua ke rau hauv tag nrho cov kab ke, lossis siv cov cai kuv muab. Txhawm rau ua qhov ntawd tsuas yog tsim cov qauv txheej txheem thiab clone lub chaw cia khoom, zoo li:

mkdir pib

cd poolpi git clone

Tom ntej no, kho cov ntaub ntawv npe ifttt_url.txt hauv tsab ntawv tsa suab_lert thiab dej_level cov npe kom muaj qhov URL rau koj tus kheej IFTTT web nuv ntses nrog koj tus yuam sij zais. Koj tuaj yeem siv ob lub vev xaib sib txawv rau kev ua haujlwm sib txawv.

Thaum kawg, peb xav kom cov cai no siv tau. Txoj hauv kev yooj yim tshaj plaws los ua tiav yog los ntawm Linux crontab kev pabcuam. Peb tuaj yeem ntxiv qee kab crontab rau ob txoj haujlwm tseem ceeb:

  1. Khiav peb peb txoj haujlwm: ntsuas lub ntsuas, ntsuas ntsuas dej thiab web server ntawm txhua qhov rov pib dua
  2. Ntxuav cov ntawv teev npe tso tawm, tshem cov duab qub thiab cov vis dis aus qub (Kuv xaiv rho tawm cov ntaub ntawv laus dua 1 hnub thiab cov duab qub dua 7 hnub - xav tias yuav sim)

Txhawm rau ua hom crontab -e uas yuav qhib koj li nano ntawv editor. Ntxiv cov kab hauv qab no rau hauv qab ntawm cov ntawv:

0 1 * * * nrhiav/tsev/pi/poolpi/output -type f -name " *.avi" -mtime +1 -delete

0 2 * * * nrhiav/tsev/pi/poolpi/output -type f -name " *.jpg" -mtime +7 -delete @reboot python3 /home/pi/poolpi/motion_alert/webserv/webserv.py @reboot python3 /home/pi/poolpi/motion_alert/motion_obj_alert.py @reboot python3 /home/pi/poolpi/water_level/test_water_level.py

Thaum kawg, rov pib dua koj li Raspberry Pi. Tam sim no nws tau npaj ua kom koj lub pas dej puv thiab nyab xeeb.

Ua tinker nrog teeb tsa, cov cai, thiab tsis txhob hnov qab lub hnub qub kuv qhov chaw cia khoom github thiab tawm tswv yim ntawm cov lus qhia yog tias koj pom nws muaj txiaj ntsig. Kuv ib txwm saib kom paub ntxiv.

Zoo siab ua!

IoT Kev Sib Tw
IoT Kev Sib Tw
IoT Kev Sib Tw
IoT Kev Sib Tw

Khiav Tawm hauv IoT Challenge

Pom zoo: