Bluetooth LE · lesson 1 of 8
Hear every Bluetooth device around you
Phones, watches, earbuds, speakers, keyboards and beacons announce themselves all day: short advertising packets on three radio channels, many times a second, whether anyone listens or not. B1 turns the board into a listener. It draws them on a radar, guesses what each one is, and takes a packet apart byte by byte. The radio uses NimBLE, a lightweight Bluetooth stack; the firmware is its own (ble-lab-b1), with shared code in kit/lib/ble-kit.
Find your own phone among the devices around you, read its packets byte by byte, and measure how often it advertises.
You're done when
- The radar view shows blips and the monitor's
listprints a table of devices with a kind (phone, audio, keyboard…). - You picked your own phone (bring it close: it becomes the strongest) and
bytesshows its AD structures: Flags, then manufacturer data (Apple, Samsung, Google…). watchprints one line per packet of your phone, and you can read its advertising interval from the+… msgaps.- Switching
mode passivemakes the scan responses (and some names) disappear;mode activebrings them back.
On the board
You will learn
- advertising
- channels 37 · 38 · 39
- AD structures
- active vs passive scan
- RSSI → distance
- private addresses
- scan duty cycle
uv run pio run -d labs/ble-lab-b1 -e ble-lab-b1 -t uploadParts required
Parts library- ESP32-S3-DevKitC-1 + USB-C data cable
- 1.9″ ST7789 screen
- Smartphone (Bluetooth)
- Optional: Push button
The Bluetooth track, from listening to hosting
Eight labs, each its own firmware. The board starts as a pure listener and ends up hosting your keyboard. Pick a lab to see the board's role and which way the data flows; the lock marks the labs where pairing and encryption matter.
Roadmap of the 8 Bluetooth Low Energy labs from passive scanning to GATT servers, pairing, Web Bluetooth, HID, and MIDI. Eight labs, each its own firmware. The board starts as a pure listener and ends up hosting your keyboard. Pick a lab to see the board's role and which way the data flows; the lock marks the labs where pairing and encryption matter.
- Key concepts: advertising, channels 37 · 38 · 39, AD structures, active vs passive scan, RSSI → distance, private addresses, scan duty cycle.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
Three channels, many shouts
Bluetooth LE splits the 2.4 GHz band into 40 channels of 2 MHz. Advertising uses only three of them, 37, 38 and 39, placed in the gaps between the usual Wi-Fi channels 1, 6 and 11. Every advertising event sends the same packet on all three, one after the other. The scanner listens on one channel at a time: a packet counts only if it lands inside a listening window on its channel. Move the window slider and watch how many packets the board catches; switch to active to see the scan request and response.
Visualization of BLE's 40 2.4 GHz channels: 3 advertising channels (37, 38, 39) and 37 data channels. Bluetooth LE splits the 2.4 GHz band into 40 channels of 2 MHz. Advertising uses only three of them, 37, 38 and 39, placed in the gaps between the usual Wi-Fi channels 1, 6 and 11. Every advertising event sends the same packet on all three, one after the other. The scanner listens on one channel at a time: a packet counts only if it lands inside a listening window on its channel. Move the window slider and watch how many packets the board catches; switch to active to see the scan request and response.
- Key concepts: advertising, channels 37 · 38 · 39, AD structures, active vs passive scan, RSSI → distance, private addresses, scan duty cycle.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
One advertising packet, byte by byte
What a radio actually sends, from the first bit to the checksum. Pick a device, then step through the fields with ◀ ▶. The AD structures in the middle are exactly what the inspect view and the bytes command show.
Byte-by-byte breakdown of a BLE advertising packet: preamble, access address, PDU header, MAC, and AD structures. What a radio actually sends, from the first bit to the checksum. Pick a device, then step through the fields with ◀ ▶. The AD structures in the middle are exactly what the inspect view and the bytes command show.
- Key concepts: advertising, channels 37 · 38 · 39, AD structures, active vs passive scan, RSSI → distance, private addresses, scan duty cycle.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
What the screen shows
Four views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses or resumes the scan. The icon at the top right is the radio: a sweeping radar while it scans.
Gallery of ST7789 screens shown across the ESP32-S3 Bluetooth LE labs. Four views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses or resumes the scan. The icon at the top right is the radio: a sweeping radar while it scans.
- Key concepts: advertising, channels 37 · 38 · 39, AD structures, active vs passive scan, RSSI → distance, private addresses, scan duty cycle.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
Commands, in order
Type these in the serial monitor (uv run pio device monitor) unless the grey tag says otherwise. The coloured tag says what should be near the board while it runs.
uv run pio run -d labs/ble-lab-b1 -e ble-lab-b1 -t uploadMac terminalno phone needed- Does
- Builds lab B1 and writes it to the board. The first build downloads NimBLE-Arduino 2.5.1 (the Bluetooth stack).
- You should see
Hard resetting via RTS pin…. The screen shows the radar with a sweeping line.- If not
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
uv run pio device monitorMac terminalno phone needed- Does
- Opens the serial monitor (the board restarts).
- You should see
ble-lab-b1: NimBLE 2.5.1 up, address …,+ active scan, 100/100 ms (100% listening), then the command list.- If not
- No
NimBLE … upline: the stack didn't start; unplug and replug the board.
listserial monitorphone: scanner app open- Does
- Prints every device heard in the last 30 s, strongest first: RSSI, a distance guess, kind, address and its type, packets, name or maker.
- You should see
- A table such as
1 -46 0.6 phone 5A:3C:… private (RPA) 412 Apple. Ten to fifty rows in a flat, fewer in a house. - If not
- Empty: is Bluetooth on around you? Phones often advertise only when their screen is on or an app wants them to.
(hold your phone next to the board)with your handsphone: scanner app open- Does
- Your phone becomes the strongest device. Unlock it: iPhones advertise more often with the screen on.
- You should see
- On the radar, one blip moves to the centre; on list it jumps to row 1 with about −40 dBm.
- If not
- Android phones may stay silent: open nRF Connect and use its Advertiser tab, or switch on Nearby Share / Quick Share for a moment.
pick 1, then bytesserial monitorphone: scanner app open- Does
- Picks row 1 for the inspect view and prints its advertisement and scan response, structure by structure.
- You should see
[02 01 | 1A] Flags,[0A FF | 4C 00 10 …] Manufacturer data(Apple: Nearby info), maybe[02 0A | 0C] TX power.- If not
no scan response: some devices don't send one; in passive mode nobody asks for it.
watchserial monitorphone: scanner app open- Does
- Prints one line per packet of the picked device, with the time since the previous one.
- You should see
< + 182 ms -47 dBm 31 Blines. Some gaps are missed packets (your phone sent it on a channel the board wasn't listening on); the shortest repeating gap is its interval.- If not
watch offstops it. Too many lines:near -60first.
mode passive, then mode activeserial monitorphone: scanner app open- Does
- Passive: the board only listens. Active: it also sends a scan request to every scannable device and gets a second packet back, the scan response.
- You should see
- In passive mode the inspect view loses its scan rsp row and some names turn into makers. The air view shows the mode.
timing 100 30serial monitorphone: scanner app open- Does
- Listen 30 ms out of every 100 (30 % duty cycle) instead of all the time.
- You should see
- Packets per second on the air view drop to about a third. Phones scan like this to save battery.
timing 100 100goes back. - If not
- Window must be ≤ interval.
calib (phone 1 m away)serial monitorphone: scanner app open- Does
- Takes the picked device's average RSSI as the 1 m reference for the distance guesses.
- You should see
+ 1 m = -58 dBm now: distances use it. Walk away: the blip drifts outwards.- If not
- Distances jump by ±1 m: that's RSSI. Bodies, walls and the phone's orientation move it by 5–10 dB.
Steps
0 of 6 ticked. Ticks are saved in this browser.
Everything here is what devices broadcast to anyone; the board never connects to them. Still, the list is your neighbours' gadgets: don't post their addresses (they stay out of the committed logs). Phones change their private address about every 15 minutes, so the same phone can show up twice. Distances are guesses from signal strength, good to a factor of two. The ESP32-S3 has Bluetooth LE only: Classic Bluetooth (most audio streaming, older keyboards) is invisible to it.
Preview: what you should see
Interactive BLE scanner and GATT monitor simulating NimBLE advertising discovery and characteristic updates.
- Key concepts: advertising, channels 37 · 38 · 39, AD structures, active vs passive scan, RSSI → distance, private addresses, scan duty cycle.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
ESP32-S3 peripherals used in this lab
Open interactive GPIO pinoutExplore the hardware blocks, pin rules, and registers behind this experiment.
- GPIO and IO MUX
45 pins, and a matrix that routes almost any signal to almost any pin
- SPI
Fast four-wire bus for screens, card readers and flash
- Bluetooth LE
Bluetooth 5 Low Energy: beacons, phones, keyboards, MIDI
- UART
Three serial ports, the one you see in the serial monitor
- CPU
Two Xtensa LX7 cores at up to 240 MHz
- SRAM
512 KB of fast on-chip RAM for your code and data
Troubleshooting & hardware gotchas
See all 17 ESP32-S3 hardware gotchas- What if it does not work or behaves unexpectedly?
- Everything here is what devices broadcast to anyone; the board never connects to them. Still, the list is your neighbours' gadgets: don't post their addresses (they stay out of the committed logs). Phones change their private address about every 15 minutes, so the same phone can show up twice. Distances are guesses from signal strength, good to a factor of two. The ESP32-S3 has Bluetooth LE only: Classic Bluetooth (most audio streaming, older keyboards) is invisible to it.
- If “uv run pio run -d labs/ble-lab-b1 -e ble-lab-b1 -t upload” does not work
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
- If “uv run pio device monitor” does not work
- No
NimBLE … upline: the stack didn't start; unplug and replug the board. - If “list” does not work
- Empty: is Bluetooth on around you? Phones often advertise only when their screen is on or an app wants them to.
- If “(hold your phone next to the board)” does not work
- Android phones may stay silent: open nRF Connect and use its Advertiser tab, or switch on Nearby Share / Quick Share for a moment.
- If “pick 1, then bytes” does not work
no scan response: some devices don't send one; in passive mode nobody asks for it.- If “watch” does not work
watch offstops it. Too many lines:near -60first.- If “timing 100 30” does not work
- Window must be ≤ interval.
- If “calib (phone 1 m away)” does not work
- Distances jump by ±1 m: that's RSSI. Bodies, walls and the phone's orientation move it by 5–10 dB.
- Four pins are read at reset
- GPIO0, GPIO3, GPIO45 and GPIO46 are sampled the moment the chip comes out of reset: they pick the boot mode, the flash voltage, the ROM log and the JTAG source. Anything wired to them must not pull them the wrong way at power-up. After reset they are normal pins again.
- GPIO3 has no pull resistor at reset
- GPIO0 has a weak pull-up and GPIO45/46 weak pull-downs, but GPIO3 floats. When the eFuses make it choose the JTAG source, an outside circuit has to hold it at a clear level.
- GPIO47 and 48 run at 1.8 V on R16V modules
- Modules with the ESP32-S3R16V chip set the flash voltage to 1.8 V, and GPIO47/48 share that supply. A 3.3 V part on those pins sees the wrong levels.
- The pins are not 5 V tolerant
- A high input may go up to the pin's supply plus 0.3 V, so about 3.6 V on a 3.3 V board, and the power pins are rated to 3.6 V at most. 5 V from a sensor or an Arduino can damage the chip: use a level shifter or a divider.