Cov txheej txheem:

Dog Mood Detector (Raspberry Pi): 5 Kauj Ruam
Dog Mood Detector (Raspberry Pi): 5 Kauj Ruam

Video: Dog Mood Detector (Raspberry Pi): 5 Kauj Ruam

Video: Dog Mood Detector (Raspberry Pi): 5 Kauj Ruam
Video: doubling the drop every time the PC survives #shorts 2024, Kaum ib hlis
Anonim
Dog Mood Detector (Raspberry Pi)
Dog Mood Detector (Raspberry Pi)

Cov Lus Qhia no yog tsim los coj lub suab uas tus dev ua thiab txiav txim siab tias lawv yuav tsum tau mus txog lossis tsis nrog qhov taw qhia LED. Cov tswv dev feem ntau paub lawv cov tsiaj thiab tuaj yeem nyeem cov cim qhia tias lawv muab tawm yog li Cov Lus Qhia no feem ntau yog qhia rau cov neeg tsis paub uas tuaj yeem ntsib nrog koj tus dev.

Kauj Ruam 1: Qhov Chaw

Qhov
Qhov
Qhov
Qhov
Qhov
Qhov

Koj yuav xav tau:

  • Raspberry Pi
  • Liab/Ntsuab LEDs (X2)
  • Saib xyuas
  • Keyboard/nas nrog USB
  • WiFi Dongle
  • Sab nraud USB Microphone
  • 330 ohm Resistor (X2)

Yeem Yam

  • Sab Nraud Raspberry Pi Fais Fab Khoom
  • Aub dab tshos

Kauj ruam 2: Txheej txheem

Txheej txheem
Txheej txheem

Thawj kauj ruam los pib txoj haujlwm no yog tshuaj xyuas tus cwj pwm thiab tus qauv cuam tshuam nrog koj tus dev. Koj tuaj yeem nyem HERE rau cov lus qhia yooj yim ntawm yam koj yuav tsum tau nrhiav. Hauv kuv qhov xwm txheej, kuv tus dev quaj thaum twg nws zoo siab lossis zoo siab pom ib tus neeg thiab tawv tawv sib quas ntus thaum tshee lossis hnyav. Hauv ob peb kauj ruam tom ntej no kuv yuav piav qhia yuav hloov kho kuv li program li cas kom haum rau tus cwj pwm ntawm koj tus dev.

Kauj ruam 3: Programming

Programming
Programming

Hauv qab no yog Python program kuv siv rau kuv tus dev. Hauv theem tom ntej no kuv yuav piav qhia yuav hloov kho qhov program rau koj tus dev li cas tus cwj pwm. Tsis txhob khiav qhov program tsuas yog vim nws yuav tsis ua haujlwm kom txog thaum koj ua cov kauj ruam tom ntej.

#!.

qog = 0

howl = Cuav tuav = 0 barkLength = 5 ncua = 0 tos = 2 chij = 0 liab = 7 ntsuab = 5 tawmFlag = tsis tseeb

def toggleLightRed (c): cov

GPIO.setmode (GPIO. BOARD) GPIO.setup (liab, GPIO. OUT) GPIO.output (c, Tseeb) pw (10) GPIO.output (c, Cuav) luam tawm ("Liab toggled")

def toggleLightGreen (c):

GPIO.setmode (GPIO. BOARD) GPIO.setup (ntsuab, GPIO. OUT) GPIO.output (c, Tseeb) pw (10) GPIO.output (c, Cuav) luam tawm ("Green toggled")

def lub ntsiab ():

ntiaj teb tawv thoob ntiaj teb quaj nrov thoob ntiaj teb tuav ntiaj teb tawvLeng ntiaj teb ncua ntiaj teb chij ntiaj teb liab ntiaj teb ntsuab

ua: 8192

FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 threshold = 3000 max_value = 0 p = pyaudio. PyAudio () kwj = p.open (format = FORMAT, raws = CHANNELS, tus nqi = RATE, input = True, output = True, frames_per_buffer = thooj) GPIO.setmode (GPIO. BOARD) GPIO.setup (liab, GPIO. OUT) GPIO.setup (ntsuab, GPIO. OUT) sim: luam "Tshawb nrhiav pib" thaum Muaj tseeb: sim: data = stream.read (thunk) tshwj tsis yog IOError li ex: yog ex [1]! = pyaudio.paInputOverflowed: nce cov ntaub ntawv = '\ x000' * chunk as_ints = array ('h', cov ntaub ntawv) max_value = max (as_ints) thaum max_value> threshold: ncua = 0 tuav = tuav+1 sim: data = stream.read (thooj) tshwj tsis yog IOError raws li ex: yog ex [1]! = Pyaudio.paInputOverflowed: nce cov ntaub ntawv = '\ 00' * chunk as_ints = array ('h', cov ntaub ntawv) max_value = max (as_ints) yog tuav> = barkLength: howl = True print "HOWL DETECTED" toggleLightGreen (ntsuab) GPIO.cleanup () elif tuav> 0 thiab tuav

yog _name_ == '_main_':

lub ntsiab ()

Kauj Ruam 4: Teeb meem thiab hloov kho

Teeb meem thiab hloov kho
Teeb meem thiab hloov kho
Teeb meem thiab hloov kho
Teeb meem thiab hloov kho
Teeb meem thiab hloov kho
Teeb meem thiab hloov kho

Teeb

Ua ntej koj pib qhov program koj yuav tsum tau ntaus cov hauv qab no rau hauv Terminal rau nruab PyAudio:

sudo apt-tau intall nab hab sej-pyaudio

Tom qab qhov no koj tuaj yeem sim-khiav qhov haujlwm kom paub tseeb tias nws ua haujlwm tau zoo.

Teeb meem

Koj yuav ntsib qhov yuam kev hauv qab no:

IOError: [Errno Input overflowed] -9981

Txhawm rau kho qhov no, tsuas yog nce tus lej uas tau muab rau hauv qhov sib txawv kom txog thaum qhov yuam kev tsis tshwm sim ntxiv lawm.

Hloov kho

Qhov sib txawv ntawm barkLength hais txog tus naj npawb ntawm lub sijhawm uas lub program loops ua ntej lub suab nrov tsis pom dua li cov tawv ntoo, tab sis zoo li quaj. Yog tias koj cov dev quaj tab sis ua li ntawd tsuas yog tawg ntho xwb koj yuav tsum txo tus lej no.

Qhov hloov pauv liab thiab ntsuab hais txog cov chaw nres nkoj tso tawm uas yuav siv rau qhov ntsuas LED. Cov no tuaj yeem hloov pauv kom haum rau koj cov kev xav tau.

Txawm hais tias kuv tsis siv qhov kev hloov pauv qeeb qeeb hauv kuv qhov haujlwm, nws tuaj yeem pom los qhia qhov zaus ntawm cov tawv ntoo lossis yws.

Qhov sib txawv tuav yog hais txog pes tsawg zaus qhov kev zov me nyuam cuam tshuam qhov uas lub suab nrov tau siab dua qhov pib thiab siv los txiav txim siab yog tias muaj kev quaj. Qhov kev hloov pauv no yuav tsum tsis raug hloov pauv txhua txoj hauv kev raws li kev quaj qw tau pom los ntawm kev ua haujlwm ntawm barkLength sib txawv.

Qhov sib txawv ntawm qhov pib tuaj yeem qis dua yog tias cov tawv ntoo tsis nrov nrov lossis nce siab yog tias muaj lub suab nrov tom qab uas tuaj yeem txhais tsis raug raws li lub suab nrov los ntawm tus dev.

Kauj ruam 5: Kho vajtse

Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse
Kho vajtse

Nws yog nyob rau lub sijhawm no uas koj yuav tsum muaj txoj haujlwm ua haujlwm tau zoo uas nthuav tawm mus rau lub vijtsam yam khoom kho vajtse yuav ua. Lub ntsiab lus hauv qhov haujlwm no yog qhov uas koj yuav tsum txiav txim siab seb qhov no yuav yog lub microphone nyob ruaj ruaj uas tau teeb tsa hauv ib qho (piv txwv li ib qho chaw hauv tsev uas tus dev nquag nquag lossis cuam tshuam nrog cov neeg tuaj saib) lossis yog tias qhov haujlwm no yuav txo qis. thiab txuas nrog tus dev lub dab tshis kom muab cov lus tawm tam sim rau tus neeg cuam tshuam nrog tus dev.

Nyob ruaj ruaj

Qhov yooj yim tshaj plaws yog ua txhua yam tawm ntawm lub khob cij vim tias yuav tsis muaj kev txav chaw uas tuaj yeem tshem cov xov hlau. Txuas cov cathodes ntawm Liab LEDs rau hauv av pin ntawm Raspberry Pi thiab Anodes ib qho dhau los ntawm 330 ohm resistor lossis ncaj qha rau tus pin 7 ntawm Raspberry Pi. Ua tib yam nrog Green LEDs tab sis txuas Anodes rau tus pin 5. Khiav qhov program thiab koj yuav tsum tau ua tiav txoj haujlwm ib zaug koj tau hloov kho cov cai rau koj xav tau.

Tsis nyob ruaj khov

Kuv xav kom ua tiav daim ntawv nyob ruaj khov ua ntej tsuas yog kom ntseeg tau tias txhua yam ua haujlwm thiab tom qab ntawd txav mus los ntawm qhov ntawd los ntawm kev sib txuas ua ke txhua yam kom tsis muaj xov hlau yuav tsis txuas nrog los ntawm tus dev lub zog.

Txuas cov LEDs rau lub dab tshos kom lawv ob leeg nyob hauv txoj haujlwm yooj yim thiab tuaj yeem pom los ntawm ib tus neeg thaum lawv mus txog.

Tom ntej txuas koj lub zog hluav taws xob sab nraud xws li ib qho pom ntawm no mus rau raspberry pi thiab ruaj ntseg nws rau dab tshos raws li qhov yooj yim rau tus dev.

Thaum txhua yam muaj kev nyab xeeb hauv qhov chaw mus tom ntej thiab ua haujlwm, txuas lub dab tshos rau tus dev, thiab koj ua tiav!

Pom zoo: