ESP ZeroCode AI · Community

Robo Atari

Robo Atari

Robo Atari takes reinforcement learning off the emulator and into the real world. A camera watches a screen running an Atari 2600 game. An agent reads the frames and moves a real CX40 joystick through a small robot, the Robotroller. Camera noise, motor latency and wear are all part of the problem, just like on a real robot. The original build drives the joystick with Dynamixel XC330 servos. We ported the whole stack to Feetech STS3215 servos, the cheap bus servos used by the LeRobot SO-100/SO-101 arms, so more labs and students can build it. We also added an ESP32 bridge that reads the joystick and streams its state over USB at 1 kHz, so the emulator can run on any x86 Linux laptop as well as a Raspberry Pi.

ESP32
Download the firmware Open-source licences Fork it in the studio

What it does

Manual

Device Type
A USB-serial joystick bridge: it turns a vintage Atari CX40 joystick plugged into a DB9 port into a 1 kHz binary gamepad stream that any host program can read from /dev/ttyUSB0, with no drivers, no HID profile and no wireless stack. It solves 'I have a real 2600 stick and want to use it as the input for an emulator or robot'. The device is standalone: it has no smart-home framework, no BLE, no ESP-NOW, no Wi-Fi and no network configuration.

Hardware
chip: esp32 — board: esp32-devkitc (ESP32-DevKitC, classic ESP32-D0WD-V3, PlatformIO id esp32dev, IDF target esp32) — power: From the host over the same USB cable that carries the data. No external supply, no battery. — usb: The board has no native USB. It talks through its onboard USB-to-UART bridge (CP2102 or CH340) and appears on the host as /dev/ttyUSB0. There is no USB-HID, BLE or gamepad profile. — gpios: gpio: GPIO14 — role: DB9 pin 1 (Up) — input, internal pull-up · gpio: GPIO13 — role: DB9 pin 2 (Down) — input, internal pull-up · gpio: GPIO25 — role: DB9 pin 3 (Left) — input, internal pull-up · gpio: GPIO26 — role: DB9 pin 4 (Right) — input, internal pull-up · gpio: GPIO27 — role: DB9 pin 6 (Fire) — input, internal pull-up · gpio: GND — role: DB9 pin 8 (common) — ground · gpio: GPIO0 — role: BOOT button — left untouched so download mode still works — peripherals: part: Atari CX40 joystick on a DB9 female port — notes: Five normally-open switches; closing a switch connects its line to the common (DB9 pin 8 = GND). No external resistors — the ESP32's internal pull-ups are used. A closed switch reads LOW, so pressed = 1 after inversion. Paddle lines and +5V are not used: DB9 pins 5, 7 and 9 are NOT CONNECTED, and pin 7 (+5V) must never reach an ESP32 GPIO (the pads are not 5 V tolerant). The firmware never drives any DB9 line.

Inputs
kind: joystick — label: Atari CX40 joystick (up / down / left / right / fire) — hardware: Five GPIO inputs with internal pull-ups, active low, sampled every 1 ms into one 5-bit value: bit0 up, bit1 down, bit2 left, bit3 right, bit4 fire (1 = pressed). — behavior: All five pins are read together and the whole 5-bit value is debounced as one unit so a diagonal or direction+fire change appears in a single frame. Debounce: if raw == candidate, increment a saturating counter and adopt the candidate as stable after 3 equal samples (~3 ms); if raw != candidate, restart the candidate. At startup the stable state and candidate are seeded from one initial read before streaming begins. Diagonals are simply two bits set (the CX40 closes two switches at once).

Outputs
kind: serial-stream — label: USB-serial binary frame stream — hardware: UART0 behind the board's USB-UART bridge, 115200 baud, 8N1, no flow control. — behavior: Exactly one byte is sent every 1 ms whether or not anything changed — a steady 1000 frames/s, never on-change-only. Byte = 0x80 | stable_state: bit 7 always 1 (frame marker), bits 5-6 reserved and always 0, bits 0-4 the switch state; valid range 0x80-0x9F, idle (nothing pressed) = 0x80. Examples: 0x81 up, 0x82 down, 0x84 left, 0x88 right, 0x90 fire, 0x89 up+right, 0x91 up+fire. Only the debounced state is sent, never the raw reading. No framing, checksum, header or handshake — the host keeps the newest byte with bit 7 set and drops anything else. Nothing else may be written to this UART during normal operation: no boot log, no app log, no printf, no banner.

Commissioning
method: none — instructions: No onboarding: there is no network. Plug the joystick into the DB9 port, plug the board into the host with a USB cable, and the byte stream starts. The only host action is to flash the firmware once with `idf.py set-target esp32 && idf.py build && idf.py -p /dev/ttyUSB0 flash`.

Business Logic
powerOnBehavior: On reset the firmware seeds the stable state from one immediate read of the five pins, then starts the 1 kHz loop: sample → debounce → write one byte to UART0. Debug mode always starts OFF. No LED indication (the DevKitC has only its power LED). — automationRules: Send one frame every 1 ms regardless of change (steady 1000 frames/s). · Send the debounced state, never the raw reading. · While debug mode is ON, stop the binary stream and instead print one line on each stable-state change: `up=%d down=%d left=%d right=%d fire=%d`. Turning debug OFF resumes the binary stream. — dayToDayOperation: Plug in and play. The host (an emulator front-end, a robot controller, a test script) opens /dev/ttyUSB0 read-only at 115200 8N1 and reads bytes; every byte with bit 7 set is a fresh frame at most 1 ms old. The user never interacts with the device itself except through the joystick. — bringUpCommands: 'd' — toggle debug mode, replies `\r\n[bridge] debug ON\r\n` / `\r\n[bridge] debug OFF\r\n`. · '?' — print one line `\r\n[bridge] up=%d down=%d left=%d right=%d fire=%d (0x%02X)\r\n` with the stable state and its frame byte. · All other host bytes are ignored. The host normally opens the port read-only, so these commands never fire during a real run.

Factory Reset
trigger: There is no user reset procedure and no stored configuration — nothing to reset. A power cycle or the board's EN button restarts the device, which re-seeds its state and always comes up in the default mode (binary stream, debug OFF). — effect: n/a

Failure Modes
scenario: Joystick unplugged or DB9 port empty — behavior: With no switches closed every line is pulled high, so the device streams a steady 0x80 exactly as if idle. No error is reported. · scenario: USB cable unplugged / host disappears — behavior: The board loses power and stops; there is no stored state. Re-plugging re-runs power-on behavior. · scenario: Host reopens the port or resets — behavior: Nothing to renegotiate — no handshake. The host just starts reading mid-stream and keeps the next byte with bit 7 set (≤1 ms away). · scenario: Boot log would pollute the stream — behavior: Bootloader and app log levels are compiled out (CONFIG_BOOTLOADER_LOG_LEVEL_NONE, CONFIG_LOG_DEFAULT_LEVEL_NONE) so the port carries no ASCII from power-on onward unless 'd' or '?' is sent. · scenario: Stale raw reading on a noisy or bouncy switch — behavior: The 3-sample (~3 ms) whole-value debounce rejects contact bounce; releasing a switch returns to 0x80 within ~3 ms with no stuck bits. · scenario: Loop pacing drift — behavior: CONFIG_FREERTOS_HZ=1000 is required — at the default 100 Hz pdMS_TO_TICKS(1) is 0 and the loop would silently run at 100 Hz. Pacing uses vTaskDelayUntil (1 tick = 1 ms) or an esp_timer microsecond deadline, so the task yields to the idle task and the task watchdog stays happy.

Custom Behavior
implementation: ESP-IDF v6.0, plain C, single app component (main/), project name joystick_bridge. Use the UART driver (uart_driver_install + uart_write_bytes / uart_read_bytes with 0 timeout) for both directions; read host bytes non-blockingly each loop iteration. Pin numbers, DEBOUNCE_SAMPLES, the sample rate and the baud rate are named constants at the top of main/joystick_bridge.c. GPIO0/BOOT is never configured, read or given an interrupt. — sdkconfigDefaults: CONFIG_IDF_TARGET="esp32" · CONFIG_ESP_CONSOLE_UART_DEFAULT=y · CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 · CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y · CONFIG_BOOTLOADER_LOG_LEVEL=0 · CONFIG_LOG_DEFAULT_LEVEL_NONE=y · CONFIG_LOG_DEFAULT_LEVEL=0 · CONFIG_FREERTOS_HZ=1000 — deliverables: CMakeLists.txt (top level, project joystick_bridge) · main/CMakeLists.txt · main/joystick_bridge.c · sdkconfig.defaults · README.md with the wiring table and build/flash commands — acceptanceCriteria: Host counts 1000 ± 5 bytes per second, 100% with bit 7 set. · Idle stream is all 0x80. · Each switch alone gives 0x81 / 0x82 / 0x84 / 0x88 / 0x90; up+right gives 0x89; up+fire gives 0x91. · Releasing a switch returns to 0x80 within ~3 ms with no stuck bits. · No ASCII bytes appear on the port from power-on onward (unless 'd' or '?' is sent). · Holding BOOT during reset still enters download mode (GPIO0 untouched). — outOfScope: Host-side software (emulator front-ends, drivers, a gamepad shim) is out of scope; the device only produces the byte stream.

Published 11 Nov 2026 · version 2
Firmware and source licensed Apache-2.0; photos and text CC-BY-4.0.
The firmware includes open-source software — open-source licences and notices; some components may be used only with Espressif chips.
Built with ESP ZeroCode AI — describe a device, get production firmware.
Terms of Service · Privacy Policy