Cov txheej txheem:

Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Ua Raws Li Qhov Kub Kub: 9 Kauj Ruam
Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Ua Raws Li Qhov Kub Kub: 9 Kauj Ruam

Video: Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Ua Raws Li Qhov Kub Kub: 9 Kauj Ruam

Video: Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Ua Raws Li Qhov Kub Kub: 9 Kauj Ruam
Video: Tooj Nchai rov mus noj quav nploos 8/14/2017 2024, Kaum ib hlis
Anonim
Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Tsum Ua Raws Li Qhov Kub Kub
Mood Speaker- Tus Hais Lus Muaj Hwjchim rau Mood Music Yuav Tsum Ua Raws Li Qhov Kub Kub

Nyob zoo!

Rau kuv lub tsev kawm ntawv txoj haujlwm ntawm MCT Howest Kortrijk, Kuv ua Mood Speaker qhov no yog ntse Bluetooth hais lus ntaus ntawv nrog cov ntsuas sib txawv, LCD thiab WS2812b ledstrip suav nrog. hais lus Txhua yam khiav ntawm Raspberry Pi (Database, Webserver, Backend).

Yog li cov lus qhia no yog ib qib zuj zus txheej txheem ntawm qhov kuv pom qhov haujlwm no hauv 3 lub lis piam. Yog li yog tias koj xav rov tsim kuv qhov haujlwm koj tuaj yeem ua raws cov lus qhia

Cov lus qhia no yog kuv thawj qhov uas kuv tau sau yog li yog muaj qee qhov tsis txaus ntseeg, Kuv yuav Sim teb lawv sai li kuv tuaj yeem ua tau!

Kuv GitHub:

Kauj Ruam 1: Cov khoom siv

Raspberry Pi 3B & 16GB SD Card

Kuv tag nrho txoj haujlwm khiav ntawm kuv tus Raspberry Pi 3B nrog cov duab teeb tsa, uas kuv yuav piav qhia hauv cov kauj ruam tom ntej (Kauj Ruam 4: Teeb Raspberry Pi)

LCD Zaub 16x2

Kuv siv qhov yooj yim LCD Zaub los luam tawm kuv qhov kub thiab txias, thiab IP chaw nyob.

Cov ntaub ntawv:

DS18B20 Kub Sensor

DS18B20 yog ib lub xaim hluav taws xob ntsuas qhov ntsuas kub, tsim los ntawm Maxim Integrated. Muaj 2 hom DS18B20 cov ntsuas, cov khoom tiv thaiv nkaus xwb (Uas Kuv tau siv) thiab cov dej tsis sib haum, uas yog qhov loj dua, tab sis qhov ntawd tsis yog qhov kuv xav tau rau kuv qhov haujlwm, yog li kuv siv cov khoom siv xwb. Lub ntsuas ntsuas tuaj yeem ntsuas qhov ntsuas kub ntawm -55 ° C txog +125 ° C (-67 ° F txog +257 ° F) thiab nws muaj qhov tseeb ntawm 0.5 ° C los ntawm -10 ° C txog +85 ° C. Nws kuj tseem muaj lub khoos phis tawj daws teeb meem los ntawm 9 khoom mus rau 12 khoom.

Cov ntaub ntawv:

YWB 3008

Txhawm rau nyeem cov ntaub ntawv los ntawm kuv LDR thiab PIR-sensor Kuv tau siv MCP3008, uas yog 8 channel 10 ntsis analog rau digital hloov pauv nrog SPI interface thiab zoo nkauj heev rau program.

Cov ntawv xov xwm:

PIR tsab ntawv tsa suab sensor

Txhawm rau txheeb xyuas thaum muaj ib tus neeg nkag mus thiab tawm hauv kuv chav, Kuv siv lub ntsuas hluav taws xob tsis pom kev deb vim tias lawv yooj yim siv thiab me me.

Cov ntaub ntawv:

LDR

Kuv siv tus kws yees duab lossis LDR (Lub Teeb Txo Kev Tiv Thaiv, lossis lub teeb-tiv taus lub teeb) txhawm rau txheeb xyuas qhov ci ci ntawm chav tsev nws nyob hauv. Thiab tseem yuav tig kuv Ledstrip rau thaum nws tsaus ntuj.

Hais lus - 3 "Txoj kab uas hla - 4 Ohm 3 Watt

Nov yog tus hais lus lub khob uas kuv tau xaiv tom qab suav qhov Voltage thiab Amperes nws yuav xav tau thiab qhov no yog qhov zoo tshaj plaws rau kuv qhov Raspberry Pi project, tsim los ntawm Adafruit.

Txheej txheem cej luam:

MAX98357 I2S Class-D Mono Amplifier

Qhov no yog lub tshuab ua suab nrov uas los nrog tus hais lus, tsis yog nws yog lub tshuab ua kom nrov, nws tseem yog I2S digital rau analog hloov pauv, yog li nws kuj tseem haum zoo rau kuv tus hais lus & suab kaw lus.

Txheej txheem cej luam:

Cov ntaub ntawv:

Arduino Ib

Arduino Uno yog lub hauv paus qhib microcontroller board raws li Microchip ATmega328P microcontroller, tsim los ntawm Arduino.cc. Pawg Uno muaj 14 Digital pins, 6 analog pins thiab muaj peev xwm ua tau tiav nrog Arduino IDE software

Txheej txheem cej luam:

Levelshifter

Nov yog pawg thawj coj me uas saib xyuas kev sib txuas lus ntawm Arduino Uno thiab Raspberry Pi thiab qhov sib txawv ntawm qhov sib txawv, Arduino: 5V & Raspberry Pi: 3.3V. Qhov no xav tau vim tias cov kab ntawv txuas tau txuas nrog Arduino thiab khiav ntawm qhov ntawd, thaum txhua lwm yam khoom siv ntawm Raspberry Pi.

WS2812B - Ledstrip

Nov yog kab ntawv coj nrog 60 RGB leds (koj tuaj yeem yuav cov kab ntev nrog ntau RGB leds, yog tias koj xav tau). Uas yog hauv kuv rooj plaub txuas nrog Arduino Uno, tab sis kuj tseem tuaj yeem txuas nrog ntau lwm yam khoom siv thiab yooj yim heev rau siv.

Cov ntaub ntawv:

GPIO T-Tshooj, 1 Cov qhob cij thiab ntau lub jumperwires

Txhawm rau txuas txhua yam uas kuv xav tau rau lub rooj noj mov thiab cov jumperwires, Kuv tsis tau siv GPIO T-ntu tab sis koj tuaj yeem siv nws kom paub meej tias lub thoob mus qhov twg.

Kauj ruam 2: Schematic thiab thaiv

Schematic thiab thaiv
Schematic thiab thaiv
Schematic thiab thaiv
Schematic thiab thaiv

Txhawm rau ua kuv cov phiaj xwm kuv siv Fritzing, nws yog ib qho program koj tuaj yeem teeb tsa uas tso cai rau koj los tsim cov phiaj xwm yooj yim heev hauv ntau hom kev pom.

Rub tawm Fritzing:

Xyuas kom txhua yam txuas nrog kom raug. Kuv siv cov xim kom pom tseeb me ntsis kom paub tias yuav txuas cov xov hlau nyob qhov twg. Hauv kuv qhov xwm txheej kuv siv cov xim sib txawv rau cov xov hlau

Kauj Ruam 3: Tsim Database

Tsim Database
Tsim Database

Peb tau khaws ntau cov ntaub ntawv los ntawm 3 lub ntsuas (Kub los ntawm DS18B20, Lub teeb ci los ntawm LDR thiab Qhov xwm txheej los ntawm PIR-sensor). Yog li nws zoo tshaj kom khaws tag nrho cov ntaub ntawv no hauv cov ntaub ntawv khaws tseg. Kuv yuav piav qhia hauv qib tom ntej yuav teeb tsa lub database li cas (Kauj Ruam 5: Forward Engineering Peb Lub Database rau RPi!) Kuv tau ua haujlwm zoo nrog 3NF uas yog vim li cas peb faib cov khoom sib koom thiab keeb kwm ntawm cov khoom siv rau hauv lwm lub rooj. Peb siv Music database txhawm rau taug qab cov nkauj uas tau mloog.

Zuag qhia tag nrho qhov no yog qhov pib yooj yim thiab yooj yim database tsim los ua haujlwm ntxiv nrog.

Kauj Ruam 4: Teeb Raspberry Pi

Yog li tam sim no peb muaj qee qhov pib ntawm qhov haujlwm ua tiav. Cia peb pib nrog teeb tsa Raspberry Pi!

Ntu 1: teeb tsa daim npav SD

1) Rub cov Software thiab Cov Ntaub Ntawv xav tau

Koj yuav tsum rub tawm 2 software thiab 1 OS piv txwv li Raspbian rau txoj kev ua tiav no. 1 software: Thawj software yog Win32 Disk Imager.

sourceforge.net/projects/win32diskimager/

2nd software: software thib ob yog SD Card Formatter.

www.sdcard.org/downloads/formatter_4/

Raspbian OS: Qhov no yog lub kaw lus tseem ceeb ntawm Pi.

www.raspberrypi.org/downloads/raspberry-pi-os/

Extract tag nrho cov ntaub ntawv rau lub desktop.

2) Tau txais SD Card thiab Daim Npav Nyeem Ntawv

Tau txais yam tsawg kawg 8GB chav kawm 10 SD daim npav nrog daim npav nyeem ntawv. Ntxig daim npav ntawd rau hauv daim npav nyeem ntawv thiab txuas qhov ntawd mus rau USB chaw nres nkoj.

3) Format SD Card

Qhib SD Card Formatter thiab xaiv tsav.

Nyem rau ntawm hom ntawv thiab tsis hloov lwm yam kev xaiv.

Thaum kev ua tiav tiav, nyem rau OK.

4) Sau OS rau ntawm SD Card

Qhib win32diskimager.

Xauj lub.img cov ntaub ntawv ntawm Raspbian OS uas tau muab rho tawm los ntawm cov ntawv rub tawm.

Nyem rau qhib thiab tom qab ntawv nyem Sau.

Yog tias muaj lus ceeb toom tshwm sim ces tsis quav ntsej cov ntawd los ntawm txhaj OK. Tos kom sau kom tiav thiab nws yuav siv sijhawm li ob peb feeb. Yog li ua siab ntev.

n

5) Thaum qhov no ua tiav, peb tau npaj ua qee qhov kev hloov kho zaum kawg ua ntej muab cov duab tso rau hauv peb RPi.

Mus rau koj daim npav SD npe, tshawb cov ntaub ntawv npe 'cmdline.txt' thiab qhib nws.

Tam sim no ntxiv 'ip = 169.254.10.1' ntawm tib kab.

Txuag cov ntawv.

Tsim cov ntaub ntawv npe 'ssh' yam tsis muaj kev txuas ntxiv lossis cov ntsiab lus. (Txoj hauv kev yooj yim tshaj plaws yog tsim cov ntaub ntawv txt thiab tshem tawm.txt tom qab)

Tam sim no txhua yam tau teeb tsa ntawm SD daim npav koj tuaj yeem tso nws tawm ntawm koj lub khoos phis tawj thiab muab tso rau hauv Raspberry Pi TSIS YOG txuas lub zog. Thaum SD daim npav nkag rau hauv RPI, txuas LAN cable los ntawm koj lub khoos phis tawj mus rau RPi LAN chaw nres nkoj, thaum qhov no txuas nrog koj tuaj yeem txuas lub zog rau RPi.

Ntu 2: Kho RPi

Putty

Tam sim no peb xav teeb tsa peb Raspberry Pi, qhov no ua tiav los ntawm Putty.

Putty software:

Thaum rub tawm tiav, qhib Putty thiab ntxig tus IP '169.254.10.1' thiab Chaw nres nkoj '22' thiab hom txuas: SSH.

Tam sim no peb tuaj yeem thaum kawg qhib peb cov kab hais kom ua interface thiab nkag mus nrog cov ntaub ntawv pib nkag mus -> Tus neeg siv: pi & Password: raspberry. (Nws pom zoo kom hloov nws sai li sai tau. Nov yog phau ntawv qhia yuav ua li cas:

Raspi-teeb tsa

Peb yuav tsum ua kom muaj kev cuam tshuam sib txawv thiab ua qhov ntawd peb yuav tsum xub ntaus tus lej hauv qab no:

sudo raspi-teeb tsa

Yam uas peb xav tau los pab yog hauv ntu cuam tshuam. Peb yuav tsum ua kom muaj kev cuam tshuam hauv qab no:

  • Ib-xaim
  • Cov
  • Kuv 2C
  • SPI

Qhov ntawd yog txhua yam peb xav tau ua nrog raspi-teeb tsa

Ntxiv koj li WIFI

Ua ntej, koj yuav tsum tau hauv paus rau cov lus txib hauv qab no los ua lub hauv paus

sudo -i ua

Thaum koj nyob hauv paus, siv cov lus txib hauv qab no: (Hloov SSID nrog koj lub npe network thiab tus lej nkag nrog koj tus password network)

wpa_passphrase "ssid" "password" >> /etc/wpa_supplicant/wpa_supplicant.conf

Yog tias koj tau ua qee yam tsis raug, koj tuaj yeem tshawb xyuas, hloov kho lossis tshem tawm lub network no los ntawm kev nkag mus rau cov lus txib hauv qab no:

nano /etc/wpa_supplicant/wpa_supplicant.conf

Yog li tom qab peb nkag mus rau peb lub network, cia nkag mus rau WPA tus neeg siv khoom sib tham

wpa_cli

Xaiv koj tus interface

wb wl0

Rov qab qhib cov ntawv

rov tsim dua tshiab

Thiab thaum kawg koj tuaj yeem pom yog tias koj tau txuas nrog zoo:

ip aw

Ntu 3: Hloov kho RPi + txhim kho software

Tam sim no peb tau txuas nrog internet, hloov kho cov pob uas twb tau teeb tsa yuav yog qhov txav nrawm, yog li cia ua qhov ntawd ua ntej ua ntej txhim kho lwm pob.

sudo apt-tau hloov tshiab

sudo apt-tau hloov tshiab

Tom qab hloov kho RPi peb yuav tsum teeb tsa cov software hauv qab no:

MariaDB Database

sudo apt-tau nruab mariadb-server

Apache2 Webserver

sudo apt nruab apache2

Nab hab sej

hloov tshiab-lwm -install/usr/bin/nab hab sej nab hab sej /usr/bin/python3.7 1 hloov tshiab-ua lwm yam-nruab/usr/bin/nab hab sej nab nab/usr/bin/python3 2

Nab hab sej pob

Koj yuav tsum teeb tsa txhua pob khoom no kom ua rau lub backend ua haujlwm zoo:

  • Lub hwj
  • Flask-Cors
  • Flask-MySql
  • Flask-SocketIO
  • PyMySQL Thov
  • Nab hab sej
  • RPi. GPIO
  • Gevent
  • Gevent-websocket

Hais lus tsev qiv ntawv

Rau kev siv tus neeg hais lus nrog lub tshuab ua kom nrov nrov peb yuav tau teeb tsa lub tsev qiv ntawv rau nws

curl -sS > | bash

Step 4: Reboot

After everything has been installed we will have to reboot the pi to make sure everything works correctly

sudo reboot

Step 5: Setting Up the Database to the RPi

Kev teeb tsa Database rau RPi!
Kev teeb tsa Database rau RPi!

Tam sim no peb tau teeb tsa txhua yam peb xav tau, cia peb tso peb Database peb tsim ntawm peb Raspberry Pi!

Txhawm rau teeb tsa cov ntaub ntawv peb yuav tsum txuas MySql thiab RPi. Txog qhov ntawd peb yuav qhib MySQLWorkbench thiab tsim kev sib txuas tshiab. Thaum saib cov duab koj yuav tau hloov pauv cov ntaub ntawv rau koj li.

Yog tias koj tseem tsis tau hloov dab tsi tseem tuaj yeem siv rau SSH pi thiab raspberry, rau MySQL mysql thiab mysql.

Thaum qee yam tsis meej koj tseem tuaj yeem ua raws cov lus qhia no:

Txhawm rau xa koj cov ntaub ntawv nws yuav tsum yooj yim siv PHPmyAdmin vim tias koj tuaj yeem tau txais ntau qhov yuam kev ua nrog MySql

Kauj Ruam 6: Kho Bluetooth ntawm Peb RPi

Peb tab tom tsim Mood speaker, uas peb tseem tuaj yeem siv nrog peb tus kheej lub suab paj nruag yog li qhov no yooj yim dua thaum RPi yog

conected rau bluetooth Kuv ua raws li kev qhia rau nws uas koj tuaj yeem pom ntawm no:

scribles.net/streaming-bluetooth-audio-fr…

Kuv tau sau txhua yam ntawm no ib yam rau txhua tus neeg uas xav rov tsim nws

Tshem tawm qhov uas twb muaj lawm bluealsa

sudo rm/var/khiav/bluealsa/*

Ntxiv A2DP profile Ntxuav lub luag haujlwm

sudo bluealsa -p a2dp -dab dej &

Qhib lub bluetooth interface thiab qhib koj lub bluetooth rau

bluetoothctl zog rau

Teem ib tus neeg sawv cev ua khub

tus neeg sawv cev rau default-agent

Ua kom koj RPi tshawb pom

nrhiav tau rau

  • Tam sim no los ntawm koj lub cuab yeej bluetooth, tshawb rau RPi thiab txuas nrog nws.
  • Paub meej tias kev sib txuas ntawm ob lub cuab yeej, ntaus 'yog' hauv koj cov putty.
  • Tso cai rau A2DP kev pabcuam, ntaus 'yog' dua.
  • Thaum qhov no ua tiav, peb tuaj yeem ntseeg peb lub cuab yeej, yog li peb tsis tas yuav hla txhua qhov no txhua lub sijhawm peb xav txuas

ntseeg XX: XX: XX: XX: XX: XX (Koj lub bluetooth mac chaw nyob los ntawm peb lub cuab yeej siv)

Yog tias koj xav kom koj RPi khaws cia kom pom tau, qhov ntawd yog koj li kev xaiv, tab sis kuv xav kom nws tua dua, yog li ntawd tib neeg tsis tuaj yeem sim txuas nrog koj lub thawv

nrhiav tau tawm

Tom qab ntawd peb tuaj yeem tawm ntawm peb lub bluetooth interface

tawm

Thiab thaum kawg peb txoj kev xa suab: peb cov cuab yeej siv xa mus rau peb RPi

bluealsa-aplay 00: 00: 00: 00: 00: 00

Tam sim no peb lub cuab yeej txuas nrog peb Raspberry nrog bluetooth thiab koj yuav tsum tuaj yeem sim nws los ntawm kev ua si ib qho xov xwm piv txwv li Spotify, thiab lwm yam.

Kauj Ruam 7: Sau Cov Backend Ua tiav

Yog li tam sim no teeb tsa tau ua tiav, thaum kawg peb tuaj yeem pib sau peb cov haujlwm backend!

Kuv siv Visual Studio Code rau kuv tag nrho cov backend, koj tsuas yog xav kom paub tseeb tias koj qhov Visual Studio project txuas nrog koj li Raspberry Pi, qhov no txhais tau tias koj LAN cabel yuav tsum txuas nrog koj RPi thiab ua kom SSH txuas. (cov ntaub ntawv yuav ua li cas thiaj tsim kev sib txuas nyob deb tuaj yeem pom ntawm no:

Kuv siv kuv tus kheej cov chav kawm thiab cov no tseem suav nrog hauv kuv GitHub.

Hauv kuv cov ntaub ntawv backend kuv siv chav kawm sib txawv, yog li txhua yam tuaj yeem siv sib cais thiab yog li kuv lub ntsiab cai tsis cuam tshuam nrog txhua qhov sib txawv xov. Kuv siv xov los khiav txhua chav sib txawv ib zaug. Thiab hauv qab koj tau txais txhua txoj hauv kev yog li peb tuaj yeem tau txais cov ntaub ntawv yooj yim hauv peb lub ntsej muag.

Kauj Ruam 8: Sau Frontend (HTML, CSS & JavaScript)

Tam sim no qhov backend tau ua tiav, peb tuaj yeem pib sau tag nrho pem hauv ntej-kawg.

HTML thiab CSS nyuaj heev rau kuv kuv tau ua qhov zoo tshaj plaws los ua nws lub xov tooj ua ntej vim tias kuv tuaj yeem txuas rau nws nrog bluetooth los hloov cov nkauj nrog Spotify. Yog li nws yuav yooj yim dua los ntawm lub mobile dashboard

Koj tuaj yeem tsim koj lub dashboard hauv txhua txoj kev koj xav tau, kuv tsuas yog tso kuv tus lej thiab tsim ntawm no, koj tuaj yeem ua txhua yam koj nyiam!

Thiab Javascript tsis yooj yim rau kuv, ua haujlwm nrog ob peb GET los ntawm kuv txoj hauv kev rov qab, ntau tus neeg mloog cov xwm txheej thiab qee cov qauv socket kom tau txais cov ntaub ntawv los ntawm kuv lub ntsuas cua.

Kauj Ruam 9: Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke

Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke
Tsim Kuv Cov Ntaub Ntawv thiab Muab Txhua Qhov Ua Ke

Kuv xub pib kos duab ntawm qhov kuv xav kom rooj plaub zoo li cas, qee yam tseem ceeb yog tias nws yuav tsum loj txaus rau txhua yam kom haum, txij li peb tau txais lub voj voog loj los tso rau hauv rooj plaub tab sis yuav tsum nyob ntsiag to kom nws tsis txhob ' siv ntau qhov chaw

Kuv tau ua rooj plaub tawm ntawm ntoo, Kuv xav tias nws yog qhov yooj yim tshaj plaws los ua haujlwm nrog thaum koj tsis muaj kev paub ntau txog kev tsim cov rooj plaub thiab koj kuj muaj ntau yam uas koj tuaj yeem ua nrog nws.

Kuv tau pib los ntawm cov ntoo thav duab qub uas kuv tau puag ncig thiab nyuam qhuav pib pom ntoo. Thaum kuv muaj kuv cov ntaub ntawv yooj yim, Kuv tsuas yog yuav tsum tau xaum qhov hauv nws (ntau heev nyob rau ntawm xub ntiag ntawm rooj plaub, zoo li koj tuaj yeem pom ntawm cov duab thiab muab qee cov ntsia hlau tso rau hauv, nws yog rooj plaub tiag tiag, tab sis nws zoo nkauj heev thiab haum haum. Kuv kuj txiav txim siab pleev xim nws kom nws zoo.

Thiab thaum rooj plaub tau ua tiav, nws yog lub sijhawm los muab tag nrho ua ke, zoo li koj pom hauv daim duab kawg! Nws yog qhov tsis zoo nyob hauv lub thawv, tab sis txhua yam ua haujlwm thiab kuv tsis muaj qhov chaw ntau dua, yog li kuv qhia koj tias tej zaum yuav tsim rooj plaub loj dua yog tias koj rov tsim kuv txoj haujlwm.

Pom zoo: