esp蓝牙透传

#include <Arduino.h>
#include "BluetoothSerial.h"
 
BluetoothSerial bt1;
 
void setup()
{
  Serial.begin(115200);
  delay(5000);
  bt1.begin("ESP32BLUE");
  Serial.println("Waiting for Bluetooth connection........");
}
 
void loop()
{
  if (Serial.available())
  {
    bt1.write(Serial.read());
  }
  if (bt1.available())
  {
    Serial.write(bt1.read());
  }
  delay(20);  
}

示例2

#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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值