ESP32用作经典蓝牙串口透传模块与手机进行串口通信

ESP32用作经典蓝牙串口透传模块与手机进行串口通信

简介

在这里插入图片描述

ESP32-WROOM-32模组集成了双模蓝牙包括传统蓝牙(BR/EDR)、低功耗蓝牙(BLE)和 Wi-Fi,具有广泛的用途:Wi-Fi 支持极大范围的通信连接,也支持通过路由器直接连接互联网;而蓝牙可以让用户连接手机或者广播 Bluetooth LE Beacon 以便于信号检测。
蓝牙特性:
• 支持标准 Class-1、Class-2 和 Class-3,且无需外部功率放大器
• 增强型功率控制 (Enhanced Power Control)
• 输出功率高达 +9 dBm
• NZIF 接收器具有–94 dBm 的 BLE 接收灵敏度
• 自适应跳频 (AFH)
• 基于 SDIO/SPI/UART 接口的标准 HCI
• 高速 UART HCI,最高可达 4 Mbps
• 支持蓝牙 4.2 BR/EDR 和 Bluetooth LE 双模 controller
• 同步面向连接/扩展同步面向连接 (SCO/eSCO)
• CVSD 和 SBC 音频编解码算法
• 蓝牙微微网 (Piconet) 和散射网 (Scatternet)
• 支持传统蓝牙和低功耗蓝牙的多设备连接
• 支持同时广播和扫描
开发板集成Type-C USB转TTL串口芯片CH343可以实现一键串口下载程序和串口打印。

ESP32开发板Arduino程序

开发板管理器搜索安装ESP32开发板
在这里插入图片描述
选择好自己手里所用的对应开发板
在这里插入图片描述
打开BluetoothSerial示例程序
在这里插入图片描述

//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());
  }
  if (SerialBT.available()) {
    
    
    Serial.write(SerialBT.read());
  }
  delay(20);
}

手机与ESP32开发板进行蓝牙串口透传通信

编译上传例程到ESP32开发板,在手机应用市场搜索下载安装“SPP蓝牙串口”APP,本实验中用的是"Arduino bluetooth controller"APP,打开APP搜索ESP32tset蓝牙设备并建立连接。
在这里插入图片描述
在这里插入图片描述
选择Terminal mode
在这里插入图片描述
在这里插入图片描述
Arduino IDE打开串口助手,手机蓝牙串口APP和串口助手互发信息,即可显示出收到信息。通过修改例程中的波特率参数即可更改蓝牙串口通信的波特率。

总结

通过本实验可把ESP32用作一个蓝牙串口透传设备使用,功能和常用的HC-05/06串口蓝牙设备一样。

猜你喜欢

转载自blog.csdn.net/qq_42250136/article/details/132707544