Cov txheej txheem:

Ib-khawm Xov Tooj Cua Tshaj Tawm: 7 Cov Kauj Ruam (nrog Duab)
Ib-khawm Xov Tooj Cua Tshaj Tawm: 7 Cov Kauj Ruam (nrog Duab)

Video: Ib-khawm Xov Tooj Cua Tshaj Tawm: 7 Cov Kauj Ruam (nrog Duab)

Video: Ib-khawm Xov Tooj Cua Tshaj Tawm: 7 Cov Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Ib-khawm Xov Tooj Cua Tshaj Tawm
Ib-khawm Xov Tooj Cua Tshaj Tawm

Kuv tau tsim ib lub thawv rau kuv tus phooj ywg lub bar uas muaj Raspberry Pi sab hauv thiab nrog thawb ntawm ib lub pob nws ntws suab mus rau lub vev xaib siv Darkice thiab Icecast, thaum tib lub sijhawm teeb pom kev 'On-Air' kos npe. Kuv xav tias qhov no yog qee yam uas tib neeg twb tau ua tab sis tom qab tshawb nrhiav dav dav kuv tsis pom dab tsi thiab txiav txim siab los txheeb xyuas nws rau kuv tus kheej thiab ua qhov qhia no.

Kuv siv Raspberry Pi 3+ B tab sis raws li kuv tuaj yeem qhia nws yuav ua haujlwm ntawm ib qho Pi (tej zaum GPIO tus lej tus lej yuav txawv, kuv tsis tuaj yeem lees paub qhov ntawd). Kuv siv lub pob NOOBS rau OS thiab yuav lub suab yooj yim super rau cov tswv yim. Kuv kuj tau ntxiv lub khawm kaw zoo thiab ua haujlwm LED rau hauv lub thawv los tiv thaiv Pi.

Koj yuav xav tau:

Raspberry Pi

NOOBS pob ntawm daim npav SD

On/Off hloov (Kuv tau siv lub khawm liab liab thaum muaj xwm txheej loj li no, tab sis nws tuaj yeem yog yam 'nyem' hloov)

Laub Khawm

1 LED

Ib qho 'On-Air' kos npe, Kuv tau ua kuv tus kheej nrog LED teeb

Soldering hlau thiab cov txuas me me-board (Kuv tsuas yog txiav ib qho tawm ntawm ib qho ntawm cov uas kuv tau nyob ib puag ncig)

Soundcard (Kuv siv qhov yooj yim super zoo li qhov no)

Kauj Ruam 1: Teeb tsa Koj Lub Server

Txog qhov chaw nres tsheb hauv xov tooj cua tiag tiag peb tab tom siv Kuv tsis tau ua ntu no vim kuv tsis tau nkag mus rau server thiab kuv tus phooj ywg tau ua nws, tab sis muaj cov txheej txheem teeb tsa yooj yim ntawm Icecast lub vev xaib thiab kuv tau tswj kom tau txais nws ua haujlwm los ntawm Pi thaum pib tsuas yog pom tias nws mus li cas. Xwb, koj tuaj yeem tau txais tus as khauj ntawm internet-radio.com thiab nws ua haujlwm nrog Darkice.

Kauj Ruam 2: Teeb tsa Pi thiab Nruab Darkice

Tau txais daim npav SD nrog pob NOOBS. Thaum koj tau qhib Raspbian thiab teeb tsa txhua qhov hloov tshiab qhib lub Terminal qhov rai thiab ntaus:

sudo apt-tau hloov tshiab

sudo apt-tau nruab darkice

Darkice yog ib feem ntawm Debian yog li nws yuav nruab cia, nws yuav siv sijhawm me ntsis.

Thaum nws ua tiav ntawm hom kev hais kom sai:

tsaus

Nws yuav muab cov lus yuam kev thiab tsis ua haujlwm, tab sis qhov ntawd zoo. Hauv cov lus nws yuav hais qee yam xws li:

Siv cov ntaub ntawv teeb tsa: /etc/darkice.cfg

Koj yuav tsum tau kho cov ntaub ntawv ntawd, yog li ntawm hom sai:

sudo nano /etc/darkice.cfg

Kho cov ntaub ntawv uas qhib siv cov ntaub ntawv ntawm nplooj ntawv wiki. Radioreference, thaum koj ua tiav nias CTRL-X kom kaw, Y kom txuag thiab koj yuav tsum rov qab mus rau Terminal kom sai. Nws ib txwm zoo rau rov pib dua tom qab txhim kho qhov haujlwm tshiab yog li ntaus:

rov pib dua

thiab thaum Pi tau rov pib dua rov qhib lub Terminal qhov rai. Tam sim no thaum koj ntaus 'Darkice' nws yuav tsum khiav yam tsis muaj lus yuam kev. Yog tias koj mus rau https:// YOURSERVERADDRESS: 8000/(8000 lossis qhov twg qhov chaw nres nkoj koj tus neeg rau zaub mov icecast tau muab rau) koj yuav tsum tau txais nplooj ntawv txheeb cais hais tias koj tau txuas nrog. Yog tias tsis yog, hloov kho cov ntaub ntawv teeb tsa (kab lus tawm suab tau muab qee yam teeb meem rau kuv tab sis kuv tau sim txhua qhov kev xaiv thiab thaum kawg pom kuv daim npav suab). Thaum Darkice tau ua haujlwm kom raug txav mus rau qib tom ntej.

Kauj Ruam 3: Khawm Khawm thiab On-Air Sign

Khawm Khawm thiab On-Air Sign
Khawm Khawm thiab On-Air Sign

Kuv tau ua ntau qhov kev qhia sib txawv rau qhov no vim tias tsis muaj ib qho tshwj xeeb rau kev ua haujlwm rau lub pob hauv Python. Qhov teeb meem loj tshaj plaws uas kuv tau ntsib yog tau txais Darkice los khiav hauv keeb kwm yav dhau (thiab yog li tsis khov tsab ntawv Python thaum nws pib ua haujlwm) tab sis kuv nug tus phooj ywg coder kom tuaj thiab pab thiab nws tau nrhiav txoj hauv kev los ua nws sau ntawv, qee yam kuv tsis tau. Thaj nws kuj tseem tuaj yeem siv tau '&' qhov chaw nyob hauv txoj cai tab sis kuv tsis muaj tus coder thiab qhov kuv tau ua haujlwm yog li kuv tau xaiv tsis txhob cuam tshuam nrog nws. Thaum kuv muaj txhua yam ua haujlwm Kuv pib txhuam tag nrho cov kab hluav taws xob los ntawm lub khob cij kom txog thaum kuv tau tso nrog cov teeb tsa hauv qab no:

GPIO16 rau sab nraud 3-point txuas.

GPIO7 mus rau lub davhlau ya nyob twg zoo ntawm LED teeb rau ON-Air kos npe.

GPIO25 mus rau qhov hloov pauv nyem.

Lwm sab ntawm qhov nyem-hloov txuas rau 3-point txuas.

Lub davhlau ya nyob twg tsis zoo ntawm LED teeb kuj tseem txuas rau 3-point txuas.

(Lwm yam khoom ntawm daim duab tau piav qhia hauv theem tom ntej).

Python tsab ntawv uas peb tau xaus nrog yog raws li hauv qab no (thov nco ntsoov qhov no yog Cov Lus Qhia rau tag nrho txoj haujlwm, Kuv tsis paub tiag tiag txaus los piav qhia txoj cai. Kuv muab nws ua ke los ntawm ntau lwm yam kev qhia rau kev ua haujlwm sib txawv):

ntshuam lub sij hawm ntshuam os import RPi. GPIO li GPIO GPIO.setwarnings (Cuav) GPIO.setmode (GPIO. BOARD) ledPin = 12 buttonPin = 16 GPIO.setup (ledPin, GPIO. OUT) GPIO.setup (buttonPin, GPIO. IN, pull_up_down = GPIO. PUD_UP)

toggle = tsis tseeb

def pib_darkice ():

print ('hu rau txheej txheem') #result = subprocess.call ('sh screen -S darkice -d -m darkice') os.system ('screen -S darkice -d -m darkice') print ('resuming') def stop_darkice (): os.system ('screen -X -S darkice tawm')

thaum Muaj Tseeb:

buttonState = GPIO.input (buttonPin) yog buttonState == Muaj tseeb: yog tias tsis toggle: toggle = True print ('tig rau darkice') start_darkice () #print ('BUTTON STATE TRUE') GPIO.output (ledPin, GPIO. HIGH)

lwm tus:

yog toggle: toggle = Luam tsis tseeb ('tsum tsum darkice') stop_darkice () #print ('BUTTON STATE FALSE') GPIO.output (ledPin, GPIO. LOW) time.sleep (1)

Cov ntaub ntawv py tau txuas nrog Cov Lus Qhia no, koj tuaj yeem rub tawm nws thiab ua raws Kauj Ruam 5 yog tias koj nyiam.

Kauj Ruam 4: Khawm Kaw Kom Zoo thiab Ua Haujlwm LED

Khawm Kaw Zoo thiab Ua Haujlwm LED
Khawm Kaw Zoo thiab Ua Haujlwm LED

Tsuas yog rau kev nyab xeeb thiab kom lub neej nyob ntev ntawm Pi Kuv ntxiv lub pob kaw zoo thiab ua haujlwm sab nraud LED kom tib neeg paub thaum nws nyab xeeb rau tshem lub thawv. Kuv pom tau yooj yim qhia rau ob qho no, tab sis kuv tau pom tias Raspberry Pi 3 B+ muaj ACT LED muab rau GPIO tus pin thaum cov qauv ua ntej tsis ua thiab uas tuaj yeem muaj teeb meem yog tias koj muaj Pi loj dua.

Txuas lub davhlau ya nyob twg zoo ntawm LED mus rau GPIO13 thiab qhov tsis zoo rau GPIO26. Rau ACT LED ua haujlwm koj yuav tsum hloov kho cov ntaub ntawv config.txt hauv BOOT phau ntawv teev npe. Koj tuaj yeem pom qhov no hauv Raspbian browser lossis nrog:

sudo nano /usr/boot/config.txt

Thaum koj kho cov ntaub ntawv yooj yim ntxiv cov kab hauv qab no:

# Siv sab nrauv LED ua SD ACT LED dtoverlay = pi3-act-led, gpio = 19

Tam sim no sab nraud LED wil flicker nrog SD daim npav ua haujlwm.

Txuas lub laub hloov mus rau GPIO3 thiab GPIO8. Kuv pom cov cai hauv qab no los ntawm kev qhia thiab nws ua haujlwm zoo:

ntshuam sijhawm los ntawm gpiozero ntshuam khawm los ntawm cov txheej txheem ntshuam ntshuam_call los ntawm teeb liab ntshuam ncua

def kaw ():

check_call (['sudo', 'poweroff'])

shutdown_btn = Khawm (2, tuav_time = 1)

shutdown_btn.when_held = kaw

ncua ()

sijhawm.sleep (1)

Cov ntaub ntawv py no tseem txuas rau koj kom rub tawm yog tias koj xav tau. Kuv lub pob yuav tsum tau tuav rau 1 thib ob, yog tias koj xav hloov qhov hloov pauv 'tuav-sijhawm =' tus nqi.

Kauj Ruam 5: Ua kom Python Scripts Run From Boot

Ib zaug ntxiv, muaj ntau qhov kev qhia ntawm cov ncauj lus no, Kuv tau siv qhov no los ntawm Dexter Industries thiab ua raws qib ib los ntawm kev kho cov ntaub ntawv rc.local.

sudo nano /etc/rc.local

Hauv no koj yuav tsum ntxiv cov ntaub ntawv ua tiav-txoj kev mus rau qhov kawg ntawm daim ntawv, ua kom tiav nrog '&' kawg ntawm txhua kab. Koj yuav tsum ntxiv ib kab rau txhua cov ntaub ntawv:

sudo nab hab sej/tsev/pi/YOURFILENAME, py &

sudo nab hab sej /home/pi/YOURFILENAME2.py &

tsuas yog ua ntej kab

ua ex0

Qhov '&' ntawm qhov kawg ntawm txhua kab yog qhov tseem ceeb kom ntseeg tau tias txoj haujlwm loops.

Kauj Ruam 6: Tsim Lub Thawv

Tsim lub Thawv
Tsim lub Thawv
Tsim lub Thawv
Tsim lub Thawv
Tsim lub Thawv
Tsim lub Thawv

Qhov no yog tag nrho rau koj. Nws tsuas yog xav tau qhov loj me ntawm Pi, tab sis kuv muab lub tshuab tso rau hauv kuv qhov teeb tsa kom cov xov tooj cua nyob ntawm qib ncaj ncees ib yam yog li lub thawv loj dua. Kuv muaj lub qhov nyob rau sab xub ntiag rau On-Air kos npe thiab ib qho rau Lub Pob Loj Loj, ntxiv rau kuv tau ua daim ntawv qhia me ntsis rau DJs thiab sau nws hauv qab lub pob. Ntawm sab ntawm lub npov muaj lub qhov rau lub laub khawm, ACT LED thiab lub suab tawm tswv yim, ntxiv rau cov lus qhia rau cov neeg ua haujlwm bar yuav ua li cas thiaj kaw lub thawv kom nyab xeeb.

Kauj Ruam 7: Kev teeb tsa

Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa
Kev teeb tsa

Txhim kho tag nrho cov khoom sib cais rau hauv koj lub npov, nco ntsoov nws yog qhov zoo ib txwm tso cai rau qee qhov huab cua ncig ncig Pi kom tiv thaiv kev kub ntxhov. Txuas cov kab hluav taws xob los ntawm koj lub tov khoom, ntaus lub pob thiab txaus siab rau kev tshaj tawm!

Pom zoo: