Cov txheej txheem:

Raspberry Tank Nrog Web Interface thiab Video Streaming: 8 Cov Kauj Ruam (nrog Duab)
Raspberry Tank Nrog Web Interface thiab Video Streaming: 8 Cov Kauj Ruam (nrog Duab)

Video: Raspberry Tank Nrog Web Interface thiab Video Streaming: 8 Cov Kauj Ruam (nrog Duab)

Video: Raspberry Tank Nrog Web Interface thiab Video Streaming: 8 Cov Kauj Ruam (nrog Duab)
Video: Часы G Shock до 100 долларов-15 лучших часов Casio G Shock до 100 дол... 2024, Hlis ntuj nqeg
Anonim
Raspberry Tank Nrog Web Interface thiab Video Streaming
Raspberry Tank Nrog Web Interface thiab Video Streaming

Peb yuav mus saib yuav ua li cas kuv tau pom me ntsis WiFi Tank, muaj peev xwm ntawm tej thaj chaw deb tswj lub vev xaib thiab Video Streaming.

Qhov no yog npaj los ua kev qhia uas xav tau kev paub yooj yim ntawm hluav taws xob thiab software software. Vim li no kuv tau xaiv lub Tank chassis Kit (tsis txhob luam nws siv 3D tshuab luam ntawv, tej zaum yuav tau hloov kho tom qab) thiab tag nrho ntawm 6 yam khoom suav nrog roj teeb. Ntawm software sab koj tuaj yeem ua raws cov kauj ruam ib kauj ruam txheej txheem kev teeb tsa thiab kev ua haujlwm raug khaws cia yam tsawg kawg nkaus, kev paub pib ntawm Raspberry yam tuaj yeem pab tau.

Kuv tau kwv yees 12 teev ntawm kev ua haujlwm los ntawm 0 kom npaj tau khiav lub tank. Tag nrho tus nqi 70 € rau txhua qhov khoom siv.

Kauj ruam 1: BOM

BOM
BOM
BOM
BOM
BOM
BOM
BOM
BOM

1 - DIY RC Neeg Hlau Chassis Tank - 32 (€)

www.banggood.com/DIY-RC-Robot-Chassis-Tan…

1 - Dual Channel L298N DC Tsav Tsav Tsav Tsheb - 1, 39 (€)

www.banggood.com/Dual-Channel-L298N-DC-Mo…

1 - Raspberry Pi Zero W Starter Kit - 26 (€)

amzn.eu/1ugAaMP

1 - 16 GB SD Card - 5,50 (€)

www.gearbest.com/memory-cards/pp_337819.h…

1 - Raspberry Pi 5MP Lub Koob Yees Duab Module Webcam rau Qauv Xoom - 8 (€)

www.gearbest.com/raspberry-pi/pp_612249.h…

1 - Power Bank 5V

1 - 9v roj teeb

Sib tov Breadboard Cable Dupont Connector

Mouse, keyboard, Saib lossis TV rau Raspberry teeb (xaiv tau, tsuas yog ua thawj zaug teeb tsa yooj yim dua)

Kauj Ruam 2: Cov Txheej Txheem Tseem Ceeb Tshwj Xeeb

Tsav

JGA25-370 DC gearmotor

Lub cav no muaj lub ntsej muag D-zoo li tus ncej.

Kev qhia tshwj xeeb

· Ua haujlwm voltage: nruab nrab ntawm 6 V thiab 18 V

· Nominal voltage: 12 V

· Kev khiav ceev dawb ntawm 12 V: 399 RPM

· Ua haujlwm pub dawb ntawm 12 V: 50 mA

· Khw tam sim no ntawm 12V: 1200 mA

· Stall torque ntawm 12V: 2.2 kg.cm

· Iav piv: 1:21

· Qhov loj me me: 19 hli

Qhov hnyav: 84g

Dual Channel L298N DC Tsav Tsav Tsav Tsheb

Dual H-choj tsav tsheb, tuaj yeem tsav ob lub cav DC lossis 4-hlau ob-theem stepper motors. Built-in TSD, los tiv thaiv los ntawm lub cav nres.

Kev qhia tshwj xeeb

· Cov khoom siv hluav taws xob: DC 2V-10V

· Teeb liab qhov hluav taws xob: DC 1.8-7V

· Ib leeg ua haujlwm tam sim no: 1.5A

· Peak tam sim no txog 2.5A

· Tsawg standby tam sim no (tsawg dua 0.1uA)

· Ua-nyob rau hauv ib qho kev coj ua hluav taws xob, lub davhlau ya nyob twg nkag tsis tau, lub cav tsis ua haujlwm

