Skip to content
esp-labsESP32-S3 bench guide
ESP32-S3 DevKitC pinoutThis lesson uses: VCC on 3V3, BLK on 7, RES on 8, DC on 9, CS on 10, SDA on 11, SCL on 12, GND on GND, BTN on 5, BOOT on 0.ESP32-S3WROOM-1 N16R8BOOTRSTRGBUSBCOM3V3VCC3V3RST45BTN67BLK151617188RES3469DC10CS11SDA12SCL13145VGNDGNDGNDTX 43RX 441242414039383736350BOOT454847212019GNDGND
  • used in this lesson
  • safe GPIO
  • avoid
  • power
  • ground
  • button input
  • RC522
Between lessons
  1. Ctrl+C closes the monitor on the Mac only. The board keeps running.
  2. Unplug USB: this is what stops the program and the screen
  3. Rewire while off
  4. Check VCC is on 3V3, no loose ends
  5. Plug in, flash the next lesson

Never unplug during Writing at 0x…. Pin changing from output to input? Flash first, then wire.

Lesson B8

Bluetooth LE · lesson 8 of 8

Swap roles: your keyboard types onto the board

built, not flashed

Until now a phone or a laptop was the central and the board answered. Here the board is the central, the way your laptop is. It finds connectable devices, connects, and explores their GATT tables (read-only: only the public basics like name, maker and battery). Then it hosts your own BLE keyboard and mouse: it pairs (the board shows a passkey, you type it on the keyboard), reads the keyboard's own description of its reports (the Report Map), subscribes, and turns the raw bytes into text and a paint cursor on the screen.

Goal

Pair your BLE keyboard with the board, type on its screen, and understand every byte the keyboard sends.

You're done when

  • host ends with + hosting: keyboard media keys (or mouse), after you typed the passkey on the keyboard.
  • What you type appears on the keyboard view; Shift, Ctrl, Alt and Cmd light up while held; layout de swaps Y and Z and shows ä ö ü ß.
  • On the reports view you can name every coloured byte: modifiers (amber), key codes (teal), mouse X (blue), Y (violet), wheel (coral).
  • After a power cycle the board reconnects to the bonded keyboard by itself, no passkey.

You will learn

  • central role
  • service discovery
  • HID over GATT (HOGP)
  • Report Map parsing
  • passkey entry as central
  • CCCD subscribe
  • key codes vs layouts
  • bond & reconnect
uv run pio run -d labs/ble-lab-b8 -e ble-lab-b8 -t upload
Open this lab's code on GitHubesp-labs / labs / ble-lab-b8 (opens in a new tab)

Parts required

Parts library
  • ESP32-S3-DevKitC-1 + USB-C data cable
  • 1.9″ ST7789 screen
  • Bluetooth keyboard or mouse
  • Optional: Push button

From scan to keystroke, step by step

Everything that happens between your keyboard advertising and an h appearing on the board, packet by packet. Pick a story: the first pairing, coming back after a power cycle, or exploring your JBL speaker. Use ◀ ▶ or let it play; the box below each step shows the real bytes.

BLE Central host data flow scanning, pairing, and decoding reports from a wireless keyboard or mouse. Everything that happens between your keyboard advertising and an h appearing on the board, packet by packet. Pick a story: the first pairing, coming back after a power cycle, or exploring your JBL speaker. Use ◀ ▶ or let it play; the box below each step shows the real bytes.

  • Key concepts: central role, service discovery, HID over GATT (HOGP), Report Map parsing, passkey entry as central, CCCD subscribe, key codes vs layouts, bond & reconnect.
  • Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).

Interactive diagram loads after page initialization.

Decode a report yourself

A keyboard never sends letters, only key positions and bits. Pick a Report Map, then press keys on the little keyboard or drag on the mouse pad: the report flies to the board and every field lights up in turn, with the Report Map item that defined it. Switch US/DE: the same key code becomes another letter.

HID boot-protocol report decoder translating raw modifier bytes and scan codes into characters. A keyboard never sends letters, only key positions and bits. Pick a Report Map, then press keys on the little keyboard or drag on the mouse pad: the report flies to the board and every field lights up in turn, with the Report Map item that defined it. Switch US/DE: the same key code becomes another letter.

  • Key concepts: central role, service discovery, HID over GATT (HOGP), Report Map parsing, passkey entry as central, CCCD subscribe, key codes vs layouts, bond & reconnect.
  • Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).

Interactive diagram loads after page initialization.

What the screen shows

Seven views. A click goes to the next one, a double-click runs the action at the bottom left, a long press takes the next step: connect, then host, then disconnect.

Gallery of ST7789 screens shown across the ESP32-S3 Bluetooth LE labs. Seven views. A click goes to the next one, a double-click runs the action at the bottom left, a long press takes the next step: connect, then host, then disconnect.

  • Key concepts: central role, service discovery, HID over GATT (HOGP), Report Map parsing, passkey entry as central, CCCD subscribe, key codes vs layouts, bond & reconnect.
  • 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.

  1. uv run pio run -d labs/ble-lab-b8 -e ble-lab-b8 -t uploadMac terminalno phone needed
    Does
    Builds lab B8 and writes it to the board. NimBLE-Arduino is already downloaded (B1).
    You should see
    ble-lab-b8: NimBLE 2.5.1 up, address …, the command list, and the devices view filling up.
    If not
    “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
  2. uv run pio device monitorMac terminalno phone needed
    Does
    Opens the serial monitor (and restarts the board).
    You should see
    Bluetooth lab B8 Host (ble-lab-b8) and the commands.
  3. put the keyboard in pairing modewith your handsyour keyboard/mouse on
    Does
    A keyboard already paired to your Mac only talks to the Mac. Pairing mode makes it advertise to anyone: usually hold the Bluetooth or channel key 3 s until its light blinks fast. Multi-channel keyboards: pick a channel your Mac isn't using.
    You should see
    The devices view: your keyboard near the top with a keyboard icon and HID.
    If not
    Not there: it is still connected to the Mac (switch channel, or remove it in the Mac's Bluetooth settings). Apple Magic Keyboards use Classic Bluetooth and never show up here.
  4. listserial monitoryour keyboard/mouse on
    Does
    Prints the connectable devices, strongest first. Beacons are left out: they can't be connected to.
    You should see
    1 -48 dBm keyboard/mouse C4:7D:2A:91:0E:33 Bench Keys [HID]
  5. connect 1serial monitoryour keyboard/mouse on
    Does
    Sends CONNECT_IND to device 1 (now the board chooses the connection timing), then explores: discovers every service, characteristic and descriptor and reads the public basics.
    You should see
    > CONNECT_IND to Bench Keys, + connected: we are the central, + 5 services, 19 characteristics in 820 ms, - it is a keyboard/mouse (1812): type host. The explore view shows the tree; HID values say “locked until paired”.
    If not
    no answer from …: it stopped advertising (pairing mode times out after ~60 s): start it again.
  6. host (or a long press)serial monitoryour keyboard/mouse on
    Does
    Pairs (bond + passkey + Secure Connections), reads the Report Map, finds each input report through its 2908 descriptor and subscribes (writes 01 00 into its CCCD).
    You should see
    Six big digits on the screen and ! type 482915 on the keyboard, then Enter. Type them on the keyboard, press Enter: + secured: passkey, bonded, key 16 B, < Report Map: 72 bytes, 11 input fields, > CCCD 01 00: report 1 (keyboard), + hosting: keyboard media keys. The view jumps to keyboard.
    If not
    pairing failed: the keyboard left pairing mode, or it still has an old bond with the board: forget, remove it on the keyboard side (pairing mode again), connect, host.
  7. type on your keyboardwith your handsyour keyboard/mouse on
    Does
    Each key press is a notification: the board compares it with the previous one and adds the newly pressed keys. Backspace deletes, Enter starts a new line, Esc clears.
    You should see
    Your text on the keyboard view with a blinking cursor; the modifier caps light amber while you hold Shift, Ctrl, Alt or Cmd; the media keys show a violet toast.
    If not
    Wrong letters (y and z swapped)? See the next command.
  8. layout deserial monitorpaired as keyboard/MIDI
    Does
    Key codes are positions, not letters. The board turns them into characters with the layout you choose: US or German.
    You should see
    - layout German (QWERTZ): the same keys, other letters. Now the key printed Z gives z, and ä ö ü ß appear.
  9. (click to the reports view)push button / BOOTpaired as keyboard/MIDI
    Does
    The raw input reports, newest at the bottom, each byte coloured by the Report Map field it belongs to.
    You should see
    #1 kbd 02 00 0B 00 00 00 00 00 with 02 amber (Left Shift) and 0B teal (the H key), and the decoded line under it.
  10. boot on, then hostserial monitorpaired as keyboard/MIDI
    Does
    Boot protocol: the fixed 8-byte format every BIOS understands, without reading the Report Map. Compare with report protocol.
    You should see
    > CCCD 01 00: report 0 (boot keyboard) and bootK rows on the reports view. boot off switches back.
    If not
    no Protocol Mode: this device has no boot mode: some keyboards don't offer it.
  11. disconnect, then the mouse: pairing mode, connect <n>, long presswith your handsyour keyboard/mouse on
    Does
    A mouse has no keys and no screen, so pairing falls back to Just Works (no digits). Its Report Map describes buttons, X, Y and the wheel with whatever bit sizes it likes.
    You should see
    + secured: Just Works, bonded, + hosting: mouse, and the mouse view: left button draws, right changes colour, middle clears, the wheel sets the brush.
    If not
    The cursor races across: that mouse reports in large steps; the board already halves them.
  12. unplug and replug the boardwith your handsyour keyboard/mouse on
    Does
    The bond (keys) is saved in NVS. When the keyboard advertises again (press a key to wake it), the board recognises its address and reconnects.
    You should see
    + bonded Bench Keys is back: reconnecting, then + secured: … with no passkey, and + hosting.
    If not
    Keyboards that hide behind a changing private address (RPA) may not be recognised: connect + host by hand then.
  13. connect <n> on your JBL speakerserial monitoryour keyboard/mouse on
    Does
    Explore a device that isn't a keyboard. Only the public basics are read, nothing is written.
    You should see
    A few services, mostly one long vendor UUID, and - JBL app's own service only: audio uses Classic BT. The audio itself never goes over BLE on this speaker, and this chip has no Classic Bluetooth.
    If not
    Not in the list: it only advertises BLE while the JBL app is looking, or right after power-on.
  14. forgetserial monitorno phone needed
    Does
    Deletes every bond on the board.
    You should see
    - every bond deleted: pair again to use a keyboard. Remove the board on the keyboard side too (pairing mode), or it will refuse the next pairing.

Steps

0 of 9 ticked. Ticks are saved in this browser.

Explore only connects to devices you pick and only reads the standard public values (name, appearance, maker, model, firmware, battery, PnP ID); it never writes to a device, except the two standard HID settings on a keyboard or mouse you host (the CCCD to subscribe, Protocol Mode for boot). Only connect to your own devices. One link at a time: disconnect before connecting to the next device. A keyboard bonded to the board may stop working with the Mac on that channel until you pair it there again. The keyboard view uses the screen's built-in font, which has ä ö ü Ä Ö Ü ß but no €. BLE keeps the report ID out of the notification: it lives in the Report Reference descriptor (2908), which is why the bytes on the reports view start with the data.

Preview: what you should see

Interactive BLE scanner and GATT monitor simulating NimBLE advertising discovery and characteristic updates.

  • Key concepts: central role, service discovery, HID over GATT (HOGP), Report Map parsing, passkey entry as central, CCCD subscribe, key codes vs layouts, bond & reconnect.
  • 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 pinout

Explore 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?
Explore only connects to devices you pick and only reads the standard public values (name, appearance, maker, model, firmware, battery, PnP ID); it never writes to a device, except the two standard HID settings on a keyboard or mouse you host (the CCCD to subscribe, Protocol Mode for boot). Only connect to your own devices. One link at a time: disconnect before connecting to the next device. A keyboard bonded to the board may stop working with the Mac on that channel until you pair it there again. The keyboard view uses the screen's built-in font, which has ä ö ü Ä Ö Ü ß but no €. BLE keeps the report ID out of the notification: it lives in the Report Reference descriptor (2908), which is why the bytes on the reports view start with the data.
If “uv run pio run -d labs/ble-lab-b8 -e ble-lab-b8 -t upload” does not work
“Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
If “put the keyboard in pairing mode” does not work
Not there: it is still connected to the Mac (switch channel, or remove it in the Mac's Bluetooth settings). Apple Magic Keyboards use Classic Bluetooth and never show up here.
If “connect 1” does not work
no answer from …: it stopped advertising (pairing mode times out after ~60 s): start it again.
If “host (or a long press)” does not work
pairing failed: the keyboard left pairing mode, or it still has an old bond with the board: forget, remove it on the keyboard side (pairing mode again), connect, host.
If “type on your keyboard” does not work
Wrong letters (y and z swapped)? See the next command.
If “boot on, then host” does not work
no Protocol Mode: this device has no boot mode: some keyboards don't offer it.
If “disconnect, then the mouse: pairing mode, connect <n>, long press” does not work
The cursor races across: that mouse reports in large steps; the board already halves them.
If “unplug and replug the board” does not work
Keyboards that hide behind a changing private address (RPA) may not be recognised: connect + host by hand then.
If “connect <n> on your JBL speaker” does not work
Not in the list: it only advertises BLE while the JBL app is looking, or right after power-on.
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.