Cov txheej txheem:

Xim-pi: 9 Kauj Ruam
Xim-pi: 9 Kauj Ruam

Video: Xim-pi: 9 Kauj Ruam

Video: Xim-pi: 9 Kauj Ruam
Video: Tsis Deev Koj Thiaj Tsis Seev BY Aka 2024, Kaum ib hlis
Anonim
Xim-pib
Xim-pib

Cov lus qhia no qhia yuav siv Raspberry Pi li cas los tswj lub suab RGB LED sawb, los ntawm lub vev xaib, siv Web Speech API Interfaces rau SpeechRecognition thiab SpeechSynthesis.

Qhov piv txwv no qhia yuav ua li cas

  • Tsim lub vev xaib yooj yim siv Node.js hla
  • Siv Web Speech API Interfaces rau SpeechRecognition thiab SpeechSynthesis.
  • Siv Cylon.js lub moj khaum los tswj RGB LED sawb ntawm Raspberry Pi
  • Sib txuas lus dhau WSS (Ruaj Ntseg Lub Vev Xaib) los ntawm nplooj ntawv web rau Cylon.js los tswj cov xim rau LED

Nco tseg

  • Koj yuav xav tau tus neeg hais lus lossis lub mloog pob ntseg kom hnov lub suab hais lus
  • Koj yuav tsum tau muab kev nkag mus rau koj lub microphone rau kev paub lub suab kom ua haujlwm
  • Vim tias qhov nkag mus rau koj lub microphone lub vev xaib yuav tsum tau khiav hauv qab
  • Lub tsev qiv ntawv cylon-api-socketio tsis txhawb https nyob rau lub sijhawm no. Kuv muaj qhov rub thov tos kom sib koom ua ke, tab sis txog thaum ntawd koj yuav tsum hloov /node_modules/cylon-api-socketio/lib/api.js nrog cov ntawv hauv qhov chaw cia khoom no
  • pi-blaster xav tau los ua txoj haujlwm no.

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. RGB LED Sawb Lub Teeb - Kuv tau ua si nrog Minger LED Sawb Lub Teeb 32.8ft/10M 600leds RGB SMD 5050. Qhov no los nrog tus tswj thiab lub zog xa khoom txog li CAD 40
  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
  5. Breadboard Solderless Prototype PCB Board - tej yam zoo li no
  6. 3 x 10kΩ Resistors
  7. 3 x N -channel MOSFETs rau kev tswj cov LEDs - Kuv yuav qee qhov IRL3303 los ntawm kuv lub khw hluav taws xob hauv zos. Nws yog ib qho tseem ceeb uas lub qhov rooj pib qhov hluav taws xob yog qhov siab tshaj plaws. 3.3V yog li nws tuaj yeem tsav los ntawm RPi tus pin; feem ntau yog qhia los ntawm 'L' (Logic-Level) hauv lub npe.

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: Pi-blaster

Pib-blaster
Pib-blaster

pi-blaster ua rau PWM ntawm GPIO pins koj thov ntawm Raspberry Pi. Cov txheej txheem siv tau muaj txiaj ntsig zoo: tsis siv CPU thiab muab cov mem tes ruaj khov heev.

Qhov Kev Ntsuas Dav Dav no tso cai rau Raspberry Pi tswj hwm qhov ci ntawm txhua qhov liab, Ntsuab thiab Xiav raws rau LED kab txaij.

Ua ntej, clone lub chaw cia khoom

cd /opt /cov

sudo git clone https://github.com/sarfata/pi-blaster.git sudo chown -R pi: pi pi-blaster

Tom qab ntawd, tsim thiab teeb tsa

cd/opt/pi-blaster./autogen.sh &&./configure && ua && sudo install

Thaum kawg, teeb tsa tus pin twg koj xav siv

Hauv qab tus lej hauv paus, lossis siv sudo, tsim thiab kho cov ntaub ntawv

/etc/default/pi-blaster

Ntxiv cov kab hauv qab no

DAEMON_OPTS =-gpio 23, 24, 25

Cov gpio pins no xav tau kom phim cov pins uas koj txuas rau koj cov hlua LED.

NCO TSEG: Muaj qhov sib txawv ntawm GPIO thiab tus lej tus lej. Qhov piv txwv no siv cov hauv qab no

LED - Xiav, GPIO -23, Pin - 16

LED - Liab, GPIO -24, Pin - 18 LED - Ntsuab, GPIO -25, Pin - 22

Ntxiv tweaks

Pib pi-blaster

sudo kev pabcuam pi-blaster pib

Pib dua pi-blaster

sudo kev pabcuam pi-blaster rov pib dua

Nres pi-blaster

sudo kev pabcuam pi-blaster nres

Pib pi-blaster txiav thaum lub sijhawm khau raj

sudo systemctl pab pi-blaster

Cov lus ceeb toom thiab lwm yam kev ceeb toom

Pins tau siv los ntawm pi-blaster yuav raug teeb tsa raws li kev tso tawm. Tsis txhob ntsaws qee yam ntawm cov tswv yim lossis koj yuav ua rau nws puas tsuaj! Daemon no siv lub tshuab PWM kho vajtse ntawm raspberry pi kom tau txais lub sijhawm tseeb. Qhov no yuav cuam tshuam nrog koj daim npav suab tawm.

Kauj Ruam 4: 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

los yog

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

3. Nruab qhov kev cia siab

cd xim-pi

npm nruab

Qhov no yuav siv sijhawm li 2-3 feeb

4. Txoj haujlwm no xav tau kev sib txuas lus dhau HTTPS thiab WSS. Lub sijhawm no cylon-api-socketio tsis txhawb SSL kev sib txuas. Muaj qhov qhib rub thov kom ntxiv qhov kev txhawb nqa no, tab sis kom txog thaum qhov sib koom ua ke, muaj cov ntaub ntawv thaj nyob hauv qhov chaw cia khoom no. Khiav cov lus txib hauv qab no tom qab npm nruab

git checkout node_modules/cylon-api-socketio/lib/api.js

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

1. Tsim cov ntaub ntawv tseem ceeb ntiag tug

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

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

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

openssl req-tshiab -key xim-pi-key.pem -out xim-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 Xeev]: 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]: Xim Pi Lub Koom Haum Lub Npe Lub Npe (piv txwv li, ntu) : Common Name (eg server FQDN or YOUR name) : color-pi Email Address : [email protected]

Ib lo lus zais nyuaj :

Lub tuam txhab xaiv lub 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 color-pi-csr.pem -signkey color-pi-key.pem -out color-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 6: Txuas Lub Circuit Court

Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob
Kev tiv thaiv kab mob

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. N-channel MOSFET transistors tau siv los cais 3.3v ntawm RPi pins thiab 12v ntawm LED fais fab mov.

MOSFET muaj peb tus pin Qhov Rooj, Dej thiab Qhov Chaw. Yog tias koj tsis paub meej txog qhov twg uas yog google rau cov ntaub ntawv ntawm transistor koj tab tom siv, piv txwv li SIB 3303

Peb tab tom yuav txuas Raspberry Pi Pin mus rau Lub Rooj vag, cov xov hlau LED mus rau Cov Dej thiab ib qho av sib koom mus rau Qhov Chaw. Thaum tus Pin nce siab, qhov hluav taws xob nruab nrab ntawm Cov Dej thiab Lub Hauv Paus yuav qhib lub Qhov Rooj thiab yuav txuas lub rooj vag mus rau Qhov Chaw.

Peb kuj tseem yuav tso 10kΩ Resistors hla lub Rooj vag thiab Qhov Chaw, yog li thaum peb RPi tus pin siab, peb tuaj yeem tiv thaiv tus pin los ntawm kev txo qhov tam sim no hla nws.

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

Muaj cov duab fritzing thiab cov duab ntawm qhov tseeb Circuit Court saum toj no.

Kuv xav kom ua qhov no thaum lub zog tawm rau RPi thiab LED sawb

Teeb tsa cov kab hluav taws xob transistor, ib qho xim ib zaug

  1. Ntxig ib qho ntawm cov transistors rau hauv lub khob cij raws li qhia hauv daim duab
  2. Ntxig ib qho ntawm 10kΩ Resistors hla lub Drain thiab Source pins ntawm transistor. Nov yog tus pin thawj thiab zaum kawg
  3. Siv qee lub xaim txuas txuas Tus Pin tus pin (tus pin kawg) rau hauv av ntawm lub khob cij
  4. Rov ua cov kauj ruam 1 - 3 ob zaug ntxiv, yog li koj muaj peb teev - ib qho xim (Liab, Ntsuab thiab Xiav)

Txuas RPi tus pin rau lub rooj tsavxwm

  1. Txuas tus Pin 16 mus rau Lub Rooj Pin (tus pin thawj) ntawm thawj lub transistor - Qhov no yuav yog Blue LED channel
  2. Txuas tus Pin 18 mus rau Lub Rooj Pin (thawj tus pin) ntawm thawj lub transistor - Qhov no yuav yog Red LED channel
  3. Txuas tus Pin 20 mus rau ib qho ntawm cov kab hauv av ntawm ib sab ntawm lub khob cij
  4. Txuas tus Pin 22 mus rau Lub Rooj Pin (tus pin thawj) ntawm thawj lub transistor - Qhov no yuav yog Green LED channel

Kuv tau siv cov xim sib txuas sib txuas rau LEDs: Xiav, Liab thiab Ntsuab. Kuv tau siv dub rau hauv av

Txuas Barrel Jack

  1. Txuas lub xaim dawb mus rau + qhov kawg ntawm lub thoob
  2. Txuas cov xaim dub mus rau - qhov kawg ntawm lub tog raj kheej
  3. Txuas cov xaim dub rau tib txoj kab hauv av ntawm lub khob cij raws li RPi Pin 20 tau txuas nrog
  4. Txuas cov xaim dawb mus rau + kab ntawm lub khob cij

Txuas cov hlua LED

Kuv cov hlua LED tuaj nrog lub txuas uas yog qhov loj txaus uas nws tuaj yeem raug ntsaws ib ntus rau hauv lub khob cij. Kuv thawb lub txuas rau hauv lub khob cij thiab txuas nws mus rau qhov kev sim ntawm Circuit.

  1. Thawj transistor txuas nrog Pin 16. Kuv tau xaim xaim xaim los ntawm Drain pin (tus pin nruab nrab) mus rau xaim xaim ntawm LED kab txuas
  2. Tus transistor thib ob txuas nrog Tus Pin 18. Kuv tau xaim xov liab los ntawm

    Ntws

    tus pin (tus pin nruab nrab) mus rau cov xaim liab ntawm LED kab txuas

  3. Tus transistor thib peb txuas nrog Pin 22. Kuv tau xaim hlau ntsuab los ntawm

    Ntws

    tus pin (tus pin nruab nrab) mus rau cov xaim ntsuab ntawm LED kab txuas

  4. Thaum kawg, Kuv tau xaim xaim dawb los ntawm kab + kab ntawm lub khob cij uas tau txuas nrog rau lub thoob yas, mus rau cov xaim dawb ntawm LED kab txuas.

Fais fab

Tom qab tshuaj xyuas lub Circuit Court, koj yuav tsum ua tau zoo rau lub zog ntawm Raspberry Pi thiab ntsaws rau hauv 12v muab rau lub tog raj kheej.

Kauj Ruam 7: Tus Neeg Siv Khoom Sab Nraud

Neeg rau zaub mov sab Code
Neeg rau zaub mov sab Code

Khiav tus neeg rau zaub mov sab chaws

cd /opt/com.jonhaydock/colour-pi

sudo npm pib

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

NCO TSEG: Nco ntsoov kom muaj pi-blaster khiav ua ntej

Ib puag ncig hloov pauv

Lub vev xaib lub vev xaib tsis raug 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 COLOUR_PI_PORT = 2443

Lub vev xaib lub vev xaib tsis raug yog 1443, 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 COLOUR_PI_WSS_PORT = 3443

Nco tseg: Raws li lub vev xaib lub vev xaib tau ua los ntawm cylon.js thiab tsis yog lub vev xaib tseem ceeb, cov no yuav tsum yog ntawm cov chaw nres nkoj sib txawv

Cov koob uas tau siv rau Xiav (tus pin 16), Ntsuab (tus pin 18) thiab Liab (tus pin 22) kuj tseem tuaj yeem thim tau. Piv txwv

export COLOUR_PI_PIN_BLUE = 36

export COLOUR_PI_PIN_RED = 38 export COLOUR_PI_PIN_GREEN = 40

Nco tseg: Cov no yuav tsum tau ua kom phim lub cev uas koj tau siv. Yog tias koj hloov cov no, koj tseem yuav xav tau hloov kho GPIOs uas tau hais tseg hauv/etc/default/pi-blaster file. Piv txwv

DAEMON_OPTS =-gpio 16, 20, 21

Tus lej server tseem ceeb tuaj yeem pom hauv app.js file. Cov ntaub ntawv no pib HTTPS web server thiab tseem, los ntawm Cylon.js lub moj khaum, siv socket.io los mloog rau lub vev xaib qhov thov ntawm ib qho chaw nres nkoj cais.

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 vev xaib server yuav ua haujlwm ib qho ntsiab lus hauv qab daim nplaub tshev pej xeem. Nws tsis zoo los tso saib nplooj ntawv index.html.

Cylon.js tsim qhov kawg uas koj tuaj yeem txuas Socket.io.

10.0.1.2:1443/api/robots/colour-pi

Koj tuaj yeem xa cov lus set_colour los ntawm lub qhov (socket) los teeb lub Liab, Ntsuab thiab Xiav qhov tseem ceeb

device.emit ('set_colour', r, g, b)

Uas hu rau set_colour hais kom ua, uas hu rau setColour muaj nuj nqi hauv app.js. Txoj haujlwm no teeb tsa qib ci ci, rau txhua qhov R, G thiab B qhov tseem ceeb, nruab nrab ntawm 0 thiab 255. Qhov twg 0 tawm thiab 255 ua tiav.

xws li

Liab r = 255, g = 0, b = 0

Ntsuab r = 0, g = 255, b = 0 Xiav r = 0, g = 0, b = 255 Dawb r = 255, g = 255, b = 255 Dub / Tawm r = 0, g = 0, b = 0

Kauj Ruam 8: Website Code

Website Code
Website Code

General

Lub vev xaib siv lub suab lees paub los xaiv cov xim los ntawm daim ntawv teev npe ua ntej. Txhawm rau ntxiv xim rau cov npe, kho cov ntaub ntawv ntawm tus neeg rau zaub mov: pej xeem/cov ntaub ntawv/colours.json

xws li

"liab": "#FF0000", Thaum pom cov xim, lossis xaiv los ntawm qhov poob qis, Lub thawv Output yuav raug teeb tsa rau cov xim ntawd thiab cov lus yuav xa los ntawm socket.io mus rau Raspnerry Pi, uas yuav teeb tsa LEDs rau tib xim.

NCO TSEG: nyob ntawm seb koj cov LEDs zoo npaum li cas koj tuaj yeem lossis yuav tsis pom cov xim zoo sib xws. Qee qhov yooj yim dua li lwm tus

Thaum koj xub rub lub vev xaib, thaum koj siv tus kheej-kos npe SSL daim ntawv pov thawj koj yuav tsum lees paub qhov no hauv qhov browser. Koj yuav tsum pom kev ceeb toom kev nyab xeeb txog daim ntawv pov thawj.

Lub suab lees paub

Lub npov no muaj lub cim microphone. Yog tias koj nyem lub cim thaum nws ntsuab, nws yuav pib mloog xim. Thaum nws tab tom mloog, nws yuav tig liab. Nws yuav mloog rau lub sijhawm luv luv thiab tom qab ntawd nres. Nyem rau lub cim microphone thaum nws liab tseem yuav txwv tsis pub nws mloog.

Raws li lub vev xaib no xav tau nkag mus rau koj lub microphone, koj yuav tsum tau tso cai rau nws thaum hais kom sai

NCO TSEG: Koj xav tau lub microphone rau ntu no. Kuv siv ib qho ntawm kuv lub vev xaib lub koob yees duab.

Cov Ntawv Teev Tseg Ib Ntus

Lub npov no yog taug qab qhov kwv yees ntawm cov lus uas koj tab tom hais, zoo li koj tau hais rau lawv.

Daim ntawv teev lus kawg

Lub npov no taug qab qhov kev kwv yees zaum kawg yog qhov koj hais.

Paub Xim

Nov yog cov npe ntawm txhua qhov xim uas nplooj ntawv paub txog. Nws yog tsim los ntawm cov ntawv colours.json. Yog tias koj xaiv ib qho ntawm cov xim no, nplooj ntawv yuav hais xim thiab teeb cov xim tso tawm.

NCO TSEG: Koj xav tau tus hais lus lossis lub mloog pob ntseg kom hnov lus

Pom Cov Xim

Lub vev xaib no tam sim no tsuas yog txhawb cov xim. Yog tias lo lus lossis lus koj tau hais rau hauv lub microphone zoo ib yam lub npe paub xim, lossis koj xaiv cov xim los ntawm Known Color list, nws yuav raug ntxiv ntawm no raws li tus lej.

Tso zis

Cov xim pom zaum kawg yuav tshwm ntawm no. Cov xim Hex tus nqi (piv txwv li #7cb9e8) thiab tus nqi RGB (piv txwv li 124, 185, 232) yuav muab tso tawm ua cov ntawv thiab tom qab ntawm lub npov nyob hauv nruab nrab yuav raug teeb tsa rau xim tiag.

Cov xim no tseem raug xa mus rau Raspberry Pi thiab koj yuav tsum pom cov xim ntawm LED sawb hloov.

NCO TSEG: yog tias koj tsis pom qhov hloov xim LED, sim rov pib dua pi-blaster thiab/lossis node.js app

sudo kev pabcuam pi-blaster rov pib dua

sudo npm pib

Paub Cov Suab

Lub npov no nthuav tawm cov npe ntawm "Paub Lub Suab" los ntawm kev txhawb nqa kev hais lus Synthesis. Xaiv ib lub suab no yuav hloov lub suab thiab hom lus uas koj yuav hnov, thiab nws yuav hais lub suab lub npe.

Nws tseem yuav hloov cov lus ntawm SpeechRecognition kom zoo ib yam li tau xaiv hauv cov npe.

Kauj ruam 9: Thaum kawg

Image
Image

Nov yog qhov piv txwv ntawm qhov koj yuav tsum pom.

Thov qhia rau kuv paub yog tias koj muaj teeb meem thiab kuv tuaj yeem hloov kho raws li xav tau.

Pom zoo: