当前位置:
首页 >
ESP32cam蓝牙模块与arduino uno通信实验
发布时间:2025/3/19
41
豆豆
生活随笔
收集整理的这篇文章主要介绍了
ESP32cam蓝牙模块与arduino uno通信实验
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
网上关于esp32cam与arduino通信的资料几乎没有,有的还得付费,于是自己动手琢磨,实验成功。
实验有多个版本,成功实现蓝牙收到数据后发送单个字符给arduino板,匹配到对应字符亮对应颜色的灯,发送字符串可以此类推。
实验材料,接线方式在下图可以看到:
需要下载一个蓝牙串口助手,应用商店里很容易找到。
arduino uno上传代码(接收单字符):
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通信实验的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 相对路径,绝对路径
- 下一篇: esp32cam与下载板的实际有效接线图