Cov txheej txheem:

LED Blink Nrog Raspberry Pi - Yuav Siv GPIO Pins ntawm Raspberry Pi: 4 Cov Kauj Ruam
LED Blink Nrog Raspberry Pi - Yuav Siv GPIO Pins ntawm Raspberry Pi: 4 Cov Kauj Ruam

Video: LED Blink Nrog Raspberry Pi - Yuav Siv GPIO Pins ntawm Raspberry Pi: 4 Cov Kauj Ruam

Video: LED Blink Nrog Raspberry Pi - Yuav Siv GPIO Pins ntawm Raspberry Pi: 4 Cov Kauj Ruam
Video: Varying brightness of LED using PWM on Rpi 2024, Hlis ntuj nqeg
Anonim
LED Blink Nrog Raspberry Pi | Yuav Siv GPIO Pins ntawm Raspberry Pi li cas
LED Blink Nrog Raspberry Pi | Yuav Siv GPIO Pins ntawm Raspberry Pi li cas

Nyob zoo cov neeg hauv phau ntawv qhia no peb yuav kawm paub siv GPIO li cas ntawm Raspberry pi. Yog tias koj tau siv Arduino ces tej zaum koj paub tias peb tuaj yeem txuas LED hloov lwm yam rau nws cov pins thiab ua kom nws ua haujlwm zoo li. ua rau LED ntsais muag lossis tau txais cov tswv yim los ntawm kev hloov qee yam zoo li ntawd. Txij li Raspberry pi kuj tseem muaj GPIOs yog li peb yuav kawm paub siv GPIOs li cas thiab peb yuav txuas lub LED rau nws thiab ua rau nws ntsais muag. Tsuas yog qhov yooj yim LED ntsais txoj haujlwm peb yuav ua kom koj nkag siab siv GPIOs ntawm Raspberry pi li cas.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Txog cov lus qhia no koj yuav xav tau cov khoom hauv qab no: Raspberry Pi 3 teeb tsa nrog saib thiab USB Mouse & Keyboard (Nco ntsoov tias Raspbian OS tau teeb tsa kom raug hauv koj li Raspberry pi) breadboardJumper wiresResistorsLED

Kauj ruam 2: Circuit Court

Circuit Court
Circuit Court
Circuit Court
Circuit Court

Ib feem ntawm Circuit yog ib qho yooj yim heev. Kuv txuas nrog LED rau tus pin 8. Which txhais tau tias tsis zoo txhais ceg ntawm LED txuas nrog Gnd tus pin (6 tsis muaj.) Thiab cov ceg zoo txuas nrog 100ohm (100-1000ohm siv aby tus nqi) thiab lwm ceg ntawm resistor txuas nrog tus pin 8 ntawm Raspberry pi.

Kauj Ruam 3: Coding Tshooj

Coding Tshooj
Coding Tshooj

Tom qab ntawd qhib lub dav hlau pi kom ua rau LED ntsais: Txhawm rau nruab Python lub tsev qiv ntawv qhib lub davhlau ya nyob twg thiab ua raws cov lus txib hauv qab no: $ sudo apt-get install python-rpi.gpio python3-rpi.gpioto initialize GPIO ports ntawm Raspberry Pi peb xav tau ntshuam lub tsev qiv ntawv Python, tom qab ntawd peb yuav tsum tau pib lub tsev qiv ntawv thiab teeb tsa tus pin 8 raws li tus pin tso tawm ntawm Raspberry pi.import RPi. GPIO li GPIO # Ntshuam Raspberry Pi GPIO lub tsev qiv ntawv los ntawm lub sijhawm ntshuam pw tsaug zog # Ntshuam pw tsaug zog los ntawm lub sijhawm moduleGPIO. setwarnings (Cuav) # Tsis quav ntsej ceeb toom rau tam sim no GPIO.setmode (GPIO. BOARD) # Siv tus lej tus lej tus lej GPIO.setup (8, GPIO. OUT, pib = GPIO. LOW) # Teeb tus pin 8 los ua tus pin tso tawm thiab teeb tus nqi pib rau qis (tawm) Qhov tom ntej peb yuav tsum tau ua yog ua tus pin 8 siab (rau) rau ib pliag thiab qis (tawm) rau ib pliag thiab peb yuav muab nws tso rau hauv lub voj ib ntus kom nws yuav ntsais ib txhis. # Khiav mus tas li GPIO.output (8, GPIO. HIGH) # Qhib pw tsaug zog (1) # Pw tsaug zog rau 1 thib ob GPIO.output (8, GPIO. LOW) # Tua tsaug zog (1) # Pw tsaug zog rau 1 vib nas this Ua ke ob ntu saum toj no ntawm cov lej ua ke thiab tsim cov lej tiav: ntshuam RPi. GPIO li GPIO # Ntshuam Raspberry Pi GPIO lub tsev qiv ntawv los ntawm lub sijhawm ntshuam pw tsaug zog # Ntshuam pw tsaug zog los ntawm lub sijhawm moduleGPIO.setwarnings (Tsis raug) # Tsis quav ntsej ceeb toom rau nowGPIO.setmode (GPIO. BOARD) # Siv tus lej tus lej tus lej GPIO.setup (8, GPIO. OUT, pib = GPIO. LOW) # Teeb tus pin 8 los ua tus pin tso tawm thiab teeb tsa tus nqi pib rau qis (tawm) thaum Muaj Tseeb: # Khiav mus tas li GPIO.output (8, GPIO. HIGH) # Qhib pw tsaug zog (1) # Pw tsaug zog rau 1 thib ob GPIO.output (8, GPIO. LOW) # Tua tsaug zog (1) # Pw tsaug zog rau 1 thib ob Yog li peb txoj haujlwm tau ua tiav, tom qab ntawd peb yuav tsum khaws nws li blinking_led.py thiab tom qab ntawd khiav nws sab hauv koj li IDE lossis hauv koj lub console nrog cov hauv qab no: $ python blinking_led.py

Kauj ruam 4: LED ntsais

LED ntsais
LED ntsais
LED ntsais
LED ntsais

Tom qab khiav cov cai koj yuav pom koj LED Blinking li kuv.so kuv vam tias cov lus qhia no tuaj yeem pab koj yog li qhia rau kuv paub txog qhov ntawd hauv cov lus.

Pom zoo: