Cov txheej txheem:
- Khoom siv
- Kauj Ruam 1: Tsim Tus Neeg Hlau Platform
- Kauj Ruam 2: Program Robot
- Kauj Ruam 3: Nws Ua Haujlwm Li Cas
- Kauj Ruam 4: Cov Tswv Yim & Cov Nqis
Video: DuvelBot - ESP32 -CAM Npias Pab Neeg Hlau: 4 Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:25
Tom qab ua haujlwm hnyav hnub, tsis muaj dab tsi los ze rau sipping koj nyiam npias ntawm lub rooj zaum. Hauv kuv qhov xwm txheej, qhov ntawd yog Belgian pojniam plaub hau daj "Duvel". Txawm li cas los xij, tom qab tag nrho tab sis sib tsoo peb tau ntsib nrog qhov teeb meem loj tshaj plaws: lub tub yees uas muaj kuv lub Duvel yog qhov tsis tuaj yeem txav 20 taw tawm ntawm lub rooj zaum.
Thaum qee qhov kev quab yuam me me los ntawm kuv ib sab tuaj yeem txav cov tub ntxhais hluas lub tub yees txias tub yees los nchuav tawm kuv lub lim tiam nyiaj pub dawb ntawm Duvel, txoj haujlwm ntawm kev xa nws mus rau nws cov neeg ua haujlwm yuav luag tag yog pom tseeb ib kauj ruam dhau lawm.
Lub sijhawm txhawm rau txhawm rau tshem cov hlau txuas thiab cov keyboard…
DuvelBot yog qhov tsis txaus ntseeg AI-Thinker ESP32-CAM raws lub vev xaib tsav tsheb, uas koj tuaj yeem tswj hwm los ntawm koj lub xov tooj smartphone, browser lossis ntsiav tshuaj.
Nws yooj yim los hloov lossis nthuav lub platform no kom siv cawv tsawg (xav tias SpouseSpy, NeighbourWatch, KittyCam…).
Kuv ua tus neeg hlau no feem ntau yog kawm me ntsis txog tag nrho lub vev xaib thiab IoT khoom, uas kuv tsis paub dab tsi txog. Yog li qhov kawg ntawm Cov Lus Qhia no yog piav qhia ntxaws txog qhov ntawd ua haujlwm li cas.
Ntau qhov ntawm Cov Lus Qhia no yog ua raws cov lus piav qhia zoo nyob ntawm Random Nerd Tutorials, yog li thov mus ntsib lawv!
Khoom siv
Koj xav tau dab tsi:
Daim ntawv teev npe tsis yog carved hauv pob zeb thiab ntau qhov tuaj yeem tau txais hauv ib tuj ntawm ntau qhov sib txawv thiab los ntawm ntau qhov chaw sib txawv. Kuv tau yuav feem ntau los ntawm Ali-Express. Zoo li Machete hais tias: kho kom raug.
Kho vajtse:
- AI Thinker ESP32-CAM module. Nws yuav zaum ua haujlwm nrog lwm ESP32-CAM cov qauv tab sis qhov ntawd yog qhov kuv tau siv
- L298N tsav tsav lub rooj tsavxwm,
- Ib qho pheej yig 4-wheeled neeg hlau platform,
- Ib lub tsev nyob nrog lub tiaj tiaj tiaj zoo li Hammond Electronics 1599KGY,
- USB-rau-3.3V-TTL-hloov pauv rau lub cajmeem.
- Rau teeb pom kev zoo: 3 LEDs dawb, BC327 lossis lwm lub hom phiaj dav dav transistor NPN (Ic = 500mA), 4k7k resistor, 3 82Ohm resistors, perfboard, cables (saib cov duab thiab duab).
- Qhov qhib/tawm toggle hloov thiab ib txwm qhib-qhib lub pob rau lub program.
Yeem:
- Lub koob yees duab fisheye nrog lub zog ntev dua li tus qauv OV2460 lub koob yees duab muab nrog ESP32-CAM module,
- Cov kav hlau txais xov WiFi nrog cov xov txuas ntev txaus thiab Ultra Miniature Coax Connector, zoo li no. ESP32-CAM muaj lub kav hlau txais xov nyob hauv thiab lub tsev yog yas, yog li lub kav hlau txais xov tsis xav tau tiag tiag, txawm li cas los kuv xav tias nws zoo li txias, yog li …
- Inkjet luam tawm daim ntawv nplaum rau sab saum toj tsim.
Cov cuab yeej kho vajtse ib txwm muaj: cov hlau txuas, xyaum ua haujlwm, ntswj ntsia hlau, pliers …
Kauj Ruam 1: Tsim Tus Neeg Hlau Platform
Lub schematic:
Schematic tsis muaj dab tsi tshwj xeeb. ESP32-cam tswj lub cav ntawm L298N lub rooj tsav tsheb tsav, uas muaj ob txoj hauv kev. Cov motors ntawm sab laug thiab sab xis tau muab tso ua ke thiab txhua sab nyob ib sab. Plaub qhov me me 10..100nF cov khoom siv hluav taws xob nyob ze ntawm lub tshuab pins yog ib txwm pom zoo los tawm tsam RF cuam tshuam. Tsis tas li, lub hau hluav taws xob loj (2200… 4700uF) ntawm qhov muab khoom ntawm lub rooj tsav xwm lub cev raws li tau qhia hauv cov txheej txheem, thaum tsis nruj me ntsis xav tau, tuaj yeem txwv cov khoom siv hluav taws xob ripple me ntsis (yog tias koj xav pom cov yeeb yaj kiab txaus ntshai, tom qab ntawd sojntsuam Vbat nrog oscilloscope thaum lub cav ua haujlwm).
Nco tseg tias ob txoj kev tsav tsheb ENABLE pins tau tsav los ntawm tib lub mem tes-dav hloov pauv (PWM) tus pin ntawm ESP32 (IO12). Qhov no yog vim tias ESP32-CAM module tsis muaj tuj ntawm GPIOs (tus qauv cov txheej txheem suav nrog rau siv). Tus neeg hlau LEDs tau tsav los ntawm IO4, uas tseem tsav lub onboard flash LED, yog li tshem Q1 los tiv thaiv lub teeb nyem LED kom pom kev hauv lub tsev kaw.
Txoj haujlwm khawm, qhib/tua hloov, them lub txuas thiab lub tshuab txuas txuas tuaj yeem nkag tau hauv qab tus neeg hlau. Kuv tuaj yeem ua tiav txoj haujlwm zoo dua rau cov phiaj xwm sib txuas (3.5mm jack?), Tab sis npias tsis tuaj yeem tos ntxiv lawm. Tsis tas li tshaj-huab cua-hloov tshiab (OTA) yuav zoo rau teeb tsa.
Txhawm rau muab tus neeg hlau rau hauv hom phiaj, nyem lub pob programming (qhov no rub IO0 qis) thiab tom qab ntawd hloov nws.
Tseem ceeb: kom them lub roj teeb NiMH ntawm tus neeg hlau, siv lub chaw tso khoom tso tawm (tshem tawm) txog li 14V thiab tam sim no txwv rau 250mA. Qhov hluav taws xob yuav hloov pauv mus rau lub roj teeb. Txiav tawm yog tias tus neeg hlau xav tias kub lossis lub roj teeb hluav taws xob nce mus txog 12.5V. Qhov kev txhim kho pom tseeb ntawm no yuav yog kev sib txuas lub roj teeb kom raug, tab sis qhov ntawd yog sab nraud ntawm qhov kev qhia no.
Kho vajtse:
Thov kuj saib cov ntawv hauv cov duab. Lub tsev nyob tau teeb tsa ntawm lub hauv paus neeg hlau siv 4 M4 ntsia liaj qhov rooj thiab ntsuas tus kheej. Nco tseg cov roj hmab tubing siv ua qhov sib nrug deb. Vam tias, qhov no tseem muab qee qhov kev ncua rau Duvel, yog tias lub caij ua pov thawj tsis txaus. ESP32-CAM tus qauv thiab L298N lub rooj tsav tsheb tau teeb tsa hauv lub tsev siv cov yas yas taw (tsis paub meej txog lub npe raug yog lus Askiv), txhawm rau tiv thaiv kom txhob xaum qhov ntxiv. Tsis tas li ESP32 tau teeb tsa ntawm nws tus kheej lub qhov txhab thiab lub taub hau ntsaws ntsaws. Qhov no ua rau nws yooj yim los pauv pauv ESP32.
Tsis txhob hnov qab: yog tias koj tab tom mus nrog WiFi sab nraud antennna hloov chaw ua ib qho, tom qab ntawd kuj tseem txuas lub kav hlau txais xov-xaiv jumper ntawm sab hauv qab ntawm ESP32-CAM board.
Luam tawm lub logo sab saum toj hauv cov ntawv DuvelBot.svg ntawm daim ntawv nplaum daim ntawv (lossis tsim koj tus kheej), thiab koj npaj txhij mus!
Kauj Ruam 2: Program Robot
Nws raug nquahu kom ua haujlwm cov neeg hlau ua ntej koj kaw nws, kom ntseeg tau tias txhua yam ua haujlwm thiab tsis muaj pa luam yeeb tshwm sim.
Koj xav tau cov cuab yeej software hauv qab no:
- Lub Arduino IDE,
- Lub tsev qiv ntawv ESP32, SPIFFS (cov ntaub ntawv txuas ib ntus ib ntus), ESPAsync Webserver lub tsev qiv ntawv.
Qhov kawg tuaj yeem teeb tsa tau los ntawm kev ua raws cov lus qhia hauv qab no mus txog thiab suav nrog ntu "teeb tsa koj cov ntaub ntawv". Kuv yeej tsis tuaj yeem piav qhia nws zoo dua.
Cov cai:
Kuv tus lej tuaj yeem pom ntawm:
- Arduino kos duab DuvelBot.ino,
- Cov ntaub ntawv subfolder uas tuav cov ntaub ntawv uas yuav muab tso rau ESP flash siv SPIFFS. Cov nplaub tshev no muaj lub vev xaib uas ESP yuav ua haujlwm (index.html), lub logo duab uas yog ib feem ntawm lub vev xaib (duvel.png) thiab daim ntawv cascaded lossis CSS cov ntaub ntawv (style.css).
Txhawm rau program tus neeg hlau:
- Txuas lub USB-TTL hloov pauv raws li qhia hauv kab lus,
- Cov Ntaub Ntawv -> Qhib -> mus rau qhov chaw uas DuvelBot.ino nyob.
- Hloov koj li ntawv pov thawj network hauv kab kos:
const char* ssid = "yourNetworkSSIDHere"; const char* password = "yourPasswordHere";
- Cov Cuab Yeej -> Pawg Thawj Coj -> "AI -Thinker ESP -32 CAM" thiab xaiv qhov chaw nres nkoj uas tsim nyog rau koj lub pc (Cov Cuab Yeej -> Chaw Nres Nkoj -> qee yam zoo li /dev /ttyUSB0 lossis COM4),
- Qhib tus lej saib hauv Arduino IDE, Thaum nias lub PROG khawm (uas rub IO0 qis), hloov ntawm tus neeg hlau,
- Txheeb xyuas ntawm cov ntawv saib xyuas uas ESP32 tau npaj rau rub tawm,
- Kaw qhov ntsuas saib (txwv tsis pub SPIFFS upload tsis tau),
- Cuab Yeej -> "ESP32 Sketch Data Upload" thiab tos kom nws ua tiav,
- Hloov tawm thiab rov tuav lub PROG khawm kom rov qab mus rau hom kev ua haujlwm,
- Nias lub pob "Upload" rau qhov program kos duab thiab tos kom nws ua tiav,
- Qhib cov ntawv saib xyuas thiab rov pib dua ESP32 los ntawm kev hloov/qhib,
- Thaum nws tau khau raj, nco ntsoov tus IP chaw nyob (qee yam zoo li 192.168.0.121) thiab txuas tus neeg hlau los ntawm USB-TTL hloov pauv,
- Qhib tus browser ntawm tus IP chaw nyob no. Koj yuav tsum pom lub interface zoo li hauv daim duab.
- Yeem: teeb tsa mac-address ntawm ESP32 rau tus IP chaw nyob hauv koj lub router (nyob ntawm router yuav ua li cas).
Qhov ntawd yog nws! Nyeem rau yog tias koj xav paub nws ua haujlwm li cas…
Kauj Ruam 3: Nws Ua Haujlwm Li Cas
Tam sim no peb los rau qhov txaus siab: nws tag nrho ua haujlwm li cas?
Kuv yuav sim piav qhia nws ib kauj ruam… los ntawm… kauj ruam tab sis thov nco ntsoov Kajnjaps tsis yog tus kws tshaj lij lub vev xaib. Qhov tseeb, kawm me ntsis ntawm lub vev xaib yog qhov tseem ceeb ntawm kev tsim DuvelBot. Yog tias kuv ua yuam kev pom tseeb, thov tawm lus!
Ok, tom qab ESP32 tau hloov pauv, raws li ib txwm muaj hauv kev teeb tsa nws pib GPIOs, koom nrog lawv nrog PWM timers rau lub cev muaj zog thiab LED tswj. Saib ntawm no kom paub ntau ntxiv ntawm kev tswj lub cev muaj zog, nws yog tus qauv zoo nkauj.
Tom qab ntawd lub koob yees duab tau teeb tsa. Kuv txhob txwm khaws cia qhov kev daws teeb meem qis heev (VGA lossis 640x480) kom tsis txhob teb qeeb. Nco tseg AI-Thinker ESP32-CAM pawg thawj coj muaj ntu ntu nti (PSRAM) uas nws siv los khaws lub koob yees duab thav duab ntawm kev daws teeb meem loj dua:
yog (psramFound ()) {Serial.println ("PSRAM pom."); config.frame_size = FRAMESIZE_VGA; config.jpg_quality = 12; config.fb_count = 2; // tus naj npawb ntawm framebuffers pom: https://github.com/espressif/esp32-camera} lwm {Serial.println ("tsis pom PSRAM."); config.frame_size = FRAMESIZE_QVGA; config.jpg_quality = 12; config.fb_count = 1; }
Tom qab ntawd cov txheej txheem txheej txheem txheej txheem txheej txheem txheej txheem txheej txheem txheej txheem (SPIFFS) tau pib:
// initialize SPIFFS yog (! rov qab; }
SPIFFS ua zoo li cov ntaub ntawv me me ntawm ESP32. Nov nws yog siv los khaws peb cov ntaub ntawv: lub vev xaib nws tus kheej index.html, cov ntaub ntawv cascaded styleheet style.css, thiab cov duab-p.webp
Tom ntej no ESP32 txuas rau koj lub router (tsis txhob hnov qab teeb tsa koj daim ntawv pov thawj ua ntej rub tawm):
// hloov daim ntawv pov thawj ntawm koj tus router hereconst char* ssid = "yourNetworkSSIDHere"; const char* password = "yourPasswordHere"; … // txuas rau WiFi Serial.print (“Txuas rau WiFi”); WiFi.begin (ssid, password); thaum (WiFi.status ()! = WL_CONNECTED) {Serial.print ('.'); ncua (500); } // tam sim no txuas nrog lub router: ESP32 tam sim no muaj tus IP chaw nyob
Txhawm rau ua qee yam muaj txiaj ntsig, peb pib asynchronous webserver:
// tsim cov khoom AsyncWebServer ntawm chaw nres nkoj 80AsyncWebServer server (80); … Server.begin (); // pib mloog rau kev sib txuas
Tam sim no, yog tias koj ntaus tus IP chaw nyob uas tau muab rau ESP32 los ntawm tus router hauv qhov browser qhov chaw nyob, ESP32 tau txais kev thov. Qhov no txhais tau tias nws yuav tsum teb rau tus neeg siv khoom (koj, lossis koj tus browser) los ntawm kev ua haujlwm qee yam, piv txwv li lub vev xaib.
ESP32 paub yuav teb li cas, vim tias teeb tsa cov lus teb rau txhua qhov ua tau tso cai thov tau sau npe siv server.on (). Piv txwv li, lub vev xaib tseem ceeb lossis ntsuas (/) tau ua haujlwm zoo li no:
server.on ("/", HTTP_GET, (AsyncWebServerRequest *thov) {Serial.println ("/thov tau txais!"); thov-> xa (SPIFFS, "/index.html", String (), tsis tseeb, tus processor);});
Yog li yog tias tus neeg siv khoom sib txuas, ESP32 teb los ntawm kev xa cov ntaub ntawv index.html los ntawm SPIFFS filesystem. Tus txheej txheem ntsuas yog lub npe ntawm kev ua haujlwm uas tau npaj ua ntej html thiab hloov ib qho tshwj xeeb cim npe:
// Hloov chaw tso rau hauv html zoo li %DATA %// nrog qhov sib txawv koj xav qhia //
Cov Ntaub Ntawv: %DATA %
String processor (const String & var) {if (var == "DATA") {//Serial.println("in processor! "); xa txoj hlua (dutyCycleNow); } rov qab txoj hlua ();}
Tam sim no, cia txheeb xyuas lub vev xaib index.html nws tus kheej. Feem ntau ib txwm muaj peb ntu:
- html code: dab tsi cov ntsiab lus yuav tsum tau qhia (cov nyees khawm/ntawv/sliders/duab thiab lwm yam),
- style code, xws li hauv cais.css ntawv lossis hauv … ntu: cov ntsiab lus yuav tsum zoo li cas,
- javascript a… ntu: yuav ua li cas lub vev xaib yuav tsum ua.
Thaum index.html thauj mus rau qhov browser (uas paub nws yog html vim yog kab DOCTYPE), nws sau rau kab no:
Qhov ntawd yog kev thov rau css style sheet. Qhov chaw ntawm daim ntawv no tau muab rau hauv href = "…". Yog li koj tus browser ua dab tsi? Yog lawm, nws nthuav tawm lwm qhov kev thov rau lub server, lub sijhawm no rau style.css. Tus neeg rau zaub mov ntes qhov kev thov no, vim nws tau sau npe:
server.on ("/style.css", HTTP_GET, (AsyncWebServerRequest *thov) {Serial.println ("css thov tau txais"); thov-> xa (SPIFFS, "/style.css", "text/css ");});
Neat huh? Qhov xwm txheej, nws tuaj yeem yog href = "/qee qhov/ntaub ntawv/ntawm/tus/lwm yam/sab/ntawm/lub/hli", rau txhua qhov koj lub browser tau saib xyuas. Nws yuav mus nqa cov ntawv ntawd zoo li muaj kev zoo siab. Kuv yuav tsis piav qhia txog cov qauv ntawv txij li nws tsuas yog tswj kev tshwm sim yog li nws tsis txaus nyiam ntawm no, tab sis yog tias koj xav kawm paub ntau ntxiv, txheeb xyuas qhov kev qhia no.
Lub DuvelBot logo tshwm sim li cas? Hauv index.html peb muaj:
uas ESP32 teb nrog:
server.on ("/duvel", HTTP_GET, (AsyncWebServerRequest *thov) {Serial.println ("duvel logo thov!"); thov-> xa (SPIFFS, "/duvel.png", "duab-p.webp
..yog lwm cov ntaub ntawv SPIFFS, lub sijhawm no ua tiav cov duab, raws li qhia los ntawm "duab/png" hauv qhov lus teb.
Tam sim no peb los rau qhov txaus nyiam tiag tiag: cov cai rau cov nyees khawm. Cia peb tsom mus rau FORWARD khawm:
TUAJ
Chav kawm = "…" lub npe tsuas yog lub npe los txuas nws mus rau cov ntawv sau los kho qhov loj me, xim, thiab lwm yam. Qhov tseem ceeb yog onmousedown = "toggleCheckbox ('rau pem hauv ntej')" thiab onmouseup = "toggleCheckbox ('nres') ". Cov no suav nrog kev ua ntawm lub pob (tib yam rau ontouchstart/ontouchend tab sis rau qhov ntawd yog touchscreens/xov tooj). Ntawm no, khawm ua haujlwm hu ua lub luag haujlwm toggleCheckbox (x) hauv ntu javascript:
muaj nuj nqi toggleCheckbox (x) {var xhr = tshiab XMLHttpRequest (); xhr.open ("TAU", "/" + x, tseeb); xhr.send (); // tuaj yeem ua qee yam nrog cov lus teb ib yam thaum npaj tau, tab sis peb tsis ua}
Yog li nias lub pob rau pem hauv ntej, tam sim ntawd ua rau toggleCheckbox ('rau pem hauv ntej') tau txais hu. Txoj haujlwm no pib XMLHttpRequest "GET", ntawm qhov chaw "/rau tom ntej" uas ua haujlwm zoo li yog tias koj yuav tau ntaus 192.168.0.121/forward hauv koj tus browser qhov chaw nyob bar. Thaum qhov kev thov no tuaj txog ntawm ESP32, nws tau ua los ntawm:
server.on ("/rau pem hauv ntej", HTTP_GET, (AsyncWebServerRequest *thov) {Serial.println ("tau txais/rau pem hauv ntej"); actionNow = FORWARD; thov-> xa (200, "text/plain", "OK rau pem hauv ntej. ");});" "" "" "" "";
Tam sim no ESP32 tsuas teb nrog cov ntawv "OK rau tom ntej". Nco tseg toggleCheckBox () tsis ua dab tsi nrog (lossis tos rau) cov lus teb no, txawm li cas los xij nws tuaj yeem pom tom qab hauv lub koob yees duab code.
Hauv nws tus kheej thaum lub sijhawm teb no, txoj haujlwm tsuas yog teeb tsa qhov hloov pauv tam sim no = FORWARD, raws li cov lus teb rau nias lub pob. Tam sim no hauv cov ntsiab lus tseem ceeb ntawm txoj haujlwm, qhov sib txawv no tau tshuaj xyuas nrog lub hom phiaj ntawm kev nce/nqis PWM ntawm lub cav. Cov laj thawj yog: tsuav peb muaj kev nqis tes ua uas tsis STOP, nce lub cav mus rau qhov kev taw qhia ntawd kom txog thaum muaj qee tus lej (dutyCycleMax) mus txog. Tom qab ntawd txhawb nqa qhov nrawm, tsuav yog qhov kev ua tam sim no tsis hloov:
void loop () {currentMillis = millis (); yog (currentMillis - previousMillis> = dutyCycleStepDelay) {// txuag lub sijhawm kawg uas koj ua tiav lub voj yav dhau losMillis = currentMillis; // mainloop yog lub luag haujlwm rau nce/nqis cov motors yog (actionNow! = yav dhau losAction) {// ramp down, tom qab ntawd nres, tom qab ntawd hloov qhov kev nqis tes ua thiab nce lub luag haujlwmCycleNow = dutyCycleNow-dutyCycleStep; yog (dutyCycleNow <= 0) {// yog tias tom qab ramping dc yog 0, teeb mus rau qhov kev qhia tshiab, pib ntawm min dutycycle setDir (actionNow); yav dhau losAction = kev ua tam sim no; dutyCycleNow = dutyCycleMin; }} lwm yam // actionNow == yav dhau los Kev ua haujlwm nce ntxiv, tshwj tsis yog thaum kev taw qhia Nres {yog (actionNow! = STOP) {dutyCycleNow = dutyCycleNow+dutyCycleStep; yog (dutyCycleNow> dutyCycleMax) dutyCycleNow = dutyCycleMax; } lwm yam dutyCycleNow = 0; } ledcWrite (pwmChannel, dutyCycleNow); // kho lub cav ua haujlwm}}
Qhov no maj mam nce qhov nrawm ntawm lub cav, tsis txhob cia li pib ntawm qhov nrawm thiab nchuav cov Duvel uas muaj nuj nqis. Qhov kev txhim kho pom tseeb yuav yog txav cov cai no mus rau lub sijhawm cuam tshuam ib ntus, tab sis nws ua haujlwm zoo ib yam.
Tam sim no yog tias peb tso lub khawm rau pem hauv ntej, koj lub browser hu rau toggleCheckbox ('nres'), ua rau thov kom tau /nres. ESP32 teeb tsa kev ua tam sim no kom nres (thiab teb nrog "OK tso tseg."), Uas ua rau lub ntsiab tseem ceeb tig mus rau lub cav.
Yuav ua li cas txog LEDs? Tib lub tswv yim, tab sis tam sim no peb muaj tus swb:
Hauv javascript, teeb tsa tus swb tau saib xyuas, xws li ntawm txhua qhov kev hloov pauv hu kom tau "/LED/xxx" tshwm sim, qhov twg xxx yog tus nqi ci ntsa iab uas LEDs yuav tsum tau teeb tsa ntawm:
var swb = document.getElementById ('swb'), sliderDiv = document.getElementById ("sliderAmount"); slide.onchange = muaj nuj nqi () {var xhr = tshiab XMLHttpRequest (); xhr.open ("Tau txais", "/LED/" + qhov no muaj nuj nqis, muaj tseeb); xhr.send (); sliderDiv.innerHTML = qhov no.value; }
Nco ntsoov tias peb siv document.getElementByID ('swb') kom tau txais cov khoom swb nws tus kheej, uas tau tshaj tawm nrog thiab tias tus nqi raug tso tawm rau cov ntawv nyeem nrog txhua qhov kev hloov pauv.
Tus tuav hauv daim duab kos tau txais txhua qhov kev thov ci ntsa iab los ntawm kev siv "/LED/*" hauv tus tuav npe. Tom qab ntawd ntu kawg (tus lej) tau faib thiab muab pov rau hauv int:
server.on ("/LED/ *", HTTP_GET, (AsyncWebServerRequest *thov) {Serial.println ("coj kev thov tau txais!"); setLedBrightness ((thov-> url ()). substring (5).toInt ()); thov-> xa (200, "text/plain", "OK Leds.");});
Zoo ib yam li tau piav qhia saum toj no, cov duab hluav taws xob tswj cov kev hloov pauv uas tau teeb tsa PWM tsis ua haujlwm, xws li DuvelBot tuaj yeem tsav qeeb rau koj nrog npias, ceev faj tsis txhob nchuav cov dej kub ntawd, thiab rov qab mus rau chav ua noj kom nqa qee yam ntxiv.
… Yog li cas lub koob yees duab duab hloov kho yam tsis tas koj yuav tsum rov ua nplooj ntawv tshiab? Txog qhov ntawd peb siv cov txheej txheem hu ua AJAX (Asynchronous JavaScript thiab XML). Qhov teeb meem yog qhov ib txwm muaj cov neeg siv-server sib txuas ua raws cov txheej txheem ruaj khov: tus thov kev pabcuam (browser) ua rau thov, server (ESP32) teb, rooj plaub kaw. Ua tiav Tsis muaj dab tsi tshwm sim ntxiv lawm. Yog tias tsuas yog qee yam peb tuaj yeem dag qhov browser mus thov hloov tshiab los ntawm ESP32 … thiab qhov ntawd yog qhov peb yuav ua nrog daim javascript:
setInterval (function () {var xhttp = tshiab XMLHttpRequest (); xhttp.open ("GET", "/CAMERA", tseeb); xhttp.responseType = "blob"; xhttp.timeout = 500; xhttp.ontimeout = muaj nuj nqi () {}; xhttp.onload = function (e) {if (this.readyState == 4 && this.status == 200) {// saib: https://stackoverflow.com/questions/7650587/using … // https://www.html5rocks.com/en/tutorials/file/xhr2/ var urlCreator = window. URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL (this.response); // tsim ib qho khoom los ntawm blob document.querySelector ("#camimage"). src = imageUrl; urlCreator.revokeObjectURL (imageurl)}}; xhttp.send ();}, 250);
setInterval siv raws li kev ntsuas ua haujlwm thiab ua nws txhua txhua zaus (ntawm no ib zaug 250ms ua rau 4 ntas/thib ob). Lub luag haujlwm uas ua tiav ua rau thov rau binary "blob" ntawm qhov chaw nyob /CAMERA. Qhov no tau ua los ntawm ESP32-CAM hauv qhov kos duab zoo li (los ntawm Randomnerdtutorials):
server.on ("/CAMERA", HTTP_GET, (AsyncWebServerRequest * thov) {Serial.println ("lub koob yees duab thov tau txais!"); camera_fb_t * fb = NULL; // esp_err_t res = ESP_OK; size_t _jpg_buf_len = 0; uint * _jpg_buf = NULL; // ntes tus ncej fb = esp_camera_fb_get (); yog (! fb) {Serial.println ("Ncej tsis tuaj yeem nrhiav tau"); rov;} yog (fb-> hom ntawv! = PIXFORMAT_JPEG)/ /twb tau nyob hauv hom ntawv no los ntawm config {bool jpeg_converted = frame-j.webp
Qhov tseem ceeb tau txais tus ncej fb = esp_camera_fb_get () hloov nws mus rau-j.webp
Lub luag haujlwm javascript ces tos kom cov duab no tuaj txog. Tom qab ntawd nws tsuas yog siv me ntsis ntawm kev ua haujlwm los hloov qhov tau txais "blob" rau hauv url uas tuaj yeem siv los ua qhov chaw los hloov kho cov duab nrog hauv nplooj ntawv html.
phem, peb ua tiav!
Kauj Ruam 4: Cov Tswv Yim & Cov Nqis
Lub hom phiaj ntawm txoj haujlwm no rau kuv yog kom kawm paub txaus lub vev xaib txhawm rau cuam tshuam kho vajtse rau lub vev xaib. Muaj ntau qhov txuas ntxiv rau txoj haujlwm no. Nov yog ob peb lub tswv yim:
- Siv 'tiag' lub koob yees duab streaming raws li tau piav qhia ntawm no thiab ntawm no thiab txav nws mus rau tus neeg rau zaub mov thib ob raws li tau piav qhia ntawm no ntawm tib ESP32, tab sis ntawm lwm lub CPU tub ntxhais, tom qab ntawd ntshuam lub koob yees duab mus rau hauv html tau txais kev pab los ntawm 1st server siv … Qhov no yuav tsum ua rau lub koob yees duab hloov tshiab sai dua.
- Siv hom kev nkag mus (AP) hom kom tus neeg hlau nyob ib leeg ntau dua li tau piav qhia ntawm no.
- Nthuav nrog ntsuas roj teeb ntsuas, pw tsaug zog muaj peev xwm thiab lwm yam Qhov no nyuaj me ntsis tam sim no vim tias AI-Thinker ESP32-CAM tsis muaj ntau GPIOs; xav tau kev nthuav dav ntawm uart thiab piv txwv li qhev arduino.
- Hloov pauv mus rau tus neeg nrhiav neeg hlau uas tshem tawm miv los ntawm lub sijhawm ua haujlwm ntawm paw nias ntawm lub pob loj, kwj tons ntawm cov miv zoo nkauj pics thaum nruab hnub …
Thov tawm tswv yim yog tias koj nyiam lossis muaj lus nug thiab ua tsaug rau kev nyeem!
Pom zoo:
Ntauwd Ncej Pab Neeg Hlau V1 - Ob Legged, RF, BT Tswj Nrog App: 22 Cov Kauj Ruam (nrog Duab)
Ntauwd Ncej Pab Neeg Hlau V1 - Ob Legged, RF, BT Tswj Nrog App: Thaum puas tau pom cov nabqaib ntawm phab ntsa kuv npaj yuav ua neeg hlau zoo li nws. Nws yog lub tswv yim ntev, kuv tshawb ntau kab ntawv rau electro-adhesives thiab txheeb xyuas qee txoj hauv kev thiab ua tsis tiav ntawm nws lub peev xwm tuav. Tsuas yog tam sim no kuv npaj yuav ua kom nws siv hluav taws xob
DIY Neeg Hlau - Kev Kawm 6 Axis Neeg Hlau Caj Npab: 6 Kauj Ruam (nrog Duab)
DIY Neeg Hlau | Kev Kawm 6 Axis Neeg Hlau Caj Npab: DIY-Robotics kev kawm ntawm tes yog lub platform uas suav nrog 6-axis neeg hlau sab caj npab, hluav taws xob tswj hluav taws xob thiab software software. Lub platform no yog qhia txog lub ntiaj teb kev lag luam neeg hlau. Los ntawm txoj haujlwm no, DIY-Robotics xav tau
Ntsuas Neeg Hlau / 3 Log Neeg Hlau / STEM Neeg Hlau: 8 Kauj Ruam
Ntsuas Cov Neeg Hlau / 3 Log Neeg Hlau / STEM Neeg Hlau: Peb tau tsim ua ke sib npaug thiab 3 lub log neeg hlau rau kev kawm siv hauv tsev kawm ntawv thiab tom qab kawm ntawv cov haujlwm. Tus neeg hlau yog ua raws Arduino Uno, tus tiv thaiv kev tiv thaiv (txhua qhov kev tsim kho cov ntsiab lus muab), Li -Ion roj teeb pob (txhua qhov tsim tawm
Neeg Hlau-Ncej Neeg Hlau Los Ntawm Lub Cev 3D Cuam Tshuam: 12 Cov Kauj Ruam (nrog Duab)
Rope-climbing Robot From a Broken 3D Pen: 3D cwjmem yog cov cuab yeej zoo los txhim kho kev muaj tswv yim ntawm koj cov menyuam. Tab sis, koj tuaj yeem ua dab tsi thaum koj 3D Doodler Pib pib ua haujlwm thiab kho tsis tau? Tsis txhob pov koj tus cwj mem 3D rau hauv lub thoob khib nyiab! Vim tias hauv cov lus qhia no kuv yuav qhia koj yuav hloov pauv li cas
[Arduino Robot] Yuav Ua Li Cas Ua Lub Suab Ntaus Neeg Hlau - Thumbs Neeg Hlau - Servo Tsav - Source Code: 26 Cov Kauj Ruam (nrog Duab)
[Arduino Robot] Yuav Ua Li Cas Ua Lub Suab Ntaus Neeg Hlau | Thumbs Neeg Hlau | Servo Tsav | Source Code: Thumbs Neeg Hlau. Siv lub hwj chim ntawm MG90S servo motor. Nws lom zem heev thiab yooj yim! Cov cai yog yooj yim heev. Nws tsuas yog nyob ib ncig ntawm 30 kab. Nws zoo li lub suab ntes.Please tawm ib lo lus nug lossis lus teb! [Qhia] Source Code https: //github.c