Arduino ESP32 蓝牙串口通讯实验
- ✨这里的硬件使用的是ESP32-DevKitC支持经典蓝牙以及BLE,对于ESP32S3,以及ESP32C3只支持BLE,不支持经典蓝牙。
🎉目的:通过蓝牙串口输出,实现无线蓝牙串口调试
📗串口函数介绍
Serial.available():返回串口缓冲区中当前剩余的字符个数。Serial.print():发送的是字符,Serial.write():发送的字节.
蓝牙串口继承类函数
SerialBT.available():返回蓝牙串口缓冲区中当前剩余的字符个数。SerialBT.print():蓝牙串口发送的是字符,SerialBT.write():蓝牙串口发送的字节.
📝程序实例代码
//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
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());//将串口收到的数据,再通过蓝牙串口转发出去
Serial.println("由SerialBT打印");
}
if (SerialBT.available()) {//将蓝牙串口收到的数据,再通过串口把信息发回给电脑
Serial.write(SerialBT.read());
Serial.println("由Serial打印");
}
delay(20);
}
- 程序烧录后,重启esp32开发板,硬件串口打印信息

🛠程序烧录完成后,给电脑端蓝牙设备添加
我的电脑-控制面板-所有控制面板-设备和打印机,添加设备

- 🌿或者在控制面板,直接点击添加设备
- 🌿或者在设置 - “蓝牙和打印机”


- 🌿会找到一个名叫"ESP32test",的设备。

- 🌿用鼠标左键-点中这个设备,然后就是下一页。只有选中该对象才能,下一页的哦!
- 🌿驱动安装完成后,在电脑-计算机管理,可以查看到硬件蓝牙串口了。(会发现有两个蓝牙窗口)

- 🌿回到控制面板-“查看设备和打印机”


- 🌿查看具体蓝牙端口号

- 🔧利用串口调试助手设置蓝牙串口(友善串口调试助手)下载

⛳蓝牙串口通讯窗口说明

📄硬件串口发数据,蓝牙串口转发(数据发送方式一)

📑esp32蓝牙串口发数据,硬件串口转发(数据发送方式二)

本文介绍了一个使用Arduino ESP32-DevKitC进行蓝牙串口通信的实验,该实验旨在通过蓝牙实现无线串口调试。程序实现了串口与经典蓝牙(SPP)之间的数据桥接,确保蓝牙串口拥有类似正常串口的功能。在电脑端,通过设备和打印机设置添加并连接名为'ESP32test'的蓝牙设备,然后使用串口调试助手设置蓝牙串口进行数据收发。


8440

被折叠的 条评论
为什么被折叠?



