Arduino ESP32 BLE蓝牙串口通讯实验
摘要:蓝牙串口通讯实验目的通过蓝牙串口输出,实现无线蓝牙串口调试串口函数介绍返回串口缓冲区中当前剩余的字符个数。只有选中该对象才能,下一页的哦驱动安装完成后,在电脑计算机管理,可以查看到硬件蓝牙串口了。Arduino ESP32 BLE蓝牙串口通讯实验
目的:通过蓝牙串口输出,实现无线蓝牙串口调试
串口函数介绍
Serial.available() :返回串口缓冲区中当前剩余的字符个数。Serial.print() :发送的是字符,Serial.write() :发送的字节.
蓝牙串口继承类函数
SerialBT.available() :返回蓝牙串口缓冲区中当前剩余的字符个数。SerialBT.print() :蓝牙串口发送的是字符,SerialBT.write() :蓝牙串口发送的字节.
程序实例代码
<pre data-clipboard-text="//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;void setup() {Serial.begin(115200);SerialBT.begin("ESP32test"); //Bluetooth device nameSerial.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);}" id="pre0" class="layui-code layui-box layui-code-view" lay-title="" lay-skin="" style="box-sizing: content-box; font-family: "Courier New"; margin-top: 10px; margin-bottom: 10px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); white-space: pre-wrap; overflow-wrap: break-word; position: relative; line-height: 20px; border-style: solid; border-color: rgb(238, 238, 238); background-color: rgb(250, 250, 250); color: rgb(51, 51, 51); font-size: 12px; max-width: 100%;">
</>复制代码
//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;void setup() {Serial.begin(115200);SerialBT.begin("ESP32test"); //Bluetooth device nameSerial.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蓝牙串口发数据,硬件串口转发(数据发送方式二)
谢谢分享 来看看吧看吧 谢谢分享