Cov txheej txheem:

Node Liab - Tswj RaspberryPi: 8 Kauj Ruam
Node Liab - Tswj RaspberryPi: 8 Kauj Ruam

Video: Node Liab - Tswj RaspberryPi: 8 Kauj Ruam

Video: Node Liab - Tswj RaspberryPi: 8 Kauj Ruam
Video: Raspberry Pi GPIO Switch Input - Part 3: Writing the Node.js Script 2024, Hlis ntuj nqeg
Anonim
Node Liab - Tswj RaspberryPi
Node Liab - Tswj RaspberryPi

Hauv cov lus qhia no peb yuav saib yuav teeb tsa Node-Red software li cas thiab yuav tswj hwm GPIO ntawm koj li raspberry pi li cas yooj yim.

Kauj Ruam 1: Txhim Kho Pob

Ua ntej peb yuav tsum teeb tsa pob khoom. Txhawm rau ua qhov no koj yuav tsum tau muab cov lus txib hauv qab no hauv lub davhlau ya nyob twg:

pi@raspberrypi: ~ $ sudo apt-tau hloov tshiab

pi@raspberrypi: ~ $ sudo apt-get install build-essential sej-rpi.gpio

(yog tias khiav stretch rasbian nws yuav tsum tau teeb tsa.)

