🛠 Périphérique BLE : pont série air ↔ USB (Bluefruit)
Objectives
Create a BLE peripheral using the Nordic SoftDevice stack via Bluefruit52Lib (Adafruit nRF52 core): the Nordic UART Service (NUS) acts as a bridge between a phone (Bluefruit LE Connect app) and the USB serial port. Understand advertising, connection, and the key constraint: the SoftDevice has higher priority than all user code when the radio is running.
Hardware
- 1× Adafruit Feather nRF52840 Express + data-capable micro-USB cable
- 1× Android/iOS smartphone with the Bluefruit LE Connect app
- Adafruit nRF52 Boards core ≥ 1.1.x + Adafruit Bluefruit nRF52 Libraries
Complete Code
// nrf52840-ble-peripheral-bluefruit.ino — inspire de l'exemple officiel bleuart
#include <bluefruit.h>
BLEUart bleuart; // service Nordic UART (caracteristiques RX/TX)
void setup {
Serial.begin(115200); // console USB CDC
Bluefruit.begin; // demarre la SoftDevice (orchestree FreeRTOS)
Bluefruit.setTxPower(4); // jusqu'a +8 dBm sur le module MDBT50Q
Bluefruit.setName("Feather52840");
bleuart.begin;
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addService(bleuart);
Bluefruit.Advertising.start(0); // advertising illimite
}
void loop {
if (bleuart.available) // telephone -> carte -> USB
Serial.write((uint8_t)bleuart.read);
if (Serial.available) // USB -> carte -> telephone
bleuart.write((uint8_t)Serial.read);
}
Expected Verification
In Bluefruit LE Connect, the device “Feather52840” appears, the connection succeeds, and the UART page displays what you type in the USB monitor — and vice versa. The board’s NeoPixel blinks blue upon connection (BSP status behavior).
Common Errors
- Hard timing during radio activity: the SoftDevice “has higher priority than all user code, including interrupts” — real-time control (strict NeoPixel, WS2812 frames) may break when BLE is active.
- Wrong profile selected in the app: you must open the *UART* service, not the generic “Bluetooth Low Energy” option.
Bluefruit.beginomitted or called afterbleuart.begin: the stack must start before the services.- Advertising silently stopped: without
start(0), discovery stops after a disconnection.
Other tutorials for this board
Code examples for this board
neopixel_pulsation.pyPythonled_bouton.pyPythonentrees_num.pyPythonanalogique_lumiere.pyPythonservo_pwm.pyPythonscanner_i2c.pyPython