Turn the board into a wireless Bluetooth mouse β tilt to move the cursor, tap the touchscreen to click.
The QMI8658 gyroscope (256 dps range, 128 LSB/dps) streams angular velocity at ~120 Hz. The sketch maps gyro X/Y directly to mouse delta X/Y after applying a dead-zone of Β±1.5 Β°/s to eliminate drift at rest.
The CST816T capacitive touch controller is polled each loop β a finger-down event fires a MOUSE_LEFT click via the BLE HID stack. The ST7789V2 display shows a live crosshair that tracks the simulated cursor position.
| Step | Detail |
|---|---|
| IMU read | 12 bytes from QMI8658 starting at 0x35 (AX_L). Gyro X/Y extracted from bytes 6β9 (raw[3], raw[4]). Scale: 128 LSB/Β°/s at 256 dps range. |
| Dead-zone | If |gy| < 1.5 β dx = 0; if |gx| < 1.5 β dy = 0. Eliminates jitter when held still. |
| Sensitivity scale | dx = gy Γ 0.35, clamped to int8_t (β127 β¦ 127). Lower SENSITIVITY = slower, more precise. |
| BLE move | bleMouse.move(mx, my) only called when mx β 0 or my β 0 β avoids unnecessary HID reports. |
| Touch click | Rising edge on touch (lastTouch = false β true) fires bleMouse.click(MOUSE_LEFT) once per tap. |
| Display update | ~30 fps (33 ms timer). Erases old crosshair in BLACK, redraws at new position in CYAN. Click briefly flashes WHITE. |
| Register | Value | Effect |
|---|---|---|
| CTRL1 (0x02) | 0x40 | Address auto-increment on burst reads |
| CTRL2 (0x03) | 0x13 | Accelerometer Β±4 g, 250 Hz ODR |
| CTRL3 (0x04) | 0x43 | Gyroscope Β±256 dps, 250 Hz ODR β tighter range for cursor precision |
| CTRL7 (0x08) | 0x03 | Enable both accel and gyro |
DC=4, CS=5, SCK=6, MOSI=7 RST=8, BL=15 Display: ST7789V2 240Γ280 IPS row_offset=20
SDA=11, SCL=10 400 kHz QMI8658 β 0x6B (6-axis IMU) CST816T β 0x15 (touch)
Uses the T-vK/ESP32-BLE-Mouse library. The device advertises as "ESP32 Air Mouse" (manufacturer: Waveshare). Once paired, the host OS sees it as a standard HID mouse β no drivers needed.
SENSITIVITY = 0.35f // higher = faster DEAD_ZONE = 1.5f // Β°/s threshold Poll rate = 8 ms // ~120 Hz
Lower SENSITIVITY for fine-grained desktop use; raise DEAD_ZONE in vibration-prone environments.
Full sketch in the ESP32-S3-LCD repo β sketches/ble_air_mouse/ble_air_mouse.ino.
git clone https://github.com/binRick/ESP32-S3-LCD bash flash-sketch-002-ble-air-mouse.sh