pi@raspberrypi: ~ $ bash <(curl -sL

Kauj Ruam 2: Pib Node-Liab thawj zaug

Txhawm rau pib Node-Liab koj tsuas yog xav tau los ua lub davhlau ya nyob twg hais kom ua: pi@raspberrypi: ~ $ node-red-start

Txhawm rau pib dua Node-Red thaum lub khau khau khau koj tsuas xav tau los pab cov kev pabcuam nrog cov lus txib hauv qab no:

pi@raspberrypi: ~ $ sudo systemctl pab kom nodered.service

Kauj Ruam 3: Nkag Mus Rau Hauv Web Page

Nkag Mus Rau Hauv Web Page
Nkag Mus Rau Hauv Web Page

Tam sim no koj tsuas xav tau nkag mus rau lub vev xaib uas tam sim no tau khiav ntawm koj li raspberry pi rau Node-Red kev txhim kho.

Txhawm rau ua qhov no koj tsuas yog yuav tsum mus rau koj tus pi chaw nyob thiab siv chaw nres nkoj 1880.

Piv txwv:

Yog tias kuv tus pi chaw nyob yog 192.168.1.40 ces kuv yuav nkag mus siv

Kauj Ruam 4: Txhim Kho Dashboard Module rau GPIO

Txhim kho Dashboard Module rau GPIO
Txhim kho Dashboard Module rau GPIO

Tam sim no peb yuav saib tsim lub dashboard rau koj tswj hwm GPIO. Ua ntej peb yuav tsum tau teeb tsa lub dashboard tivthaiv.

Ua cov lus txib hauv qab no hauv lub davhlau ya nyob twg ntawm koj tus pi:

pi@raspberrypi: ~ $ node-red-stop

pi@raspberrypi: ~ $ cd ~/.node-red pi@raspberrypi: ~ $ npm nruab node-red-dashboard pi@raspberrypi: ~ $ node-red-start

Kauj Ruam 5: Tsim Dashboard rau GPIO

Tam sim no koj yuav tsum rov qab mus rau nplooj ntawv browser uas koj tau mus rau ua ntej hauv qhov haujlwm no.

Los ntawm nplooj ntawv no peb yuav tsim ib qho piv txwv ntawm GPIO. Kuv yuav tso qhov hloov pauv thiab ib qho swb rau tig GPIO rau thiab tawm thiab ib qho rau kev ua haujlwm pwm nthwv dej.

Koj yuav tsum tau nrhiav, los ntawm sab laug ntawm lub vaj huam sib luag hauv qab dashboard, khawm hloov thiab rub nws mus rau Flow 1. Tom qab ntawd koj yuav tsum nrhiav tus swb thiab rub nws mus rau Flow 1 ib yam.

Tam sim no koj yuav tsum nrhiav GPIO nyob rau hauv seem raspberry pi. Tam sim no koj xav tau gpio module uas muaj qhov txuas sib txuas ntawm sab laug txij li qhov no yog cov qauv siv. Luag ob qho ntawm qhov no mus rau Flow 1 hla ntawm qhov hloov pauv thiab swb.

Cias tso koj tus cursor ntawm qhov txuas ntawm sab laug ntawm qhov hloov pauv thiab nyem thiab rub mus rau qhov txuas txuas ntawm sab laug ntawm ib qho ntawm GPIO pins. Ua tib yam rau tus swb.

Thaum txuas nrog koj yuav tsum teeb tsa txhua daim los ntawm ob npaug nyem rau lawv.

Kauj ruam 6: Configuring Switch

Kho qhov Hloov
Kho qhov Hloov
Kho qhov Hloov
Kho qhov Hloov

Ob npaug nias rau ntawm qhov hloov pauv thiab qhib cov khoom ntawv qhia zaub mov.

Ntawm no koj yuav tsum nyem qhov xaum ntawm sab xis ntawm pab pawg.

Tam sim no tsim cov pab pawg tshiab lub npe (Kuv tso kuv tus kheej rau lub neej ntawd)

Xaiv tus xaum cim lub cim nyob ib sab ntawm TAB thiab npe lub rooj koj xav kom qhov no yog ib feem ntawm (Kuv tau xaiv tsev)

Tam sim no xaiv hloov tshiab nyob rau sab xis saum toj.

Tam sim no koj tuaj yeem xaiv koj qhov loj thiab teeb tsa ntawm koj qhov kev hloov pauv. Thaum koj tau txais lub cim koj xav siv thiab txhua yam tshuaj pleev ib ce tiav koj yuav nqis mus rau qhov kev xaiv them nyiaj.

Rau kev hloov pauv koj yuav tsum teeb tsa cov kev xaiv them nyiaj raws li hauv qab no:

Xaiv qhov nco cia nyob ib sab ntawm lub thawv ntawv them nyiaj thiab xaiv tus lej rau ob qho kev them nyiaj ces teeb:

Them Nyiaj: 1

Tsis Them Nyiaj: 0

Tam sim no koj yuav tsum teeb tsa GPIO tus pin uas koj xav hloov.

Ob npaug nias rau tus pin rau qhov hloov pauv thiab qhov no yuav qhib qhov hloov rpi-gpio tawm hom.

Xaiv tus pin koj xav siv, hauv peb qhov xwm txheej peb siv GPIO04-7 tus pin.

Muab nws lub npe yog tias koj xav tau thiab xaiv "Ua"

Kauj Ruam 7: Kho lub Slider

Kho lub Slider
Kho lub Slider
Kho lub Slider
Kho lub Slider

Txhawm rau teeb tsa tus slider koj yuav tsum xub nyem ob zaug ntawm lub pob nyem slider dashboard.

Thaum nyob ntawd koj yuav hloov cov khoom "ntawv cim" rau yam koj xav kom nws lub npe nyob hauv UI.

Tom ntej no koj yuav teeb tsa yam tsawg kawg nkaus thiab qhov ntau kawg. Txij li PWM LED qhov ci ci nyob rau hauv feem pua feem ntau, vim yog %Duty Cycle, peb xav tau yam tsawg kawg yog 0 thiab qhov siab tshaj plaws yog 100.

Tam sim no rau peb tus piv txwv yuav ua li cas txhoj puab heev lub teeb hloov ci ntsa iab yog los ntawm cov kauj ruam. Kuv muaj peb teeb tsa rau 1 rau ib kauj ruam yog li 1 chav ntawm cov swb yog sib npaug rau 1% ci ntsa iab.

Qhov ntawd yog nws rau tus swb

Rau tus Pin koj yuav xav tau ob npaug nias qhov cuam tshuam nrog GPIO tus lej cim.

Tam sim no rau rus peb xaiv GPIO18 tus pin vim qhov no yog PMW tus pin rau Raspberry pi 3 B+

Tom qab ntawd koj yuav tsum xaiv PWM tso tawm hauv hom teb kom nws paub tias nws yog PWM tso tawm.

Muab nws lub npe thiab koj tau npaj mus.

Kauj ruam 8: Tua tawm UI thiab Xeem

Image
Image

Tam sim no txhawm rau sim tawm koj lub dashboard UI tshiab koj yuav tsum tau nyem rau ntawm lub kaum sab xis saum toj kom siv koj li kev cai. Tom qab ntawd koj yuav tsum mus rau IP chaw nyob ntawm koj tus pi uas yog runnin node-red. Thiab tshaj qhov UI xaiv rau nws piv txwv: https://192.168.1.31:1880/ui Yam koj yuav tsum pom yog koj hloov thiab koj tus swb uas koj tau tsim. Tam sim no koj tuaj yeem sim los ntawm txhaj rau txhua tus Kuv vam tias koj tau txaus siab rau Cov Lus Qhia no thiab thov txheeb xyuas hauv youtube channel thiab cov vis dis aus rau lwm cov ntaub ntawv.

Pom zoo: