Customizable Arduino and ESP32 BLE Serial library, compliant with Nordic UART Service and others
MIT License
This library allows using Nordic UART Service (NUS) with ESP32 Arduino.
Get involved: 💬 Discord • 🌐 Website • 🐛 Issues • 📢 Twitter • 💎 Patreon
HardwareSerial
-compatible APIlib_deps =
+ senseshift/Serial_BLE
For all examples, take a look at the examples
folder.
#include <BLESerial.h>
BLESerial<> SerialBLE;
void setup() {
Serial.begin(9600);
SerialBLE.begin("ESP32-BLE-Slave");
}
void loop() {
if (Serial.available()) {
SerialBLE.write(Serial.read());
SerialBLE.flush();
}
if (SerialBLE.available()) {
Serial.write(SerialBLE.read());
}
}
Using custom UUIDs for Microchip BM70/RN4870 Transparent UART
// ...
void setup() {
// ...
SerialBLE.begin(
"ESP32-BLE-Slave",
"49535343-FE7D-4AE5-8FA9-9FAFD205E455",
"49535343-1E4D-4BD9-BA61-23C647249616",
"49535343-8841-43F4-A8D4-ECBE34729BB3"
);
// ...
}
// ...
// ...
void setup() {
// ...
BLEDevice::init("ESP32-BLE-Slave");
BLEServer* pServer = BLEDevice::createServer();
auto pService = pServer->createService("49535343-FE7D-4AE5-8FA9-9FAFD205E455");
auto pRxCharacteristic = pService->createCharacteristic("49535343-1E4D-4BD9-BA61-23C647249616", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_NOTIFY);
auto pTxCharacteristic = pService->createCharacteristic("49535343-8841-43F4-A8D4-ECBE34729BB3", BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);
SerialBLE.begin(pRxCharacteristic, pTxCharacteristic);
// ...
}
// ...
Using ETL provides a way to use this library without dynamic memory allocation.
#include <Embedded_Template_Library.h>
#include <etl/queue.h>
#include <etl/circular_buffer.h>
BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE;
Using the NimBLE library saves a significant amount of RAM and Flash memory.
Make sure to install NimBLE-Arduino
library in Arduino IDE.
Update BLESERIAL_USE_NIMBLE
setting Before including library header:
+ #define BLESERIAL_USE_NIMBLE true
#include <BLESerial.h>
Alternatively, сhange the following line in BLESerial.h
:
- # define BLESERIAL_USE_NIMBLE false
+ # define BLESERIAL_USE_NIMBLE true
Change your platformio.ini
file to the following settings:
lib_deps =
+ h2zero/NimBLE-Arduino@^1.4.0
build_flags =
+ -D BLESERIAL_USE_NIMBLE=true