之所以用ESP32是因为它有自带的蓝牙和WIFI等通信功能,我所使用的型号是GOOUUU-esp32
在arduino ade中可以直接找到esp32蓝牙的示例程序
首先在“工具”一栏里选择相应的开发板
然后在“文件-示例”中找到相应的蓝牙示例
图中有两个蓝牙相关的示例后缀为“BT”的是作为从机的蓝牙示例,而后缀为“BTM”的是作为主机的蓝牙示例,这两个是用于两个ESP32之间互相通信时的两个相关示例,这里只说一下从机的示例
点击后缀为“BT”的示例以后系统将给出一下程序
//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