A beginner-friendly Arduino library for creating Bluetooth Low Energy (BLE) controllers that connect to the DF Pong browser game.
| Board | Status | BLE Library |
|---|---|---|
| Arduino UNO R4 WiFi | Tested | ArduinoBLE (built-in) |
| Arduino Nano 33 IoT | Tested | ArduinoBLE (built-in) |
| Arduino Nano 33 BLE / BLE Sense | Supported | ArduinoBLE (built-in) |
| ESP32 / ESP32-S3 / ESP32-C3 | Supported | NimBLE-Arduino (install separately) |
Note: ESP32-S2 does not have Bluetooth and is not supported.
The DF Pong game uses the Web Bluetooth API, which has limited browser support.
| Browser | Desktop | Mobile |
|---|---|---|
| Chrome | ✅ Supported | ✅ Android only |
| Edge | ✅ Supported | ✅ Android only |
| Opera | ✅ Supported | ✅ Android only |
| Safari | ❌ Not supported | ❌ Not supported |
| Firefox | ❌ Not supported | ❌ Not supported |
| iOS (all browsers) | ❌ Not supported | ❌ Not supported |
Important Notes:
- iOS devices (iPhone/iPad) do not support Web Bluetooth in any browser, including Chrome
- Use Chrome on desktop for the most reliable experience
- On Android, use Chrome, Edge, or Opera
- Open Arduino IDE
- Go to Sketch > Include Library > Manage Libraries...
- Search for "DFPongController"
- Click Install With Dependencies
- Download this repository as a ZIP
- In Arduino IDE, go to Sketch > Include Library > Add .ZIP Library...
- Select the downloaded ZIP file
No additional libraries needed - ArduinoBLE is included with the board package.
Just make sure you have the correct board package installed:
- UNO R4 WiFi: Install "Arduino UNO R4 Boards" via Boards Manager
- Nano 33 IoT: Install "Arduino SAMD Boards" via Boards Manager
- Nano 33 BLE: Install "Arduino Mbed OS Nano Boards" via Boards Manager
ESP32 requires the NimBLE-Arduino library:
- Go to Sketch > Include Library > Manage Libraries...
- Search for "NimBLE-Arduino" by h2zero
- Click Install
Once your code is uploaded:
- Open the controller test page: https://digitalfuturesocadu.github.io/df-pong/game/test/
- Select your controller number from the dropdown
- Click Connect
- Your controller should connect and show movement when you press buttons
#include <DFPongController.h>
DFPongController controller;
void setup() {
pinMode(2, INPUT_PULLUP); // UP button
pinMode(3, INPUT_PULLUP); // DOWN button
// IMPORTANT: Set YOUR unique controller number (1-242)
controller.setControllerNumber(1); // <-- CHANGE THIS!
controller.setStatusLED(LED_BUILTIN);
controller.begin();
}
void loop() {
controller.update(); // Required every loop!
if (!digitalRead(2)) {
controller.sendControl(UP);
} else if (!digitalRead(3)) {
controller.sendControl(DOWN);
} else {
controller.sendControl(NEUTRAL);
}
}- Uses the built-in LED on pin
LED_BUILTIN - Tested and verified working
- Uses the built-in LED on pin
LED_BUILTIN - Button pins may need adjustment based on your wiring
- Same setup as Nano 33 IoT
- Built-in sensors can be used as controller inputs
- Requires NimBLE-Arduino library (see installation above)
- Use
LED_BUILTINor specify your LED pin (varies by board) - RSSI reading returns approximate value (-50 dBm) due to NimBLE limitations
- ESP32-S2 is NOT supported (no Bluetooth hardware)
| Method | Description |
|---|---|
setControllerNumber(int n) |
Required. Set your unique number (1-242) |
setStatusLED(int pin) |
Set LED pin for connection status |
setDebug(bool enabled) |
Enable Serial debug messages |
begin() |
Initialize BLE with default name |
begin(const char* name) |
Initialize BLE with custom device name |
| Method | Description |
|---|---|
update() |
Required. Call every loop() iteration |
sendControl(int direction) |
Send UP, DOWN, or NEUTRAL |
| Method | Returns | Description |
|---|---|---|
isConnected() |
bool |
True if BLE connected |
isReady() |
bool |
True if connected AND handshake complete |
getRSSI() |
int |
Signal strength in dBm (-50 excellent, -90 poor) |
hasStrongSignal() |
bool |
True if signal > -70 dBm |
getControllerNumber() |
int |
Returns configured controller number |
| Constant | Value | Description |
|---|---|---|
UP |
1 | Paddle moves up |
DOWN |
2 | Paddle moves down |
NEUTRAL |
0 | No movement |
| Pattern | Meaning |
|---|---|
| Slow blink (500ms) | Disconnected, advertising |
| Fast blink (100ms) | Connected, handshaking |
| Solid ON | Ready to play |
Each player/device needs a unique controller number between 1 and 242. This ensures devices can be identified correctly in the game.
controller.setControllerNumber(1); // Player 1
controller.setControllerNumber(2); // Player 2
// ... up to 242You forgot to set your controller number. Add this before begin():
controller.setControllerNumber(YOUR_NUMBER);- Make sure the test page or game is open in your browser
- Check that your controller number matches the dropdown selection
- Try refreshing the browser page
- Make sure Bluetooth is enabled on your computer/phone
Use getRSSI() to check signal strength:
if (controller.isConnected()) {
Serial.print("Signal: ");
Serial.print(controller.getRSSI());
Serial.println(" dBm");
}-30 to -50: Excellent-50 to -70: Good-70 to -90: Weak (move closer)< -90: Very weak (connection may drop)
Make sure you installed the NimBLE-Arduino library:
- Sketch > Include Library > Manage Libraries...
- Search for "NimBLE-Arduino"
- Install the library by h2zero
The library includes several examples to help you get started, from basic templates to creative control schemes:
| Example | Description |
|---|---|
| 00_StartTemplate | Empty template with commented structure for creating your own custom controller |
| 01_SimpleDigital | Basic two-button controller - paddle moves while buttons are held |
| 02_ClickDetection | Tap-based control - paddle moves once per click instead of continuous hold |
| 03_ChordedInputs | Use button combinations (chords) for multiple controls with fewer buttons |
| 04_GravityClick | Flappy Bird-style control - click to go up, gravity pulls you down |
| 05_SlotMachine | Chaotic controller where buttons only work a percentage of the time |
Access these examples in Arduino IDE via File > Examples > DFPongController.
MIT License - see LICENSE for details.
Created by Digital Futures at OCAD University.