Arduino下 ESP32蓝牙与PC蓝牙数据传输

Arduino下 ESP32蓝牙与PC蓝牙数据传输

ESP32

打开Arduino,选择“文件”—“示例”—“BluetoothSerial”—“SerialToSerialBT”:
在这里插入图片描述
然后选择开发板和端口,编译烧录,在下方发送框内输入要发送的信息
在这里插入图片描述

//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);
}

PC端

设置好上边的,打开电脑蓝牙,搜索新设备
在这里插入图片描述
连接ESP32test
在这里插入图片描述
在下方会看到已添加设备
在这里插入图片描述
再点击更多蓝牙选项、COM端口、选择ESP32test(带SPP的)端口,记住端口后边会用。或者点添加、选择传出,选择你的设备(ESP32test)最后就确定就行了。
在这里插入图片描述
在这里插入图片描述

测试效果

打开Arduino端,在输入框内输入发送的数据,同时打开串口调试助手,选择刚才设置传出的端口,设置好对应的波特率。发送123接收端收到123,测试成功
在这里插入图片描述

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值