· Loj: 24.7 x 21 x 7mm

Kauj ruam 3: WIRING

HLOOV
HLOOV
HLOOV
HLOOV

Qhov no yuav yog qhov txuas kawg, tab sis WAIT, ua ntej peb xav tau los nruab qee qhov

software thiab nws yog lub tswv yim zoo los ntsuas nws nrog cov kab yooj yim dua, thaum npaj tau rov qab los ntawm no.

Peb xav tau ob lub zog sib txawv, ib qho rau lub cev muaj zog thiab ib qho rau Raspberry.

Tus tsav tsheb Dual Channel L298N DC Tsav Tsav Tsav Tsav Tsheb (qhov siab tshaj qhov hluav taws xob DC 2V-10V) tau siv los ntawm kev siv 9V roj teeb thiab Raspberry Pi siv cov qauv 5V USB accumulator.

GND tus pin ntawm tus tsav tsheb yuav txuas nrog lub roj teeb rho tawm thiab Raspberry Pi (GND). GPIO pins ntawm Raspberry Pi txuas nrog tus tsav tsheb raws li lub rooj.

Kauj Ruam 4: Npaj RASPBERRY O. S

Nov yog tus txheej txheem teeb tsa rau Raspbian cov haujlwm ua haujlwm, koj tuaj yeem pom

ntau cov ncauj lus qhia ntxaws tshawb hauv lub vev xaib, cov theem pib yog:

1. Rub iso RASPBIAN STRETCH NROG DESKTOP los ntawm

2. Format 16 GB SD Card, Kuv tau siv SD Formatter

3. Hlawv. IMG cov ntaub ntawv, Kuv tau siv Win32DiskImager

Tam sim no koj cov raspberry tau npaj rau khau raj, txuas nws mus rau USB lub zog siv hluav taws xob (5V, 2A) thiab npaj rau kev teeb tsa thawj zaug. Koj tuaj yeem ua nws hauv ob txoj hauv kev, siv cov cuab yeej sab nraud zoo li nas, keyboard thiab saib xyuas lossis siv koj lub PC thiab kev sib txuas deb ntawm Raspberry. Muaj ntau qhov kev qhia txog qhov no, ib qho yog:

Kauj Ruam 5: YUAV UA LI CAS tswj peb lub WIFI TANK nrog NODE. JS THIAB WEBSOCKET. IO

YUAV UA LI CAS tswj peb lub WIFI TANK nrog NODE. JS THIAB WEBSOCKET. IO
YUAV UA LI CAS tswj peb lub WIFI TANK nrog NODE. JS THIAB WEBSOCKET. IO

Tam sim no peb muaj kev teeb tsa tshiab ntawm peb Raspberry micro PC npaj los ua peb txoj haujlwm, yog li … peb siv dab tsi los tso cov lus txib rau lub tank?

Python yog ib qho yooj yim heev rau siv cov lus uas nquag siv los ua haujlwm Rapsberry cov xuab zeb tuaj yeem siv tau yooj yim kuj tseem cuam tshuam nrog Rapsberry cov tswv yim thiab cov pins tso tawm (GPIO)

Tab sis, kuv lub hom phiaj yog txhawm rau txuas kuv lub tank wi-fi los ntawm ib qho khoom siv (PC, xov tooj ntawm tes, ntsiav tshuaj …) siv lub vev xaib sib txuas thiab tseem tso cov vis dis aus los ntawm nws. Yog li, hnov qab Python tam sim no, thiab cia txav mus rau NODE. JS thiab SOCKET. IO.

NODE.js

Node.js (https://github.com/nodejs/node/wiki) yog qhov qhib qhov server server ua haujlwm raws li lus js. Txij li thaum kuv siv Raspberry Pi Zero (ARMv6 CPU) peb tsis tuaj yeem siv cov txheej txheem teeb tsa tsis siv neeg (npaj rau ARMv7 CPU) thiab peb yuav tsum ua nws tus kheej:

Rub tawm Nodejs hauv zos, (Kuv tau siv 7.7.2 version rau ARMv6, txheeb xyuas lwm cov ntawv ntawm no

pi@raspberry: ~ $ wget

nodejs.org/dist/v7.7.2/node-v7.7.2-linux-…

Thaum ua tiav, rho tawm cov ntaub ntawv compressed:

pi@raspberry: ~ $ tar -xzf node-v7.7.2-linux-armv6l.tar.gz

Luam thiab Nruab cov ntaub ntawv rau hauv /user /local

pi@raspberry: ~ $ sudo cp -R node-v7.7.2-linux-armv6l/*/usr/zos/

Ntxiv qhov chaw uas peb teeb tsa nodejs rau txoj hauv kev, kho cov ntaub ntawv ".profile":

pi@raspberry: ~ $ nano ~/.profile

Ntxiv kab hauv qab no ntawm qhov kawg ntawm cov ntawv, txuag thiab tawm

PATH = $ PATH:/usr/local/bin

Tshem cov ntaub ntawv rub tawm:.

pi@raspberry: ~ $ rm ~/node-v7.7.2-linux-armv6l.tar.gz

pi@raspberry: ~ $ rm -r ~/node-v7.7.2-linux-armv6l

Ntaus cov lus txib hauv qab no los tshuaj xyuas nodejs kev teeb tsa:

pi@raspberry: ~ $ node -v

pi@raspberry: ~ $ npm -v

Koj yuav tsum nyeem v7.7.2 thiab v4.1.2 raws li cov lus teb.

Yog tias txhua yam mus tau zoo, tsim daim nplaub tshev tshiab los tuav koj cov ntaub ntawv nodejs:

pi@raspberry: ~ $ mkdir nodehome

Txav mus rau hauv daim nplaub tshev tshiab:

pi@raspberry: ~ $ cd nodehome

Txhim kho cov qauv ntxiv uas yuav tsum tau tswj GPIO hauv txoj hauv kev yooj yim, ON thiab OFF:

pi@raspberry: ~ $ npm nruab onoff

Tam sim no yog lub sijhawm los sim peb thawj qhov haujlwm "Blink.js", qhov txiaj ntsig yuav yog … lub ntsais ntsais LED

pi@raspberry: ~ $ nano blink.js

Muab tshuaj txhuam cov cai hauv qab no, txuag thiab tawm:

var Gpio = xav tau ('onoff'). Gpio; // suav nrog onoff

var LED = tshiab Gpio (3, 'tawm'); // siv GPIO 3

var blinkInterval = setInterval (blinkLED, 250);

// ntsais LED txhua 250ms

muaj nuj nqi blinkLED () {// muaj nuj nqi kom pib ntsais muag

yog

(LED.readSync () === 0) {// xyuas lub xeev tus pin, yog tias lub xeev yog 0 (lossis tawm)

LED.writeSync (1);

// teeb lub xeev tus pin rau 1 (tig LED rau)

lwm yam {

LED.writeSync (0);

// teeb lub xeev tus pin rau 0 (tua LED tawm)

}

}

muaj nuj nqi endBlink () {// muaj nuj nqi kom tsis txhob ntsais muag

clearInterval (blinkInterval); // Tsis txhob ntsais muag ib ntus

LED.writeSync (0); // Tua LED tawm

LED.unexport (); // Unexport GPIO pub dawb cov peev txheej

}

setTimeout (endBlink, 5000); // nres ntsais muag tom qab 5 vib nas this

Hlau ib LED, tus tiv thaiv (200ohms) raws li qhia hauv cov phiaj xwm thiab ua haujlwm:

pi@raspberry: ~ $ node blink.js

Node yog npaj txhij.

SOCKET. IO

WebSocket yog lub khoos phis tawj sib tham sib tham, raws TCP kev sib txuas, nws muab tus programmer los tsim cov server thiab cov neeg siv khoom. Tus neeg siv khoom txuas rau lub server thiab tso tawm thiab tau txais cov lus mus thiab los ntawm tus neeg rau zaub mov. Kev siv WebSocket rau Node.js hu ua Socket.io (https://socket.io/).

Nruab socket.io:

pi@raspberry: ~ $ npm nruab socket.io --save

Tsiv mus rau hauv nodejs tsev, tsim ua ntej:

pi@raspberry: ~ $ cd nodehome

Thiab tsim cov ntawv tshiab "pej xeem":

pi@raspberry: ~ $ mkdir pej xeem

Tsim tus qauv tshiab web server, hu nws "webserver.js"

pi@raspberry: ~ $ nano webserver.js

Muab tshuaj txhuam cov cai hauv qab no, txuag thiab tawm:

var http = xav tau ('http'). createServer (tus tuav); // xav tau http server, thiab tsim server nrog ua haujlwm ua haujlwm ()

var fs = xav tau ('fs'); // xav tau fileystem module

http.listen (8080); // mloog qhov chaw nres nkoj 8080

muaj nuj nqi handler (req, res) {// tsim server

fs.readFile (_ dirname + '/public/index.html', muaj nuj nqi (yuam kev, cov ntaub ntawv) {// nyeem

cov ntaub ntawv index.html hauv cov nplaub tshev pej xeem

yog (yuam kev) {

res.writeHead (404, {'Cov ntsiab lus-Hom': 'ntawv/html'}); // tso saib 404 ntawm qhov ua yuam kev

rov res.end ( 404 Tsis yog

Pom );

}

res.writeHead (200, {'Cov ntsiab lus-Hom': 'ntawv/html'}); // sau HTML

res.write (cov ntaub ntawv); // sau cov ntaub ntawv

los ntawm index.html

rov res.end ();

});

}

Lub vev xaib no yuav mloog koj li Raspberry chaw nres nkoj 8080 thiab muab cov ntaub ntawv rau txhua lub vev xaib uas txuas nrog nws. Tam sim no peb yuav tsum tsim qee yam los tuav thiab muab rau peb cov neeg siv khoom: Tsiv sab hauv "pej xeem" nplaub tshev: pi@raspberry: ~ $ cd pej xeem

Tsim cov ntaub ntawv html tshiab “index.html”:

pi@raspberry: ~ $ nano index.html

Muab tshuaj txhuam tus lej los ntawm txuas "HelloWorld.txt", txuag thiab tawm mus.

Tsiv sab hauv nodejs nplaub tshev "nodehome":

pi@raspberry: ~ $ cd nodehome

Pib HTTP web server:

pi@raspberry: ~ $ node webserver.js

Qhib lub vev xaib hauv qhov browser siv https:// Raspberry_IP: 8080/(hloov Raspberry_IP nrog koj tus IP)

Kauj Ruam 6: TSHUAJ TIV THAIV VIDEO STREAMING CAPABILITY

Muaj ntau txoj hauv kev los siv kev tshaj tawm video ntawm Raspberry, yooj yim dua

txoj kev kuv tau pom txog tam sim no, uas yog kev ua tau zoo thiab tuaj yeem koom ua ke hauv lub vev xaib sib tham yog lub hauv paus ntawm txoj haujlwm los ntawm Miguel Mota:

miguelmota.com/blog/raspberry-pi-camera-bo…

Ua tsaug Miguel! Los ntawm nws blog cov no yog cov kauj ruam:

Nruab cov khoom siv libjpeg8 thiab cmake:

pi@raspberry: ~ $ sudo apt-tau nruab libjpeg8

pi@raspberry: ~ $ sudo apt-tau nruab libjpeg8-dev

pi@raspberry: ~ $ sudo apt-tau nruab cmake

Rub tawm mjpg-streamer nrog raspicam plugin:

pi@raspberry: ~ $ git clone

github.com/jacksonliam/mjpg-streamer.git ~/mjpg-streamer

Hloov cov npe:

pi@raspberry: ~ $ cd ~/mjpg-streamer/mjpg-streamer-sim

Sau:

pi@raspberry: ~ $ ua kom txhua tus huv

Hloov qub mjpg-streamer:

pi@raspberry: ~ $ sudo rm -rf /opt /-j.webp

pi@raspberry: ~ $ sudo mv ~/mjpg-streamer/mjpg-streamer-sim

/opt/mjpg-tso tawm

pi@raspberry: ~ $ sudo rm -rf ~/mjpg -streamer

Tsim cov ntawv tshiab "start_stream.sh", luam thiab muab tshuaj txhuam los ntawm daim ntawv "start_stream.txt".

Ua kom nws ua tiav (tsim cov ntawv sau hauv plhaub):

pi@raspberry: ~ $ chmod +x start_stream.sh

Pib Streaming server:

pi@raspberry: ~ $./start_stream.sh

Qhib lub vev xaib hauv qhov browser siv https:// Raspberry_IP: 9000 (hloov Raspberry_IP nrog koj tus IP)

Kauj Ruam 7: TANK PROGRAM

Txhua yam tau npaj tiav, tam sim no peb yuav tsum tsim peb lub vev xaib los tswj lub tank (index.html) thiab peb lub vev xaib kom mloog peb cov lus txib (webserver.js). Yog li, tsuas yog hloov cov ntaub ntawv pom txog tam sim no (tsuas yog piv txwv los sim lub kaw lus) nrog txuas nrog webserver.txt thiab index.txt.

Kauj Ruam 8: Pib QHIA INTERFACE THIAB STREAMING SERVER

Pib tswj kev sib cuam tshuam thiab STREAMING SERVER
Pib tswj kev sib cuam tshuam thiab STREAMING SERVER

Txhawm rau pib cov kev pabcuam qhib ob lub davhlau ya nyob twg windows thiab khiav cov lus txib no:

ntawm nodehome/webserver.js

./nodehome/start_stream.sh

Qhib lub vev xaib hauv qhov browser siv https:// Raspberry_IP: 8080 (hloov Raspberry_IP nrog koj tus IP)

Pom zoo: