日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ESP32cam蓝牙模块与arduino uno通信实验

發布時間:2025/3/19 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ESP32cam蓝牙模块与arduino uno通信实验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上關于esp32cam與arduino通信的資料幾乎沒有,有的還得付費,于是自己動手琢磨,實驗成功。
實驗有多個版本,成功實現藍牙收到數據后發送單個字符給arduino板,匹配到對應字符亮對應顏色的燈,發送字符串可以此類推。
實驗材料,接線方式在下圖可以看到:
需要下載一個藍牙串口助手,應用商店里很容易找到。





arduino uno上傳代碼(接收單字符):

int i ; void setup() {Serial.begin(115200);pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT); }void loop() {if (Serial.available()){ // Serial.write(Serial.read());//輸出原數據格式i = Serial.read(); // Serial.println(i);//輸出可顯示的ascll值Serial.write(i);Serial.write('\n');}if (i == 'a'){digitalWrite(2, HIGH);}if (i == 'b'){digitalWrite(3, HIGH);}if (i == 'c'){digitalWrite(4, HIGH);} }

arduino上傳代碼(接收字符串):

String itext = "" ; void setup() {Serial.begin(115200);pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT); }String detectString(); String gettext();void loop() {if (Serial.available()){ // Serial.write(Serial.read());itext = gettext(); // Serial.println(i);Serial.println(itext);}if (itext == "blue"){digitalWrite(2, HIGH);}if (itext == "green"){digitalWrite(3, HIGH);}if (itext == "red"){digitalWrite(4, HIGH);} }//======接收esp32cam數據=========================== String detectString() //刪除傳輸格式 {while(Serial.read() != '{');return(Serial.readStringUntil('}')); } String gettext() //得到數據 {String s = detectString();return s; }

esp32cam上傳代碼:

//This example code is in the Public Domain (or CC0 licensed, at your option.) //By Evandro Copercini - 2018 // //This example creates a bridge between Serial and Classical Bluetooth (SPP) //and also demonstrate that SerialBT have the same functionalities of a normal Serial#include "BluetoothSerial.h"#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endifBluetoothSerial SerialBT;char i;void setup() {Serial.begin(115200);SerialBT.begin("ESP32test"); //Bluetooth device nameSerial.println("The device started, now you can pair it with bluetooth!"); }void loop() {// 藍牙助手發送數據到arduino unoif (SerialBT.available()) {while (SerialBT.available()) {// Serial.write(SerialBT.read());i = SerialBT.read();//一個字符一個字符讀取,讀一個就少一個Serial.print(i);//發送數據到arduino uno}}}

兩個實驗接收數據顯示圖:
(1)單字符

(2)字符串

總結

以上是生活随笔為你收集整理的ESP32cam蓝牙模块与arduino uno通信实验的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。