Skip to content

Instantly share code, notes, and snippets.

@dglaude
Created October 20, 2025 00:26
Show Gist options
  • Select an option

  • Save dglaude/44956c676aed5651beadc84ab82bedad to your computer and use it in GitHub Desktop.

Select an option

Save dglaude/44956c676aed5651beadc84ab82bedad to your computer and use it in GitHub Desktop.
AI generated BLE to USB-HID for Belgian French keyboard

I needed a way to type my computer from my phone, acting as a keyboard. But I cannot add software to my computer, so I needed to be a USB-HID device. I asked Gemini for help, and he produced this code, first for US EN keyboard, but then I addapted it for Belgian French.

For the Belgian French keyboard, I went to Neradoc repo, but Î could only find French keyboard: https://github.com/Neradoc/Circuitpython_Keyboard_Layouts

So Î went to his page: https://www.neradoc.me/layouts/ Gave it the Belgian French keyboar page: https://kbdlayout.info/kbdbe And it generated for me the needed Python file

The trick is then to use the application "Bluefruit Connect", use the UART mode, type your text and send. This will be send to your computer as keystroke.

Works for me

import time
import board
import usb_hid
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from keyboard_layout_win_be import KeyboardLayout as KeyboardLayoutAZERTY
# --- 1. Set up USB-HID Keyboard ---
# We use Keycode for special keys and KeyboardLayoutUS for typing strings
try:
kbd = Keyboard(usb_hid.devices)
# layout = KeyboardLayoutUS(kbd)
layout = KeyboardLayoutAZERTY(kbd)
print("USB Keyboard HID enabled")
except Exception as e:
print(f"Error setting up USB HID: {e}")
print("Continuing without USB keyboard.")
kbd = None
layout = None
# --- 2. Set up BLE ---
ble = BLERadio()
uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)
# Give your device a unique name
ble.name = "CircuitPython-BLE-KB"
# --- 3. Main Loop ---
print("Advertising BLE UART service...")
ble.start_advertising(advertisement)
while True:
# Wait for a BLE connection
while not ble.connected:
pass
print("BLE CONNECTED")
# While we stay connected
while ble.connected:
if uart.in_waiting > 0:
try:
# Read all available bytes
data = uart.read(uart.in_waiting)
# Decode bytes to a string
text = data.decode().strip()
print(f"Received via BLE: {text}")
# Type the string over USB
if layout:
layout.write(text)
except Exception as e:
print(f"Error processing data: {e}")
# If we got here, we're disconnected
print("BLE DISCONNECTED")
print("Re-advertising...")
ble.start_advertising(advertisement)
@dglaude
Copy link
Author

dglaude commented Oct 20, 2025

It seems that there are plenty of application that turn your (android) phone into a BLE keyboard+mouse.
So going the USB-HID was overkill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment