Bluetooth LE · lesson 6 of 8
A Bluetooth keyboard and a remote for your music
The board becomes a real Bluetooth keyboard: the same HID service every wireless keyboard has, so phones, Macs and PCs use it with their own driver. Its button turns into a remote: play/pause and skip the music on your phone (which can be playing on your JBL speaker), change the volume, click through slides, or type text you send from the serial monitor. You write the Report Map that tells the computer what our bytes mean, and you see why a keyboard never sends letters, only key numbers.
Pair the board as a keyboard, control your music with the button, and type text in the right layout.
You're done when
- Your phone or Mac lists Bench B6 as a connected keyboard, and the screen's status bar shows the lock (encrypted) and the key (bonded).
- A click on the media view pauses and resumes your music; a double-click skips the track; touching GPIO 2 turns it up.
type yestypes “yes”, not “zes”:layoutmatches the computer's keyboard setting.- On the keys view you can read a press as bytes: modifier bits, key number, and the all-zero release after it.
On the board
You will learn
- HID over GATT
- report map
- key numbers vs characters
- keyboard layouts
- consumer control
- bonding
- media remote
uv run pio run -d labs/ble-lab-b6 -e ble-lab-b6 -t uploadParts required
Parts library- ESP32-S3-DevKitC-1 + USB-C data cable
- 1.9″ ST7789 screen
- Smartphone (Bluetooth)
- Optional: Push button
A key press, from button to letter
Type in the box or press a key below and follow it: the board turns the character into a key number with ITS layout setting, sends 8 bytes, and the computer turns the number back into a character with ITS layout. Set the two layouts differently and type yes: that's the bug layout de fixes.
USB/BLE HID report descriptor breakdown for keyboard keycodes and consumer media controls. Type in the box or press a key below and follow it: the board turns the character into a key number with ITS layout setting, sends 8 bytes, and the computer turns the number back into a character with ITS layout. Set the two layouts differently and type yes: that's the bug layout de fixes.
- Key concepts: HID over GATT, report map, key numbers vs characters, keyboard layouts, consumer control, bonding, media remote.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
Why the board can't play to your speaker
Your JBL plays music over Classic Bluetooth audio. The ESP32-S3 only has Bluetooth LE, so it can't stream to it, but it can be the remote for the phone that does. Press a media key to follow it, or try the direct path to see where it fails.
Interactive BLE media remote simulator sending play/pause and volume HID reports. Your JBL plays music over Classic Bluetooth audio. The ESP32-S3 only has Bluetooth LE, so it can't stream to it, but it can be the remote for the phone that does. Press a media key to follow it, or try the direct path to see where it fails.
- Key concepts: HID over GATT, report map, key numbers vs characters, keyboard layouts, consumer control, bonding, media remote.
- Signals & pins: 3V3 (VCC), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC), GPIO10 (CS).
Interactive diagram loads after page initialization.
What the screen shows
Six views. Media and slides are modes: there the button is the remote (click, double-click, hold), and a 2-second hold moves on. On the other views a click moves on as usual.
Gallery of ST7789 screens shown across the ESP32-S3 Bluetooth LE labs. Six views. Media and slides are modes: there the button is the remote (click, double-click, hold), and a 2-second hold moves on. On the other views a click moves on as usual.
- Key concepts: HID over GATT, report map, key numbers vs characters, keyboard layouts, consumer control, bonding, media remote.
- 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-b6 -e ble-lab-b6 -t uploadMac terminalno phone needed- Does
- Builds lab B6 and flashes it (no new downloads: NimBLE came with B1).
- You should see
ble-lab-b6: NimBLE 2.5.1 up,advertising as keyboard "Bench B6", the command list. The screen opens on the media view: “pair me: Bluetooth settings > Bench B6”.- If not
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
Bluetooth settings → Bench B6 → Connect / Pairon your phonephone paired- Does
- Your phone or Mac connects, reads the Report Map, asks to pair (HID needs encryption), and stores a bond so it reconnects by itself next time.
- You should see
+ connected, then+ secured: Just Works, bonded, key 16 B. The status bar shows the linked rings, a violet lock and a key. A Mac may open the Keyboard Setup Assistant: close it, or press the key it asks for and pick ISO (German) or ANSI (US).- If not
- Listed but won't connect:
forgethere AND “Forget This Device” on the phone, then pair again. A bond kept on only one side is the usual cause.
(media view) click · double-click · touch GPIO 2push button / BOOTpaired as keyboard/MIDI- Does
- Start music on the phone (to its speaker, earbuds or your JBL). Click = play/pause, double-click = next track, hold under 2 s = mute, touch the wire on GPIO 2 / 1 (after
touch on) = volume up / down. - You should see
- The icon ripples, a dot runs board → phone → speaker, and the music reacts. The monitor prints
> media key: play/pause (usage 0CD). - If not
- Nothing happens? The app must have audio focus: play something first. On a Mac, Music/Spotify react; a browser tab may not.
type hello benchserial monitorpaired as keyboard/MIDI- Does
- Open Notes (or any text field) on the paired device, then type this in the monitor. The board queues 2 reports per character (press, release) and sends 6 per frame, 8 ms apart.
- You should see
- “hello bench” appears on the phone or Mac. The typer view fills its progress bar, then says
typed 11 keys. - If not
- Only the line says
not paired yet? Pair first. Letters come out wrong: seelayout.
layout de (or layout us)serial monitorpaired as keyboard/MIDI- Does
- Tells the board which layout the COMPUTER is set to, so it picks the right key for each character. Saved in NVS.
- You should see
layout German (QWERTZ) (saved). Nowtype yesgives “yes” on a German Mac. Characters the layout needs AltGr/Option for (@ [ ] { } \ | ~) are skipped with a warning.- If not
- Still y/z swapped: the computer's layout is the other one. Check the input menu in the Mac's menu bar.
key cmd+spaceserial monitorpaired as keyboard/MIDI- Does
- One key or a combo: modifiers (cmd, ctrl, alt, shift) plus a key (enter, tab, esc, arrows, f1-f12, a letter).
- You should see
- Spotlight opens on the Mac (on an iPhone with a keyboard, the search too). The keys view shows modifier byte
08(left GUI) and key2C(space). - If not
- Windows:
key win+ropens Run,key ctrl+alt+deletethe security screen.
snippet my@mail.example (then double-click on typer)serial monitorpaired as keyboard/MIDI- Does
- Saves a text in NVS; a double-click on the typer view (or
snippetalone) types it. A tiny macro pad. - You should see
snippet saved, and the text on the typer view.
(hold the button 2 s) → slides viewpush button / BOOTpaired as keyboard/MIDI- Does
- Open a presentation (Keynote, PowerPoint, Google Slides in present mode). Click = right arrow (next), double-click = left arrow, hold under 2 s = b (black screen).
- You should see
- The slide on the screen slides in from the side you moved to; the deck on the computer follows.
(click to the keys view)push button / BOOTpaired as keyboard/MIDI- Does
- The last reports, byte by byte: the modifier bits, the key numbers, and what each press types with the board's layout.
- You should see
down mod 02 key 04 types 'A'thenup all zerofor a capital A.
Steps
0 of 7 ticked. Ticks are saved in this browser.
While an iPhone or iPad is connected to a hardware keyboard, its on-screen keyboard hides: disconnect the board (or switch Bluetooth off) to get it back. To unpair, forget the board on both sides (forget here, “Forget This Device” there). The ESP32-S3 has Bluetooth LE only: it can't stream audio to a speaker or headphones (that's Classic Bluetooth, A2DP), so the board controls the phone and the phone plays to your JBL. Volume and track keys go to whichever app has audio focus. Hosts disagree on what Option/AltGr characters live where, so the German table only types what it can type the same way on Mac and Windows.
Preview: what you should see
Interactive BLE scanner and GATT monitor simulating NimBLE advertising discovery and characteristic updates.
- Key concepts: HID over GATT, report map, key numbers vs characters, keyboard layouts, consumer control, bonding, media remote.
- 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
- Touch sensor
Fourteen pins that feel a finger through capacitance
- 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
Troubleshooting & hardware gotchas
See all 17 ESP32-S3 hardware gotchas- What if it does not work or behaves unexpectedly?
- While an iPhone or iPad is connected to a hardware keyboard, its on-screen keyboard hides: disconnect the board (or switch Bluetooth off) to get it back. To unpair, forget the board on both sides (
forgethere, “Forget This Device” there). The ESP32-S3 has Bluetooth LE only: it can't stream audio to a speaker or headphones (that's Classic Bluetooth, A2DP), so the board controls the phone and the phone plays to your JBL. Volume and track keys go to whichever app has audio focus. Hosts disagree on what Option/AltGr characters live where, so the German table only types what it can type the same way on Mac and Windows. - If “uv run pio run -d labs/ble-lab-b6 -e ble-lab-b6 -t upload” does not work
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
- If “Bluetooth settings → Bench B6 → Connect / Pair” does not work
- Listed but won't connect:
forgethere AND “Forget This Device” on the phone, then pair again. A bond kept on only one side is the usual cause. - If “(media view) click · double-click · touch GPIO 2” does not work
- Nothing happens? The app must have audio focus: play something first. On a Mac, Music/Spotify react; a browser tab may not.
- If “type hello bench” does not work
- Only the line says
not paired yet? Pair first. Letters come out wrong: seelayout. - If “layout de (or layout us)” does not work
- Still y/z swapped: the computer's layout is the other one. Check the input menu in the Mac's menu bar.
- If “key cmd+space” does not work
- Windows:
key win+ropens Run,key ctrl+alt+deletethe security screen. - 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.