Cov txheej txheem:

Yuav Siv Bluetooth (BLE) Nrog ESP32: 3 Cov Kauj Ruam
Yuav Siv Bluetooth (BLE) Nrog ESP32: 3 Cov Kauj Ruam

Video: Yuav Siv Bluetooth (BLE) Nrog ESP32: 3 Cov Kauj Ruam

Video: Yuav Siv Bluetooth (BLE) Nrog ESP32: 3 Cov Kauj Ruam
Video: ib sim cas tsis tsim nyog tsom xyooj 2022 2024, Kaum ib hlis
Anonim

##### NCO TSEG #####

Txoj hauv kev qhia hauv Cov Lus Qhia no yog qub thiab qub dhau lawm. Saib cov vis dis aus no rau txoj kev tshiab.

###############

Thaum ESP32 khav theeb cov npe tshwj xeeb (Wikipedia), qhov tshwj xeeb tshaj plaws uas ua rau lub qhov muag yog lub hauv bluetooth v4.2 nrog kev txhawb nqa BLE. Tab sis cov lus ntawd tuaj yeem ua yuam kev, thaum kho vajtse nyob ntawd, kev txhawb nqa software rau siv Bluetooth ploj lawm. (Nws tseem tab tom txhim kho)

Rau cov uas tsis paub BLE yog dab tsi, nws sawv rau Bluetooth Tsawg Zog. Nws yog bluetooth raws tu qauv uas txhawb kev siv zog tsawg dua piv rau "Classic" Bluetooth.

Hauv Cov Lus Qhia no Kuv yuav qhia koj li cas koj tuaj yeem siv qhov txwv (software) cov peev txheej ntawm koj qhov pov tseg kom xa cov ntaub ntawv los ntawm ESP32 pawg thawj coj mus rau koj lub xov tooj dhau BLE.

Qee qhov tsis lees paub…

Ob peb yam ntawm kev ceeb toom Kuv yuav tsum hais ua ntej koj mus txuas ntxiv nrog phau ntawv qhia no..

Nco tseg 1: Thaum kuv hais tias kev txhawb nqa Bluetooth tseem tsis tau muaj, kuv txhais tau tias nyob hauv ib puag ncig kev txhim kho arduino.

Kev txhawb nqa zoo heev yuav muaj nyob hauv SDK tus thawj coj nrog rau IDF tab sis kuv tsis tau pom muaj cov lus qhia muaj peev xwm rau cov ntawd.

Nco tseg 2: Txoj hauv kev uas kuv tab tom siv yog qhov ua haujlwm tau zoo heev thiab tsis yog li cas BLE tau xav tias yuav tsum ua haujlwm. Lub tsev qiv ntawv txhawb rau kev tsim cov kev pabcuam hauv BLE tsis nyob ntawm no rau ib puag ncig arduino.

Ib yam uas koj tuaj yeem ua tau ntseeg tau yog tsim Beacon uas tshaj tawm nws lub npe. Kev tawm tswv yim hauv YouTube tso nws zoo nkauj heev: "LOL, kev lim hiam phem. Tab sis koj tuaj yeem ua dab tsi?"

Nco tseg 3: Tib cov ntaub ntawv uas koj tuaj yeem xa tuaj yog hlua.

Koj tuaj yeem txiav txim siab tau zoo los txiav txim siab thiab txiav txim siab lwm yam ntaub ntawv rau thiab los ntawm txoj hlua tab sis qhov ntawd dhau ntawm qhov uas tau qhia hauv phau ntawv qhia no.

Kauj Ruam 1: Piv Txwv Tsim

Image
Image
Piv Txwv Tsim
Piv Txwv Tsim
Piv Txwv Tsim
Piv Txwv Tsim
Piv Txwv Tsim
Piv Txwv Tsim

Yog tias koj tsuas yog nyob ntawm no rau qhov kev piav qhia koj tuaj yeem hla cov kauj ruam no tab sis mus dhau nws yuav ua rau koj pom meej me ntsis ntxiv..

Ua ntej kuv yuav tsim ib qhov piv txwv qhov project thiab tom qab ntawd kuv yuav sim piav qhia nws ua haujlwm li cas thiab koj tuaj yeem rov ua dua Bluetooth kev sib txuas lus li cas. Peb yuav tsim lub ntsuas qhov ntsuas kub uas txav tau uas xa cov khoom pub rau koj lub smartphone. Kev tsim kho tuaj yeem ua haujlwm nyob rau ib hnub ntawm ib leeg li-po thiab yooj yim qhia qhov txiaj ntsig ntawm BLE.

Koj tuaj yeem siv tus qauv ua lub coaster los tiv thaiv koj cov dej qab zib thiab tau txais kev ceeb toom sai li sai tau thaum koj cov dej haus mus txog qhov ntsuas kub zoo. Vim tias nws yuav yog ib qho txhaum cai yog tias koj yuav tsum tau haus dej tshuaj yej uas yog qib siab dua 40.

Tsuas yog kho vajtse koj xav tau yog ESP32 lub rooj tsavxwm thiab lub ntsuas kub digital. Kuv pawg thawj coj txhawb nqa roj teeb sab nraud yog li kuv siv 3.7v li-po uas kuv tau khaws los ntawm qee lub cuab yeej qub los ua qhov haujlwm no.

Kho vajtse

Kev sib txuas rau qhov ntsuas kub yog qhov yooj yim. Cov hlau liab txuas rau 3.3v, dub txuas rau hauv av (gnd), daj txuas rau GPIO 2 uas ntawm kuv lub rooj tsav xwm tau cim ua D9. Txuas 4.7k ohm resistor ntawm cov hlau liab thiab daj. Kuv tsis siv tus tiv thaiv, hloov kuv tab tom siv 3 tus pin txuas-lub davhlau ya nyob twg uas tuaj nrog kuv lub sensor. Nws muaj built-in rub tawm resistor.

Li-po yuav tsum tau txuas nrog siv JST txuas tab sis kuv tsis tuaj yeem txhawj xeeb yuav ib qho yog li kuv tsuas yog khau khiab hauv qee (poj niam rau poj niam) jumper cables rau hauv qhov txuas thiab txuas lwm khub rau lub roj teeb. Qhov no ua rau muaj kev ntseeg tau txuas thiab hloov hluav taws xob hloov pauv.

Tam sim no raws li phiaj xwm phiaj xwm, kuv tab tom siv Styrofoam disk uas tau txiav tawm los ntawm daim ntawv loj dua. Qhov no ua rau cov insulator zoo. Lwm qhov me me disk tau nyam rau sab saum toj tab sis me ntsis rau sab. Qhov no yog txhawm rau qhwv qhov ntev ntxiv ntawm cov xov hlau kom lawv tsis txhob poob thoob plaws qhov chaw. Tom qab ua haujlwm dav dav ntawm koj cov kua nplaum thiab lub qhov me me rau lub ntsuas qhov ntsuas, koj tau npaj mus txuas ntxiv mus rau software.

Software

Yog tias koj tsis tau muaj arduino IDE teeb tsa ces mus rau qhov txuas no txhawm rau rub nws. Arduino software los ntawm lub neej ntawd tsis tuaj nrog cov lus txhais ntawm pawg thawj coj saib rau ntau pawg ESP32. Txhawm rau kom lawv mus rau qhov txuas no thiab rub tawm cov ntawv hauv zip. Koj yuav tsum tau unzip lawv rau qhov chaw no:

C:/Cov neeg siv // Cov ntaub ntawv/Arduino/kho vajtse/espserrif/ESP32

Koj lub npe neeg siv ntawm koj lub PC nyob qhov twg. Nco ntsoov tias ntau cov ntaub ntawv muaj nyob hauv ESP32 nplaub tshev thiab tsis nyob hauv lwm daim nplaub tshev.

Tam sim no yog tias koj pib siv software arduino thiab mus rau cov cuab yeej-> cov laug cam koj yuav tsum pom ntau yam ESP32 cov laug cam thaum koj nqes mus.

Feem ntau cov ntsuas kub digital siv OneWire cov txheej txheem los sib tham nrog cov tswj hwm me me yog li peb xav tau txais lub tsev qiv ntawv. Mus rau kos duab-> suav nrog tsev qiv ntawv-> tswj cov tsev qiv ntawv thiab tshawb rau ib qho txuas thiab teeb tsa lub tsev qiv ntawv uas yog los ntawm ntau txoj kev sau ntawv. Koj tsis xav tau lub Onewire hub. Tsis quav ntsej nws.

Tam sim no koj tuaj yeem rub tawm thiab qhib cov cai txuas rau cov kauj ruam no (ntsuas kub-piv txwv.ino).

Yog tias koj siv lub ntsuas sib txawv los ntawm kuv ces koj yuav tsum hloov txoj cai raws li. Hloov cov cai hauv qab getTemp (). Tsuas yog xa rov qab qhov kub kawg hauv daim ntawv ntawm

Rov qab los;

Qhov ntab uas muaj qhov kub nyob qhov twg.

Plug rau hauv lub rooj tsavxwm, xaiv lub rooj tsavxwm raug thiab chaw nres nkoj los ntawm hauv qab cov cuab yeej thiab ntaus upload.

Yog tias txoj cai tsis kam tso tawm, tshem lub sensor thiab txuas GPIO 0 rau hauv av. Rov qab sib txuas tom qab rub tawm.

Koj li ESP yuav tsum tam sim no tau hnov qhov kub ntawm koj kas fes mus rau lub ntiaj teb tab sis koj xav tau ib tus neeg uas tuaj yeem nkag siab nws.

Android App Cov

Thov txim cov neeg siv iPhone (… tsis yog tiag tiag).

Rub lub apk los ntawm no thiab nruab nws. Thaum koj pib lub app koj yuav tau txais tos nrog lub interface yooj yim heev.

Yog tias koj tau txais cov lus yuam kev hais tias 'kev tshaj tawm tsis txhawb nqa', nyem OK thiab tsis quav ntsej nws tab sis yog tias koj tau txais cov lus tias 'BLE tsis txhawb nqa' ces koj lub xov tooj tsis muaj Bluetooth 4.0 lossis siab dua thiab tsis tuaj yeem khiav tau lub app.

Nco ntsoov tias Bluetooth ntawm koj lub xov tooj tau qhib thiab nyem 'Start Scanning', tsuav yog esp nyob hauv thaj tsam thiab siv rau ntawm koj yuav tsum tau txais qee qhov ntsuas kub.

Ua tsis raug:

  • -1000:: Qhov no txhais tau tias koj lub cuab yeej nrhiav tsis tau ESP. nco ntsoov tias Bluetooth tau qhib thiab sim rov pib ESP.
  • SNA:: Qhov no txhais tau tias koj lub xov tooj tau txais cov ntaub ntawv los ntawm ESP tab sis ESP nws tus kheej tsis tuaj yeem pom qhov ntsuas kub ntawm GPIO 2. Nco ntsoov tias kev sib txuas muaj kev nyab xeeb, saib yog tias koj siv tus tiv thaiv tus nqi raug. Txheeb ob zaug nrog koj cov phiaj xwm phiaj xwm uas koj tau txuas nrog GPIO 2 thiab tsis yog tus lej cim ua D2.

Kauj Ruam 2: Piav Qhia

Yuav ua li cas BLE ib txwm ua haujlwm yog tias lub cuab yeej tshaj tawm nws lub npe zoo li lub teeb, lub npe no tuaj yeem pom los ntawm txhua tus thiab siv los txheeb xyuas lub cuab yeej. Tom qab ntawd lub cuab yeej tuaj yeem tsim ntau yam kev pabcuam uas pom los ntawm lwm tus thaum lawv txuas rau nws. Cov kev pabcuam no tuaj yeem muaj cov kwj sib txawv ntawm cov ntaub ntawv.

Rau eg. Ib lub cuab yeej hu ua 'Weather Station' tuaj yeem ua haujlwm zoo li 'Kub', 'Vaum' thiab 'Cua'. Thaum lwm lub cuab yeej BLE zoo li koj lub xov tooj smartphone ntsuas rau cov cuab yeej, nws yuav pom Lub Chaw Huab Cua thiab thaum nws txuas rau nws, nws yuav tuaj yeem tau txais cov ntaub ntawv ntws raws li qhov sib txawv ntawm cov kev pabcuam.

Cov tsev qiv ntawv (rau ESP32) uas tam sim no muaj rau peb tso cai rau peb los tsim lub teeb ci uas lwm tus tuaj yeem tshawb pom tab sis qhov ntawd yog nws li cas. Peb tsis tuaj yeem tsim cov kev pabcuam lossis tsis muaj cov cuab yeej txuas rau nws.

Yog li kuv yuav xa cov ntaub ntawv yam tsis tsim kev pabcuam yog los ntawm kev siv cov txheej txheem zoo ib yam li WiFi raws tu qauv hu ua Beacon Stuffing. Qhov no txhais tau tias kuv suav nrog cov ntaub ntawv uas yuav raug xa hauv lub teeb lub npe nws tus kheej. Qhov no ua rau kuv tshaj tawm cov ntaub ntawv yam tsis xav tau lwm yam khoom siv txuas rau lub teeb.

ble.begin (beaconMsg); // beaconMsg yog lub npe tshaj tawm

Peb tab tom siv SimpleBLE lub tsev qiv ntawv los tsim lub teeb nrog nws lub npe hauv hom ESP. Qhov twg 'ESP' ib txwm tsis hloov pauv thaum pib ntawm lub npe thiab hloov pauv nrog cov ntaub ntawv tshiab tshaj tawm los ntawm getValue () ua haujlwm txhua 100 milliseconds.

ntab getValue () {rov sensorValue;}

Hauv app zoo rau BLE cov npe khoom siv pib nrog 'ESP', ib zaug pom, nws faib lub npe thiab tsuas yog qhia cov ntaub ntawv los ntawm qhov kawg.

Kev sib txuas lus tsuas yog ib txoj hauv kev, lub app tsis xa dab tsi rov qab.

Kauj Ruam 3: Xaus

Thaum kawg ntawm hnub no, txoj kev no tsis muaj kev hloov pauv rau kev siv BLE lub tsev qiv ntawv kom raug tab sis nws yuav txaus kom nthwv dej qee qhov haujlwm kom txog thaum ua tiav BLE kev txhawb nqa los rau Arduino. Vam tias Cov Lus Qhia no yog qee qhov kev pab rau koj.

Ua tsaug ntau rau DFRobot.com rau xa kuv cov khoom no:

  • ESP32 FireBeetle Board
  • FireBeetle Expantion Shield
  • DS18B20 Kub Sensor

Kuv nyuam qhuav pom lub tsev qiv ntawv no. ReadME hais tias koj tuaj yeem txuas rau lwm yam khoom siv BLE kom tau txais cov ntaub ntawv (Tsis tuaj yeem tshaj tawm koj tus kheej). Kuv tsis tau sim nws tab sis koj tuaj yeem tshawb xyuas nws yog tias koj xav tau.

Koj tuaj yeem tshawb xyuas qhov project video ntawm: YouTube

Pom zoo: