ESP32cam蓝牙模块与arduino uno通信实验
生活随笔
收集整理的這篇文章主要介紹了
ESP32cam蓝牙模块与arduino uno通信实验
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
網(wǎng)上關(guān)于esp32cam與arduino通信的資料幾乎沒有,有的還得付費,于是自己動手琢磨,實驗成功。
實驗有多個版本,成功實現(xiàn)藍牙收到數(shù)據(jù)后發(fā)送單個字符給arduino板,匹配到對應(yīng)字符亮對應(yīng)顏色的燈,發(fā)送字符串可以此類推。
實驗材料,接線方式在下圖可以看到:
需要下載一個藍牙串口助手,應(yīng)用商店里很容易找到。
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數(shù)據(jù)=========================== String detectString() //刪除傳輸格式 {while(Serial.read() != '{');return(Serial.readStringUntil('}')); } String gettext() //得到數(shù)據(jù) {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() {// 藍牙助手發(fā)送數(shù)據(jù)到arduino unoif (SerialBT.available()) {while (SerialBT.available()) {// Serial.write(SerialBT.read());i = SerialBT.read();//一個字符一個字符讀取,讀一個就少一個Serial.print(i);//發(fā)送數(shù)據(jù)到arduino uno}}}兩個實驗接收數(shù)據(jù)顯示圖:
(1)單字符
(2)字符串
總結(jié)
以上是生活随笔為你收集整理的ESP32cam蓝牙模块与arduino uno通信实验的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 相对路径,绝对路径
- 下一篇: esp32cam与下载板的实际有效接线图