Cov txheej txheem:

Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Analogue to Digital Converter): 4 Cov Kauj Ruam
Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Analogue to Digital Converter): 4 Cov Kauj Ruam

Video: Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Analogue to Digital Converter): 4 Cov Kauj Ruam

Video: Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Analogue to Digital Converter): 4 Cov Kauj Ruam
Video: node.js-powered 8-bit CPU - 6309 executing NOPs at 2Hz 2024, Hlis ntuj nqeg
Anonim
Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Sib Piv rau Digital Converter)
Raspberry Pi GPIO Circuits: Siv LDR Analogue Sensor Tsis Muaj ADC (Sib Piv rau Digital Converter)

Hauv peb Cov Kev Qhia Ua Ntej Ua Ntej, peb tau qhia koj li cas koj tuaj yeem txuas koj li Raspberry Pi's GPIO pins rau LEDs thiab hloov pauv thiab GPIO pins tuaj yeem siab lossis qis. Tab sis dab tsi yog tias koj xav siv koj li Raspberry Pi nrog lub ntsuas qhov sib piv?

Yog tias peb xav siv cov ntsuas sib piv nrog Raspberry Pi, peb yuav tsum muaj peev xwm ntsuas qhov tsis kam ntawm lub ntsuas. Tsis zoo li Arduino, Raspberry Pi's GPIO pins tsis tuaj yeem ntsuas qhov tsis kam thiab tuaj yeem nkag siab tau yog tias qhov hluav taws xob muab rau lawv siab dua qee qhov hluav taws xob (kwv yees li 2 volts). Txhawm rau kov yeej qhov teeb meem no, koj tuaj yeem siv Analogue to Digital Converter (ADC), lossis koj tuaj yeem siv tus nqi hluav taws xob pheej yig dua.

Cov Lus Qhia no yuav qhia koj yuav ua li cas thiaj ua tiav qhov no.

Kauj Ruam 1: Yam Koj Yuav Tsum Tau

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

- RaspberryPi nrog Raspbian twb tau teeb tsa. Koj tseem yuav tsum muaj peev xwm nkag tau Pi siv Monitor, Mouse thiab Keyboard lossis los ntawm Remote Desktop. Koj tuaj yeem siv txhua tus qauv ntawm Raspberry Pi. Yog tias koj muaj ib qho ntawm Pi Zero cov qauv, koj yuav xav muab qee lub taub hau txuas rau GPIO chaw nres nkoj.

- Lub Teeb Ntsuas Tus Kheej (Kuj tseem hu ua LDR lossis Photoresistor)

- A 1 uF Ceramic Capacitor

- Ib Lub Cuab Yeej Tsis Txaus Siab Prototyping Breadboard

- Qee tus txiv neej rau poj niam jumper xov hlau

Kauj Ruam 2: Tsim Koj Li Circuit Court

Tsim Koj Li Circuit Court
Tsim Koj Li Circuit Court
Tsim Koj Li Circuit Court
Tsim Koj Li Circuit Court

Ua kom muaj cov kab lus saum toj no ntawm koj daim ntawv qhia zaub mov kom ntseeg tau tias tsis muaj ib feem ntawm cov khoom coj los kov. Lub Teeb Ntsuas Tus Kws Tiv Thaiv thiab Cov Khoom Siv Hluav Taws Xob tsis muaj qhov sib txawv uas txhais tau tias qhov tsis zoo thiab qhov zoo tam sim no tuaj yeem txuas nrog ob qho tib si. Yog li koj tsis tas yuav txhawj xeeb txog txoj kev uas cov khoom siv no tau txuas nrog hauv koj lub Circuit.

Thaum koj tau txheeb xyuas koj lub Circuit Court, txuas lub jumper cables rau koj Raspberry Pi's GPIO pins los ntawm kev ua raws daim duab saum toj no.

Kauj Ruam 3: Tsim kom muaj Python Script los nyeem Lub Teeb Ntsuas Tus Kheej

Tsim kom muaj Python Script los nyeem Lub Teeb Pom Kev Tiv Thaiv
Tsim kom muaj Python Script los nyeem Lub Teeb Pom Kev Tiv Thaiv

Tam sim no peb yuav sau tsab ntawv luv luv uas yuav nyeem thiab nthuav tawm qhov tsis kam ntawm LDR siv Python.

Ntawm koj tus Raspberry Pi, qhib IDLE (Ntawv Qhia> Programming> Python 2 (IDLE)). Qhib ib qhov haujlwm tshiab mus rau File> New File. Tom qab ntawv ntaus (lossis theej thiab muab tshuaj txhuam) cov cai hauv qab no:

ntshuam RPi. GPIO li GPIOimport timempin = 17 tpin = 27 GPIO.setmode (GPIO. BCM) cap = 0.000001 adj = 2.130620985i = 0 t = 0 thaum Tseeb: GPIO.setup (mpin, GPIO. OUT) GPIO.setup (tpin, GPIO. OUT) GPIO.output (mpin, False) GPIO.output (tpin, False) time.sleep (0.2) GPIO.setup (mpin, GPIO. IN) time.sleep (0.2) GPIO.output (tpin, Tseeb)) pib sijhawm = sijhawm. sijhawm () sijhawm kawg = sijhawm. sijhawm () thaum (GPIO.input (mpin) == GPIO. LOW): sijhawm kawg = sijhawm. sijhawm () ntsuas kev tiv thaiv = kawg sijhawm-pib lub sijhawm res = (ntsuas kev tiv thaiv/cap)* adj kuv = kuv+1 t = t+res yog kuv == 10: t = t/kuv luam tawm (t) kuv = 0 t = 0

Txuag koj txoj haujlwm li lightsensor.py (Cov Ntaub Ntawv> Txuag Raws Li) hauv koj cov ntawv tais ceev tseg.

Tam sim no qhib Terminal (Ntawv Qhia> Accessories> Terminal) thiab ntaus cov lus txib hauv qab no:

nab hab sej lightsensor.py

Raspberry Pi yuav rov ua kom pom qhov tsis kam ntawm photoresistor. Yog tias koj tso koj tus ntiv tes hla tus photoresistor, qhov kev tiv thaiv yuav nce ntxiv. Yog tias koj ua lub teeb ci ntsa iab ntawm lub photoresistor, qhov ua haujlwm yuav txo qis. Koj tuaj yeem nres qhov haujlwm no los ntawm kev nias CTRL+Z.

Kauj Ruam 4: Nws Ua Haujlwm Li Cas

Raws li tus capacitor maj mam tsub nqi, qhov hluav taws xob uas dhau los ntawm Circuit Court thiab mus rau GPIO tus pin nce. Thaum lub capacitor raug them rau qee qhov taw tes, nws qhov hluav taws xob nce siab dua 2 volts thiab Raspberry Pi yuav nkag siab tias GPIO tus pin 13 yog HIGH.

Yog tias qhov tsis kam ntawm lub ntsuas hluav taws xob nce ntxiv, lub tshuab hluav taws xob yuav them qeeb dua thiab lub Circuit Court yuav siv sijhawm ntau dua los mus txog 2 volts.

Cov ntawv sau saum toj no tseem ceeb npaum li cas nws yuav siv sij hawm ntev rau tus pin 13 kom tig siab thiab tom qab ntawd siv qhov ntsuas no los xam qhov tsis kam ntawm Photoresistor.

Pom zoo: