Cov txheej txheem:

Slimbox - Ntse Hais Lus Bluetooth!: 10 Kauj Ruam (nrog Duab)
Slimbox - Ntse Hais Lus Bluetooth!: 10 Kauj Ruam (nrog Duab)

Video: Slimbox - Ntse Hais Lus Bluetooth!: 10 Kauj Ruam (nrog Duab)

Video: Slimbox - Ntse Hais Lus Bluetooth!: 10 Kauj Ruam (nrog Duab)
Video: Will A $40 PS4 Work? 🤨 2024, Kaum ib hlis
Anonim
Slimbox - Ntse Hais Lus Bluetooth!
Slimbox - Ntse Hais Lus Bluetooth!

Nyob zoo!

Rau kuv lub tsev kawm ntawv txoj haujlwm ntawm MCT Howest Kortrijk, Kuv tau ua tus ntse Bluetooth hais lus ntaus ntawv nrog cov ntsuas sib txawv, LCD thiab RGB NeoPixel ntiv nplhaib suav nrog. Txhua yam khiav ntawm Raspberry Pi (Database, Webserver, Backend).

Yog li hauv cov lus qhia no kuv yuav qhia koj yuav ua li cas kuv ua txoj haujlwm no hauv 3 lub lis piam, ib qib zuj zus, yog li yog koj ib leeg xav rov tsim kuv txoj haujlwm, koj tuaj yeem ua tau yooj yim!

Qhov no kuj yog thawj qhov kev qhia, yog tias koj muaj lus nug, kuv yuav sim teb lawv sai li sai tau!

Kuv GitHub:

Kauj Ruam 1: Cov khoom siv

Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv

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:

Potentiometer sensor

Lub hwj chim muaj zog yog tus tiv thaiv nrog peb lub davhlau ya nyob twg uas tuaj yeem kho tau tus kheej los ntawm kev tig sab saud ntawm lub sensor. Txoj hauj lwm ntawm sab saud txiav txim siab qhov hluav taws xob tso tawm ntawm lub zog.

LSM303 Accelerometer + Compass Breakout

LSM303 pawg thawj coj sib cais yog kev sib koom ua ke ntawm peb-axis accelerometer thiab lub ntsuas hluav taws xob / ntsuas hluav taws xob, tsim los ntawm Adafruit. Nws tau siv nrog I2C interface ntawm Raspberry Pi.

Txheej txheem cej luam:

Cov ntaub ntawv:

YWB 3008

Txhawm rau nyeem cov ntaub ntawv los ntawm kuv lub hwj chim kuv siv MCP3008, uas yog 8 channel 10 ntsis analog rau digital hloov pauv nrog SPI interface thiab zoo nkauj yooj yim rau program.

Cov ntawv xov xwm:

Hais lus - 3 "Txoj kab uas hla - 8 Ohm 1 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 lub nplhaib NeoPixel txuas nrog Arduino thiab khiav ntawm qhov ntawd, thaum txhua lwm yam khoom siv ntawm Raspberry Pi.

RGB NeoPixel Nplhaib

Nov yog lub nplhaib me me uas muaj 12 RGB leds (koj tuaj yeem yuav lub nplhaib loj 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.

Txheej txheem cej luam:

LCD Zaub 16x2

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

Cov ntaub ntawv:

Raspberry Pi 3B+ & 16GB SD Card

Kuv txoj haujlwm tag nrho khiav ntawm kuv Raspberry Pi 3B+ nrog cov duab teeb tsa, uas kuv yuav pab koj teeb tsa tom qab hauv kuv cov lus qhia.

GPIO T-Tshooj, 2 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 tau siv GPIO T-ntu yog li kuv muaj chaw ntau dua thiab nws yog qhov tseeb uas tus pin yog qhov twg.

Kauj ruam 2: Schematic thiab thaiv

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

Txog kuv cov txheej txheem Kuv tau siv Fritzing, nws yog qhov 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:

Yog li xyuas kom koj txuas txhua yam hauv txoj kev yog! Hauv kuv qhov xwm txheej cov xim ntawm cov xov hlau tsis zoo ib yam li ntawm cov phiaj xwm.

Kauj Ruam 3: Tsim Database

Tsim Database
Tsim Database

Peb tab tom khaws ntau cov ntaub ntawv los ntawm 3 lub cim txuas nrog, yog li peb xav tau cov ntaub ntawv khaws cia cov ntaub ntawv thiab cov cim ntsuas hauv. Tab sis ua ntej tsim cov ntaub ntawv lossis ERD (Daim Duab Txheeb Ze Kev Txheeb Ze) yuav tsum tau ua thiab kuv kuj tseem ua tau zoo nrog 3NF. Tias yog vim li cas peb faib cov sensors mus rau lwm lub rooj thiab ua haujlwm nrog ID's.

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

Kauj Ruam 4: Npaj Raspberry Pi

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

SD Card teeb tsa

Ua ntej tshaj, koj xav tau 16GB SD Card qhov twg koj tuaj yeem tso koj cov duab rau thiab ib qho program kom xa cov duab pib rau SD card.

Software:

Pib duab:

Yog li thaum cov no tau rub tawm:

  1. Muab koj daim npav SD tso rau hauv koj lub computer.
  2. Qhib Win32 uas koj nyuam qhuav rub tawm.
  3. Xaiv Raspbian duab cov ntaub ntawv uas koj tseem nyuam qhuav rub tawm.
  4. Nyem rau 'sau' rau ntawm koj daim npav SD.

Qhov no yuav siv qee lub sijhawm, nyob ntawm koj lub cuab yeej. 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.

  1. Mus rau koj daim npav SD npe, tshawb cov ntaub ntawv npe 'cmdline.txt' thiab qhib nws.
  2. Tam sim no ntxiv 'ip = 169.254.10.1' ntawm tib kab.
  3. Txuag cov ntawv.
  4. Tsim cov ntaub ntawv npe 'ssh' yam tsis txuas ntxiv lossis cov ntsiab lus.

Tam sim no koj tuaj yeem muaj kev nyab xeeb tshem tawm daim npav SD los ntawm koj lub khoos phis tawj thiab muab tso rau hauv Raspberry Pi yam tsis muaj 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.

Tam sim no peb xav tswj 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.

Raspi-teeb tsa

sudo raspi-teeb tsa

Dab tsi yog qhov tseem ceeb heev rau txoj haujlwm no yog ntu cuam tshuam, peb yuav tsum ua kom muaj ntau qhov cuam tshuam sib txawv, pab kom txhua qhov cuam tshuam hauv qab no:

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

Tam sim no uas peb tau ua tiav nrog raspi-teeb tsa, cia peb sim thiab txuas nrog internet.

Wi-nkaus kev twb kev txuas

Ua ntej, koj yuav tsum muaj hauv paus rau cov lus txib hauv qab no

sudo -i ua

Thaum koj nyob hauv paus, siv cov lus txib hauv qab no. SSID yog koj lub npe network thiab tus password yog pom tseeb nws yog tus password.

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

Yog tias koj ua yuam kev, koj tuaj yeem tshawb xyuas, hloov kho lossis tshem tawm lub network no los ntawm kev nkag mus rau cov ntaub ntawv ntawd:

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

Hloov tshiab & hloov kho dua tshiab

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

MariaDB Database

Nruab MariaDB database server:

sudo apt-tau nruab mariadb-server

Apache2 Webserver

Nruab Apache2 webserver:

sudo apt nruab apache2

Nab hab sej

Nruab Python:

hloov kho-lwm txoj hauv kev-nruab/usr/bin/sej python /usr/bin/python2.7 1

hloov kho-lwm txoj kev-nruab/usr/bin/nab nab sej/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
  • Kev thov
  • Nab hab sej
  • RPi. GPIO
  • Gevent
  • Gevent-websocket
  • Ujson
  • Wsaccel

Hais lus tsev qiv ntawv

Nruab ib lub tsev qiv ntawv hais lus los ntawm Adafruit:

curl -sS https://raw.githubusercontent.com/adafruit/Raspbe… | tsoo

Lub sijhawm rov pib dua

sudo rov pib dua

Kauj Ruam 5: Tshaj Tawm Engineering Peb Lub 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!

Yog li ua ntej peb yuav tsum tau xa cov kws tshaj lij peb cov ntaub ntawv hauv MySql workbench, thaum ua qhov ntawd, theej koj cov lej database tag thiab rho tawm txhua lo lus 'pom' hauv nws. Yog li ib zaug uas tau theej, cia qhib qhib dua, nkag mus thiab ntaus:

sudo siv mysql

thiab tam sim no koj nyob hauv mysql interface, luam koj cov lej database hauv nws thiab nias sau.

Tam sim no peb tsuas yog xav tsim tus neeg siv

CREATE USER 'user' IDENTIFIED BY 'user';

ZOO TSHAJ PLAWS NTAWM *. * TO 'user';

Tam sim no reboot.

Yog li txhua yam yuav tsum teeb tsa tam sim no, koj tseem tuaj yeem txuas nrog koj li Pi thiab MySql Workbench, yog li nws yooj yim dua los txheeb xyuas txhua cov ntaub ntawv hauv koj lub rooj.

Kauj Ruam 6: Kho Bluetooth ntawm Peb RPi

Peb tab tom tsim tus hais lus Bluetooth, yog li qhov no txhais tau tias kev tshaj xov xwm tau xa los ntawm peb qhov chaw mus rau Raspberry Pi thiab qhov no tuaj yeem ua tiav yooj yim zoo nkauj, cia peb mus rau qhov yog!

Kuv qhov chaw rau kev txuas bluetooth:

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 on

Teem ib tus neeg sawv cev ua khub

agent rau

default-neeg sawv cev

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 tau txuas nrog peb Raspberry thiab koj yuav tsum muaj peev xwm ua si xov xwm los ntawm koj lub cuab yeej ntawm tus hais lus Pi.

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 PyCharm rau kuv tag nrho cov backend, koj tsuas yog xav kom paub tseeb tias koj txoj haujlwm PyCharm txuas nrog koj li Raspberry Pi, qhov no txhais tau tias koj txoj kev xa khoom tau teeb tsa hauv koj qhov chaw thiab koj teeb tsa txhua pob khoom peb xav tau, yuav tsum tau ua tiav 4

Kuv siv kuv tus kheej cov chav kawm thiab cov no tseem suav nrog hauv kuv GitHub. Txuas yog nyob rau hauv intro yog tias koj plam nws;)

Hauv kuv cov ntaub ntawv backend kuv siv chav kawm threading, yog li txhua yam tuaj yeem ua haujlwm tib lub sijhawm thiab nws yuav tsis cuam tshuam ib leeg. 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 & CSS tau ua tiav yooj yim zoo, sim ua haujlwm mobile ua ntej ntau li ntau tau, txij li peb feem ntau txuas nrog Bluetooth los ntawm lub xov tooj ntawm tes, nws yuav yooj yim dua los tswj los ntawm lub xov tooj ntawm tes.

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 nyuaj li, 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.

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

Kuv xub pib nrog qee qhov kev 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.

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 pib los ntawm rooj plaub rau fwj cawv thiab nyuam qhuav pib pom ntoo. Thaum kuv muaj kuv cov ntaub ntawv tseem ceeb, Kuv tsuas yog yuav tsum tau hle qhov hauv nws (ntau ntawm ntawm lub hauv ntej ntawm rooj plaub, zoo li koj tuaj yeem pom ntawm cov duab: P) thiab muab qee cov ntsia hlau tso rau hauv, nws yog rooj plaub tiag tiag, tab sis nws zoo nkaus li txias thiab haum zoo meej.

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.

Kauj Ruam 10: Qee Qhov Teeb Meem Kuv Muaj Ntawm Kuv Txoj Kev Tsim Lub Slimbox Hais Lus…

Bluetooth & bluealsa yuam kev

Txhua lub sijhawm kuv xav ua suab paj nruag lossis txuas nrog bluetooth, kuv tau txais yuam kev los ntawm bluetooth thiab bluealsa. Kuv tau ua qee qhov kev tshawb fawb txog nws thiab qhov no yog kev daws teeb meem rau kuv. Yog li rau qee qhov laj thawj kuv bluetooth tau raug kaw, tsis paub tseeb tias qhov no yog tus qauv mos-thaiv. Koj tuaj yeem pom yog nws yog los ntawm kev ntaus cov lus txib hauv qab no hauv koj cov Putty.

rfk lis

Yog li yog tias nws yog softblocked, tsuas yog siv qhov no:

rfkill unblock bluetooth

Thiab koj yuav xav rov pib dua tom qab qhov no, kuv qhov chaw:

Teeb meem kev txuas txuas

Yog li lwm qhov teeb meem loj uas kuv muaj yog tias kuv tsis tuaj yeem txuas nrog kuv Arduino los ntawm qib hloov pauv, tom qab qee qhov kev tshawb nrhiav kuv pom tias kuv '/dev/ttyS0' tau ploj mus thiab qhov no tuaj yeem yog vim hloov tshiab ntawm koj RPi. Kuj pom kev daws teeb meem ntawm qhov no

Koj yuav tsum tau rov ua kom muaj kev sib txuas nrog nrog raspi-teeb tsa, rov pib dua, thiab tom qab ntawd tshem tawm tus kheej "console = serial0, 115200" me ntsis los ntawm '/boot/cmdline.txt'Confirm tias "enable_uart = 1" yog' /boot/config.txt ', thiab rov pib dua. Qhov ntawd yuav tsum tau txais koj qhov chaw nres nkoj ttyS0 rov qab, ntxiv rau'/dev/serial0 'txuas txuas rau nws.

Tau qhov twg los:

Pom zoo: