Cov txheej txheem:

Disco-pi: 8 Kauj Ruam (nrog Duab)
Disco-pi: 8 Kauj Ruam (nrog Duab)

Video: Disco-pi: 8 Kauj Ruam (nrog Duab)

Video: Disco-pi: 8 Kauj Ruam (nrog Duab)
Video: leej twg tej ntxhai - Mang Vang [ Official MV ] 2024, Hlis ntuj nqeg
Anonim
Disco-pib
Disco-pib

Cov lus qhia no qhia yuav siv Raspberry Pi li cas los tswj cov xim LED xim, raws cov nkauj ua los ntawm lub vev xaib.

Nws qhia txog yuav tsim lub vev xaib yooj yim siv Node.js dhau HTTPS thiab siv socket.io hla WSS (Ruaj Ntseg Websocket).

Lub vev xaib muaj ib nplooj ntawv nkaus xwb uas muaj txheej txheem yooj yim heev. Lub vev xaib nthuav tawm cov npe teev cia nrog cov nkauj suab paj nruag, uas nyob hauv cov pej xeem/suab nplaub tshev ntawm tus neeg rau zaub mov. Xaiv qhov kev xaiv hauv daim ntawv teev cov nkauj ua suab paj nruag hauv lub vev xaib siv HTML 5 lub suab. Thaum ua cov nkauj cov ntaub ntawv, lub vev xaib siv AudioContext interface los tshuaj xyuas lub suab nkauj, uas tom qab ntawd xa mus rau tus neeg rau zaub mov hla kev nyab xeeb websocket txuas.

Tus neeg rau zaub mov khiav ntawm Raspberry Pi siv Node RPI WS281x Native library (qhwv Jeremy Garff's WS281X lub tsev qiv ntawv) los hloov cov xim ntawm LEDs ntawm WS2811 LED sawb, raws li cov ntaub ntawv xa los ntawm lub websocket.

Cov piv txwv tus lej tuaj yeem pom ntawm no: disco-pi

Kauj Ruam 1: Cov Khoom Siv

  1. Raspberry Pi - Kuv siv Raspberry Pi 2B uas kuv tau tso ncig, tab sis koj tuaj yeem tau txais Raspberry Pi 3 Starter Kit rau ib puag ncig CAD 100
  2. WS2811 LED Sawb - Kuv tau ua si nrog ALITOVE 16.4ft 150 Pixels WS2811. Qhov no los nrog tus tswj thiab lub zog xa khoom txog li CAD 45-50
  3. Barrel Jack Connector - Kuv yuav ib qho los ntawm kuv lub khw hluav taws xob hauv ib cheeb tsam, qee yam zoo li no. Tsuas yog xyuas kom tseeb tias haum rau koj lub zog siv
  4. Jumper Connectors / Wire - Kuv muaj qee tus Poj Niam rau Txiv neej txuas cov xov hluav taws xob thiab qee 22 Gauge Cov khoom sib txuas tau xaim dag ib puag ncig

Kauj Ruam 2: Teeb Kho Raspberry Pi

Operating System

Kuv ib txwm siv qhov tseeb Raspbian tsim. Rub tawm daim duab thiab sau rau SD Card. Yog tias koj siv lub khoos phis tawj Windows, koj tuaj yeem siv Win32 Disk Imager los sau cov duab rau SD Card.

Node.js

Nruab qhov hloov tshiab kawg ntawm Node.js. Thaum lub sijhawm sau ntawv Kuv siv 8.9.1

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E tsoo -

sudo apt-tau nruab nodejs

Nruab git

sudo apt-tau nruab git

Kauj Ruam 3: Teeb Tus Qauv Piv Txwv

Clone tus qauv piv txwv

1. Teeb tsa daim ntawv tais ceev tseg rau nruab rau hauv

cd /opt ua

sudo mkdir com.jonhaydock sudo chown pi: pi com.jonhaydockcd com.jonhaydock

2. Clone piv txwv git repository

git clone https://github.com/haydockjp/disco-pi.git"

los yog

git clone [email protected]: haydockjp/disco-pi.git

3. Nruab qhov kev cia siab

cd disco-pib

npm nruab

Qhov no yuav siv sijhawm li 2-3 feeb

Kauj Ruam 4: Tsim Tus Kheej Kos Npe SSL Daim Ntawv Pov Thawj

1. Tsim cov ntaub ntawv tseem ceeb ntiag tug

cd /opt/com.jonhaydock/disco-pi/certs

openssl genrsa-tawm disco-pi-key.pem 2048

2. Tsim CSR (Daim Ntawv Pom Zoo Kos Npe)

openssl req -new -key disco-pi-key.pem -out disco-pi-csr.pem

Txij ntawm no mus koj yuav tau txais kev ceeb toom rau qee cov ntaub ntawv rau daim ntawv pov thawj thov. Raws li qhov no yog daim ntawv pov thawj tus kheej, nws yog nyob ntawm koj li cas koj thiaj li ua tau raws cov ntsiab lus. Nov yog qhov piv txwv

Lub Tebchaws Lub Npe (2 tsab ntawv code) [AU]: CA

Lub Xeev lossis Xeev Lub Npe (lub npe tag nrho) [Qee Lub Xeem]: British Columbia Lub Zos Lub Npe (piv txwv li, lub nroog) : Lub Koom Haum Vancouver Lub Npe (piv txwv li, tuam txhab) [Internet Widgits Pty Ltd]: Disco Pi Lub Koom Haum Lub Npe Lub Npe (piv txwv li, ntu) : Common Name (eg server FQDN or YOUR name) : disco-pi Email Address : [email protected] A lo lus zais nyuaj : Xaiv lub tuam txhab npe :

Hauv qhov ua piv txwv no, tsuas yog nias rov qab los kom tsis txhob muaj lo lus zais nyuaj

3. Tsim daim ntawv pov thawj

openssl x509 -req -days 1095 -in disco-pi-csr.pem -signkey disco-pi-key.pem -out disco-pi-cert.pem

4. Kom muaj kev nyab xeeb ntxiv peb tseem yuav tsim cov ntawv Diffie Hellman Parameters

openssl dhparam -out dh_2048.pem 2048

Qhov no tuaj yeem siv sijhawm 15-20 feeb

Kauj Ruam 5: Txuas Cov Khoom Kho Vajtse

Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse

Ua kom muaj zog ntawm LED sawb

LED sawb yog siv los ntawm 12 volts. Raspberry Pi tsuas yog muaj peev xwm ntawm kev tso tawm 3.3v lossis 5v thiab tsis muaj peev xwm tso tawm txhua qhov chaw ze ntawm amps xav tau los tsav ntau lub LEDs.

Nws yog ib qho tseem ceeb kom tsis txhob txuas lub 12 volt fais fab mov rau Raspberry Pi.

Kuv txoj hlua tseem muaj cov xov hlau txuas ntxiv txuas rau kab txaij ntawm ob sab. Kuv hais qhia tias koj kaw cov ntawv no kom lawv tsis txhob sib cuag nrog koj lwm yam cuab yeej.

Ua cov kauj ruam tom ntej ntawm koj tus kheej txoj kev pheej hmoo. Kuv tsis muaj lub luag haujlwm rau txhua yam uas tuaj yeem ua tsis raug.

LED Sawb

Kuv cov hlua LED muaj peb lub xov hlau:

RED - +12 Volts

BLACK - Hauv av

GREEN - Cov ntaub ntawv

NCO TSEG: muaj Din thiab Dout - Cov Ntaub Ntawv Hauv thiab Cov Ntaub Ntawv Tawm. Ua kom ntseeg tau tias koj tab tom ua haujlwm nrog qhov kawg ntawm kab txaij LED uas hais tias Din.

Ua kom ntseeg tau tias Barrel Jack tsis txuas nrog lub hwj chim

1. Txuas Cov Hluav Taws Xob liab los ntawm cov hlua LED mus rau + sab ntawm Barrel Jack.

Kuv tau siv lub ntsuas 22 dawb txuas rau xaim.

Muab cov xaim tso rau hauv + lub qhov nyob rau hauv lub tog raj kheej thiab ntsia hlau rau hauv qhov chaw.

Thawb lwm qhov kawg ntawm xaim mus rau lub qhov (socket) ntawm LED. Xyuas kom koj txuas nrog xaim liab.

2. Txuas Tus Hlau Dub los ntawm cov hlua LED mus rau - sab ntawm Barrel Jack.

Kuv siv tus dub 22 gauge nqes hlau.

Muab cov xaim tso rau hauv - lub qhov nyob rau hauv lub tog raj kheej. Lub sijhawm no tseem tso tus txiv neej kawg ntawm ib qho ntawm cov txuas txuas (cov xim daj hauv daim duab) rau hauv tib lub qhov thiab ntsia lawv ob qho tib si.

Thawb lwm qhov kawg ntawm cov xaim dub rau hauv lub qhov (socket) ntawm LED.

Xyuas kom koj txuas nrog cov xaim dub.

3. Txuas cov xaim ntsuab los ntawm cov hlua LED

Nqa ib qho ntawm tus poj niam rau txiv neej txuas cov xov hluav taws xob. Hauv kuv cov duab no yog xaim ntsuab.

Muab tus txiv neej kawg tso rau hauv lub qhov (socket) LED nrog cov xaim ntsuab.

Qhov no yog cov ntaub ntawv cable.

Raspberry Pi

1. Nqa cov kab txuas ntsuab thiab txuas nws mus rau Raspberry Pi GPIO.

Koj yuav tsum txuas nws mus rau PCM_CLK (Pin 12 / GPIO 18)

2. Siv tus xov tooj txuas dub thiab txuas nws mus rau Raspberry Pi GPIO.

Koj yuav tsum txuas nws mus rau ib qho ntawm thaj chaw. Kuv qhia koj siv tus pin 14, tab sis koj kuj tseem tuaj yeem siv tus pin 6, 9, 20, 25, 30, 34 lossis 39.

NCO TSEG: rau qhov no los ua haujlwm LED cov khoom siv hluav taws xob thiab Raspberry Pi yuav tsum muaj ib qho hauv paus. Tseem nco ntsoov tias koj yuav tsum tsis txhob txuas 12 Volt + (Red wire) mus rau Raspberry Pi.

LED Hwj chim

Koj yuav tsum tsis muaj peev xwm txuas koj li 12 volt fais fab mov rau lub tog raj

Tag nrho cov LEDs ntawm koj daim kab xev LED yuav tsum tam sim no pom kev dawb

Kauj Ruam 6: Tus Neeg Siv Khoom Sab Nraud

Khiav tus neeg rau zaub mov sab chaws

cd /opt/com.jonhaydock/disco-pi

sudo npm pib

Qhov no yuav pib lub vev xaib thiab pib mloog rau HTTPS thiab WSS thov.

Qhov chaw nres nkoj pib yog 443, tab sis koj tuaj yeem hla qhov no los ntawm kev teeb tsa ib puag ncig sib txawv ua ntej pib qhov chaws. Piv txwv

export DISCO_PI_PORT = 1443

Kuv cov hlua LED muaj 150 LEDs. Cov no tau tswj hwm hauv pab pawg thib peb. Qhov no txhais tau tias kuv tsis tuaj yeem tswj hwm txhua tus LED ib tus zuj zus, thiab kuv yuav tsum xa los ntawm cov ntaub ntawv txaus los tswj 50.

Yog tias koj cov LED muaj ntau dua lossis tsawg dua koj tuaj yeem hla tus lej ntawm LEDs uas koj tab tom tswj hwm los ntawm kev dhau qhov ntsuas mus rau qhov pib. Piv txwv li, yog tias koj tuaj yeem tswj tau 10 LEDs xwb

sudo npm pib 10

Tus lej server tseem ceeb tuaj yeem pom hauv app.js file. Cov ntaub ntawv no pib HTTPS web server thiab tseem ntxiv rau socket.io mloog rau websocket thov ntawm tib lub chaw nres nkoj.

Txhawm rau nkag mus rau lub vev xaib, koj yuav tsum qhib lub vev xaib ntawm koj lub khoos phis tawj loj (Kuv tsuas tau sim qhov no hauv Chrome) thiab siv IP chaw nyob ntawm Raspberry Pi, piv txwv li.

10.0.1.2/

Koj tuaj yeem paub koj tus IP chaw nyob los ntawm kab lus Raspberry Pi.

ifconfig

Lub webserver yuav ua haujlwm ib qho ntsiab lus hauv qab daim nplaub tshev pej xeem. Nws tsis zoo los tso saib nplooj ntawv index.html.

Nws muaj ib qho API kawg taw tes - /api /audio. Qhov kawg ntawm qhov no saib rau txhua cov ntaub ntawv hauv qab cov ntawv pej xeem/suab thiab xa cov npe rov qab. Piv txwv

["GYAKO.mp3", "Havana (feat. Young Thug).mp3", "Queen_Bohemian_Rhapsody.mp3", "Set It All Free.mp3", "This Is What You Came For (feat. Rihanna).mp3"]

Txhawm rau ntxiv cov nkauj raws li kev xaiv, luam cov ntawv rau daim nplaub tshev no. Kuv tus kheej siv Filezilla hla ssh. Lub nplaub tshev uas koj xav ntxiv cov ntawv rau yog /opt/com.jonhaydock/disco-pi/public/audio

Kauj Ruam 7: Website Code

Website Code
Website Code

Thaum koj tsoo lub vev xaib koj yuav tsum pom qee yam zoo li no.

Yog tias koj pom kev ceeb toom kev nyab xeeb qhov no yog vim peb tab tom siv tus kheej-kos npe SSL daim ntawv pov thawj. Koj tuaj yeem tsis quav ntsej nws lossis ntxiv nws ua kev zam.

Ntawm kev xaiv lub npe cov ntaub ntawv, lub hauv paus rau HTML 5 lub suab. yuav raug teeb tsa rau cov ntawv ntawd. Thaum npaj txhij, lub suab paj nruag yuav pib ua si. Thaum cov nkauj tau ua tiav cov nkauj yuav nres.

Yog tias koj xaiv None xaiv, lub suab paj nruag yuav tsum nres.

Thaum ua cov nkauj cov ntaub ntawv, lub vev xaib siv AudioContext interface los tshuaj xyuas lub suab nkauj, uas tom qab ntawd xa mus rau tus neeg rau zaub mov hla kev nyab xeeb websocket txuas.

Cov lus yog hom uas socket.io ntawm server tau teeb tsa los mloog rau "ws2811". Nws muaj cov kab ntawm 50 lub ntsiab lus, uas yog nruab nrab ntawm 0 thiab 255.

"ws2811", {"0": 251, "1": 252, "2": 241, "3": 217, "4": 193, "5": 164, "6": 148, "7": 139, "8": 110, "9": 96, "10": 81, "11": 67, "12": 72, "13": 66, "14": 60, "15": 60, "16": 63, "17": 54, "18": 37, "19": 30, "20": 31, "21": 26, "22": 13, "23": 3, " 24 ": 10," 25 ": 7," 26 ": 6," 27 ": 0," 28 ": 0," 29 ": 0," 30 ": 1," 31 ": 8," 32 ": 12, "33": 3, "34": 2, "35": 2, "36": 0, "37": 0, "38": 0, "39": 0, "40": 0, "41": 0, "42": 0, "43": 0, "44": 0, "45": 0, "46": 0, "47": 0, "48": 0, " 49 ": 0 hli

Tus neeg rau zaub mov siv Node RPI WS281x Native library (qhwv Jeremy Garff's WS281X lub tsev qiv ntawv) los hloov cov xim ntawm LEDs ntawm WS2811 LED sawb, raws li cov ntaub ntawv xa los ntawm lub websocket.

Kauj ruam 8: Thaum kawg

Image
Image

Koj yuav tsum pom cov LEDs ntawm kab txaij hloov xim nrog lub suab nkauj, raws li Fast Fourier Transform tsom xam ua tiav hauv lub vev xaib.

Kuv vam tias koj txaus siab rau qhov no. Qhia rau kuv paub tias koj ua dab tsi nrog nws!

NCO TSEG: Yog tias koj muaj teeb meem

Txij li lub tsev qiv ntawv no thiab onboard Raspberry Pi audioboth siv PWM, lawv tsis tuaj yeem siv ua ke.

Koj yuav xav tau blacklist Broadcom audio kernel module los ntawm kev tsim cov ntaub ntawv /etc/modprobe.d/snd-blacklist.conf nrog

npe dub snd_bcm2835

Yog tias lub cuab yeej suab tseem tab tom thauj khoom tom qab sau npe dub, koj kuj tseem yuav xav tawm nws tawm hauv /etc /modules file. Ntawm lub tshuab tsis muaj lub taub hau koj kuj tseem yuav xav yuam lub suab los ntawm hdmi

Kho kom raug config.txt thiab ntxiv:

hdmi_force_hotplug = 1

hdmi_force_edid_audio = 1

Yuav tsum tau rov pib dua rau qhov kev hloov pauv no kom siv tau

Pom zoo: