Cov txheej txheem:

Raspberry Pi IoT Foosball Table: 11 Cov Kauj Ruam
Raspberry Pi IoT Foosball Table: 11 Cov Kauj Ruam

Video: Raspberry Pi IoT Foosball Table: 11 Cov Kauj Ruam

Video: Raspberry Pi IoT Foosball Table: 11 Cov Kauj Ruam
Video: Raspberry Pi IoT Server Tutorial: InfluxDB, MQTT, Grafana, Node-RED & Docker 2024, Kaum ib hlis
Anonim
Raspberry Pi IoT Foosball Table
Raspberry Pi IoT Foosball Table

Zoo siab txais tos rau kuv cov lus ntawm hacked rooj foosball, raws li ib feem ntawm cov tub ntxhais kawm txoj haujlwm rau Kev Tshaj Tawm Tshiab thiab Kev Sib Txuas Lus thev naus laus zis. Kuv pib loj hlob nyob ib puag ncig foosball thiab cov rooj hauv pas dej yog li kuv xav tias nws yuav zoo los sim txuas ib qho ntawm cov cuab yeej no rau hauv internet.

Lub ntsiab teeb tsa yog siv lub rooj foosball uas twb muaj lawm txuas nrog Raspberry Pi uas tuaj yeem ua txhua yam haujlwm hauv qab no:

  • Siv GPIO pins los tsav IR LED/Txais thiab 8 x 8 dot matrix modules
  • Khiav Flask lub vev xaib siv nginx
  • Khiav MySQL/MariaDB database rau khaws cov ntaub ntawv

Txhawm rau kom rov tsim txoj haujlwm no koj yuav xav tau cov txuj ci hauv qab no:

Backend:

  • Nkag siab HTML/CSS/Javascript rau cov neeg siv khoom ntawm lub vev xaib
  • Nkag siab txog Python nrog Flask/Flask-SocketIO/Jinja2 rau server sab ntawm lub vev xaib
  • Kev paub pib ntawm MySQL
  • Paub yuav ua li cas khiav lub vev xaib

Tsab ntawv

  • Kev paub yooj yim txog yuav xaim hluav taws xob hluav taws xob li cas
  • Soldering
  • Kev nkag siab yooj yim ntawm yuav sau tsab ntawv hauv Python li cas
  • Ua haujlwm nrog Linux (Raspbian)
  • Muaj kev ua siab ntev ntau vim tias yuav muaj ntau qhov kev debug cuam tshuam nrog

Kauj Ruam 1: Cov Khoom Siv

Nov yog cov npe nrog txhua qhov tsim nyog rau lub rooj:

  • Raspberry Pi Model 3 (nrog casing)
  • T-Cobbler rau txuas tus Pi mus rau lub khob cij
  • Foosball lub rooj (Kuv siv lub rooj qub qub zoo ib yam li qhov no. Yuav tsum txaus siab los laum qhov hauv nws)
  • MAX7219 Arduino Dot Matrix Module (2)
  • IR LED Emitters (2+ vim tias lawv tawg, zoo ib yam li qhov no)
  • IR Txais (2+ vim tias lawv kuj tawg, zoo ib yam li qhov no)
  • Basic solderless breadboard
  • Ntau thiab ntau ntawm cov xaim (nyob ntawm qhov loj ntawm lub rooj foosball)
  • txiv neej txuas (30+)
  • poj niam txuas (10+)
  • 100-220 Ohm Resistors (4+)
  • cov khoom siv soldering
  • cov hlua hlau
  • LED tuav
  • qee cov ntoo/ntsia hlau yog tias koj xav xa pob mus rau hauv lub qhov dej

Tus nqi tag nrho ntawm txoj haujlwm no nyob ntawm tus nqi ntawm koj lub rooj foosball (kim). Dhau li ntawm lub rooj cov ntaub ntawv yuav siab tshaj 150 euros.

Kauj Ruam 2: Cov Hluav Taws Xob Hluav Taws Xob

Cov Hluav Taws Xob Hluav Taws Xob
Cov Hluav Taws Xob Hluav Taws Xob
Cov Hluav Taws Xob Hluav Taws Xob
Cov Hluav Taws Xob Hluav Taws Xob
Cov Hluav Taws Xob Hluav Taws Xob
Cov Hluav Taws Xob Hluav Taws Xob

Ua ntej koj sim ua kom sov, sib sau ua ke tag nrho cov khoom Kuv pom zoo kom sim nws ntawm lub khob cij ua ntej. Nws yog qhov yooj yim los hloov cov khoom ua tsis raug ua ntej koj tau siv sijhawm teev lawv.

Thaum xub thawj kuv tau sim siv 8x8 LED Matrix nrog rau 74HC595 hloov npe (thawj daim duab) thiab cov transistor array tab sis vim muaj ntau cov xov hlau thiab cov zis tsawg heev kuv hloov mus rau MAX7219 Dot Matrix Module vim tias nws tsuas siv 5 lub xov hlau thiab ncaj qha tsav los ntawm tsheb npav SPI.

Lub Circuit Court kuv thaum kawg siv tau kos nrog Fritzing. Thov nco ntsoov tias IR LEDS thiab Cov Tau Txais tuaj yeem txuas nrog ib qho ntawm koj li GPIO Pins pub dawb.

Cov Neeg Txais IR thiab LED yuav tsum ncaj qha hla ib leeg thiab sab saum toj ntawm LED yuav tsum tau taw qhia rau tus txais. Vim tias peb xav sim qhov nqaj ncaj uas tuaj yeem tawg los ntawm kev txav pob hauv qhov xwm txheej yuav muaj lub xeev hloov pauv ntawm DATA kab ntawm tus txais los ntawm 0 txog 1.

Kauj Ruam 3: Coding Sensors

Coding cov Sensors
Coding cov Sensors

Kuv tau sau qhov feem ntau ntawm txoj haujlwm no siv Pycharm vim nws tso cai yooj yim SSH xa mus rau koj li Raspberry Pi siv tus neeg txhais lus nyob deb. Kuv yuav tsis nthuav dav li yuav ua li cas txoj haujlwm no ua haujlwm tab sis muaj ntau cov ntaub ntawv tuaj yeem pom ntawm lub vev xaib pycharm.

Tam sim no kuv tseem tab tom ua haujlwm ntawm qhov project tab sis thaum txhua yam ua tiav tag nrho txoj haujlwm yuav muaj nyob ntawm kuv qhov profile github

Cov cai rau lub ntsuas ntsuas muaj 3 chav kawm uas tau ua haujlwm hauv keeb kwm yav dhau los ntawm kuv Flask server (uas yuav piav qhia tom qab):

  1. Lub Hom Phiaj Chav Kawm (txuas) -Cov ntaub ntawv no pib ua txhua yam sib cais, uas tuaj yeem raug hu los ntawm kev nkag mus rau lub cuab yeej SPI raug/tsheb npav thiab tus lej tus lej
  2. Chav Kawm Matrix (txuas) -Qhov no yog chav kawm tseem ceeb kom txhawb nqa MAX7219 tus qauv
  3. LED thiab Txais Cov Chav Kawm (txuas) - Qhov no yog chav kawm tseem ceeb los txhawb lub zog tawg infrared siv cov xov sib cais los txo CPU load ntawm RPi

LED thiab tus txais ob qho tib si ua haujlwm ntawm 38kHz zaus thiab cov txais tau ib txwm cia siab tias 50% nce thiab 50% nqes tes ua haujlwm kom raug.

Kauj Ruam 4: Npaj thiab tso cov Sensors

Npaj thiab Tso Cov Cuab Yeej
Npaj thiab Tso Cov Cuab Yeej
Npaj thiab Tso Cov Cuab Yeej
Npaj thiab Tso Cov Cuab Yeej
Npaj thiab Tso Cov Cuab Yeej
Npaj thiab Tso Cov Cuab Yeej

Tam sim no peb tab tom npaj IR LED thiab tus txais. Hauv daim duab ntawm lub rooj koj tuaj yeem pom cov chaw nyob qhov twg RPi thiab cov ntsuas yuav tsum tau muab tso rau.

Tab sis ua ntej peb yuav tsum npaj cov thaiv:

  1. Xyuas kom tseeb tias koj ntsuas tus nqi xaim xav tau los ntawm RPi/qhov chaw ntim khoom rau lub sensor qhov chaw
  2. Solder IR tus txais tus pin rau ib kawg ntawm cov xaim (COM/GND/V+)
  3. Muab cov txiv neej txuas rau ntawm lwm qhov kawg ntawm xaim

Tam sim no peb tab tom npaj lub rooj:

  1. Ua ib daim duab yooj yim (raws li daim duab) nyob qhov twg los laum. Nws yog ib qho tseem ceeb heev uas 2 qhov sib dhos ua ke ib leeg vim tias qhov no yuav yog qhov chaw nqaj.
  2. Laum qhov
  3. Yog tias koj muaj qee tus tuav LED (txuas) koj tuaj yeem tso cov no sab hauv lub qhov kom nws khov dua
  4. Ntxig + kab xev LED + tus txais ntawm ob sab
  5. Pluaj cov xov hlau + kaw lawv rau ntawm ntoo kom lawv tsis txhob hla dhau
  6. Ntxig tus txiv neej tus pin rau ntawm lub khob cij raws li qhov muab rau yav dhau los

Kauj Ruam 5: Npaj thiab tso Matrix Module

Npaj thiab Muab Cov Qauv Matrix
Npaj thiab Muab Cov Qauv Matrix

Tom ntej no peb yuav txuas 2 LED matrix modules

Nco tseg:

Vim tias kuv tau siv lub rooj foosball qub twb muaj lub qhov nkag mus rau sab saud vim yog cov neeg haus luam yeeb. Yog tias koj tsis muaj cov no koj yuav xav tsim lawv.

Txhawm rau npaj cov xov hlau:

  1. Ntsuas cov xaim los ntawm daim phiaj rau sab saum toj ntawm lub rooj
  2. Kuaj qee tus poj niam txuas rau thawj qhov kawg ntawm xaim
  3. Solder qee tus txiv neej txuas rau lwm qhov kawg ntawm xaim

Tso qhov matrix:

  1. Nqa tawm cov lej los ntawm lub qhov nyob rau sab saum toj
  2. Pluaj + kaw cov xov hlau sab hauv ntawm ntoo kom tsis txhob hla hla
  3. Ntxig tus txiv neej tus pin rau ntawm lub khob cij raws li qhov tau muab yav dhau los

Nyob rau qee kis kuv yuav ntxiv me me DIY kauj ruam ntxiv rau qhov casing rau matrix module, tab sis tam sim no lawv liab qab.

Kauj Ruam 6: Ua Nws IoT

Ua Nws IoT
Ua Nws IoT

Yog tias koj tsuas yog xav sau npe thiab tso tawm cov qhab nia, koj tuaj yeem ua tiav qhov haujlwm los ntawm kev sau me me ua kab ntawv nab nab uas tig mus txog thaum ib ntawm cov qhab nia nce mus txog 9 thiab tom qab ntawv rov pib dua.

Txawm li cas los xij yog tias koj xav txuas koj lub rooj rau hauv is taws nem ob peb kauj ruam tom ntej yuav tsum yog txoj hauv kev ntawm koj txoj kev.

Hauv ob peb kauj ruam tom ntej peb yuav hais txog cov hauv qab no:

  • Configuring Raspberry Pi
  • Ua ib lub database rau cia
  • Tsim lub vev xaib
  • Tso nws hauv online

Txog ntawm qhov no, yog tias koj paub nrog git, Kuv xav kom koj ua lub chaw cia khoom ntawm GitHub/GitLab kom taug qab koj cov ntaub ntawv. Yog tias koj tsis yog koj tuaj yeem tsim daim nplaub tshev uas muaj tus qauv zoo ib yam li hauv daim duab.

Txoj haujlwm tag nrho yuav muaj sai sai no ntawm GitHub. Txawm li cas los xij cov ntaub ntawv rar ib ntus nrog txhua cov ntaub ntawv tsim nyog muaj.

Kauj Ruam 7: Txuas Raspberry Pi

Tom ntej no peb yuav teeb tsa raspberry pi ib puag ncig, txhawm rau ua qhov no koj yuav tsum tau ua raws cov theem hauv qab no:

  • Txuas hla SSH rau koj Rasberry Pi (koj tuaj yeem siv PuTTY)
  • Tsim daim nplaub tshev (piv txwv mkdir project) thiab txav mus rau daim nplaub tshev no siv cov lus txib cd
  • Tsim virtual Python ib puag ncig hauv daim nplaub tshev no siv cov nab hab sej 3 -m venv --system-site-packages env hais kom ua
  • Qhib tus neeg txhais lus virtual nrog lub hauv paus/env/bin/qhib cov lus txib
  • Nruab cov pob khoom los ntawm cov tseev kom muaj. Txt nrog nab hab sej -m pip nruab pob -npe hais kom ua
  • Hloov cov ntaub ntawv los ntawm qhov muab yav dhau los project_example.rar cov ntaub ntawv hla SSH hauv koj cov phiaj xwm phiaj xwm

Tam sim no koj yuav tsum tuaj yeem ua tiav txoj haujlwm tag nrho ntawm koj li Raspberry Pi. Kuv qhia koj kom siv Python IDE zoo li PyCharm uas tso cai rau koj siv koj los debug los ntawm koj tus neeg txhais lus nyob deb tshaj SSH thiab ncaj qha upload hloov yog tsim nyog.

Kauj Ruam 8: Teeb tsa Lub Database

Kev teeb tsa lub Database
Kev teeb tsa lub Database

Tam sim no koj yuav tsum teeb tsa lub hauv paus yooj yim heev, raws tus qauv no.

Txoj hauv kev yooj yim tshaj plaws nrog rau qhov no yog tsim koj li database hauv MySQL workbench qhov twg koj tseem tuaj yeem ua qee qhov kev sim.

Thaum ua tiav koj tuaj yeem xa cov ntaub ntawv pov tseg ntawm koj cov ntaub ntawv thiab xa nws mus rau koj li RPi thiab tom qab ntawd ua nws nrog sudo mariadb <pathtofile/file.sql

Kauj Ruam 9: Tsim Lub Vev Xaib

Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib
Tsim Lub Vev Xaib

Tom ntej no koj tuaj yeem txheeb xyuas (thiab siv) cov cai muab hauv cov ntaub ntawv project_example.rar.

Cov ntaub ntawv tseem ceeb yog Flask.py uas yog qhob cij thiab butter ntawm txoj haujlwm no:

  • Khiav Flask-SocketIO app uas ua haujlwm rau lub backend ntawm lub vev xaib
  • Tsim kev sib txuas ntawm cov database thiab Flask
  • Muab kev nkag mus siv tau thiab tus neeg siv sau npe
  • Muab cov cai tsim nyog yuav ua li cas ua si game siv socketio los hloov kho lub vev xaib lub sijhawm tiag tiag thaum ua si
  • Muab cov txiaj ntsig kev ua si tso rau hauv lub database

Hauv cov ntawv zoo li qub thiab tus qauv koj tuaj yeem nrhiav tus HTML/CSS/JS uas muab qhov ua ntej ntawm lub vev xaib. Xav tias dawb los hloov cov no raws li koj tus kheej nyiam.

Kauj ruam 10: Txuas mus rau Lub Ntiaj Teb Thoob Ntiaj Teb

Txhawm rau txuas peb lub vev xaib mus rau lub vev xaib peb yuav siv nginx thiab uwsgi. Hauv qhov piv txwv ntawm qhov project koj tuaj yeem pom cov ntaub ntawv tsim nyog hauv daim nplaub tshev conf.

Ua ntej tshaj plaws koj yuav tsum hloov kho cov hauv qab no hauv cov ntaub ntawv no:

  • Hauv uwsgi-flask.ini koj xav tau hloov txoj hauv kev ntawm virtualenv parameter rau koj tus neeg txhais lus
  • Hauv qhov project1-flask.service koj xav tau hloov kho [Kev Pabcuam] ib feem ntawm cov ntawv nrog koj daim ntawv pov thawj thiab txoj hauv kev rau cov ntaub ntawv cuam tshuam
  • Hauv cov ntaub ntawv nginx koj xav tau hloov kho cov neeg rau zaub mov thiab qhov chaw / txoj hauv kev rau koj lub qhov txhab sib txuas

Tom ntej no koj yuav tsum hloov qhov default nginx webserver file nrog qhov chaw ntawm koj li nginx teeb tsa cov ntaub ntawv, hauv qab no yog piv txwv ntawm linux txib kom ua qhov no

  • kuv@kuv-rpi: ~/project1 $ sudo cp conf/nginx/etc/nginx/sites-available/project1
  • kuv@kuv-rpi: ~/project1 $ sudo rm/etc/nginx/sites-enabled/defaul t
  • kuv@kuv-rpi: ~/project1 $ sudo ln -s/etc/nginx/sites-available/project1/etc/nginx/sites-enabled/project1
  • kuv@kuv-rpi: ~/project1 $ sudo systemctl rov pib dua nginx.service

Thaum kawg koj xav tau ntxiv cov kev pabcuam tshwj xeeb rau koj li systemd nplaub tshev, qhov no yog piv txwv yuav ua li cas:

  • kuv@kuv-rpi: ~/project1 $ sudo cp conf/project1-*. service/etc/systemd/system/
  • kuv@kuv-rpi: ~/project1 $ sudo systemctl daemon-reload
  • kuv@kuv-rpi: ~/project1 $ sudo systemctl pib project1-*
  • kuv@kuv-rpi: ~/project1 $ sudo systemctl xwm txheej project1-*

Yog tias koj xav kom lub vev xaib pib ua haujlwm ntawm koj lub raspberry pi koj yuav tsum siv sudo systemctl pab ua haujlwm project1-*.

Yog tias ua tiav, tom qab lub kaw lus rov pib dua koj lub vev xaib yuav tsum tau khiav ntawm koj tus IP chaw nyob. Koj yuav tsum xav kho ib qho ntawm cov ntaub ntawv teeb tsa no koj ib txwm xav tau nres qhov kev pabcuam, rov qhib cov ntaub ntawv thiab siv daemon-reload hais kom ua tom qab pib, txwv tsis pub qhov kev hloov pauv yuav tsis ua haujlwm.

Kauj ruam 11: Tiav Tawm

Tiav Tawm
Tiav Tawm

Thaum ntaus qhov kawg ntawm cov lus qhia no, txoj haujlwm me me hauv tsev kawm ntawv no tseem tab tom ua haujlwm.

Kuv tau siv sijhawm ntau teev los ua qhov no tiav hauv 2.5 lub lis piam. Txawm hais tias txhua yam tau maj nrawm me ntsis Kuv tseem txaus siab rau qhov kuv tau ua tiav. Thaum lub sijhawm sib dhos ua ke kuv tau ntsib ntau qhov yoov/yuam kev/ua tsis tau zoo yog li tsis txhob poob siab yog tias txhua yam tsis ua haujlwm thawj zaug.

Qhov zoo tshaj plaws uas koj tuaj yeem ua tau yog nug lossis nrhiav kev pab hauv is taws nem, muaj ntau tus neeg uas muaj kev paub zoo dua uas muaj lub siab xav pab koj.

Qhov kawg tab sis tsis kawg kuv xav ua tsaug rau kuv cov kws qhia ntawv los ntawm New Media thiab Kev Sib Txuas Lus Tshuab rau muab tswv yim ntau rau kuv thiab pab kuv kom ua tiav txoj haujlwm no.

Pom zoo: