Build a retro-style game console powered by an ESP32 that plays Outlaws, a fast-paced Western-themed shooter. The game runs entirely on the board and streams to any device on your WiFi network—laptop, phone, or tablet—making it a multiplayer experience without needing extra hardware.
This guide covers wiring the PS2 joystick module for analog stick control and two push buttons for game actions, flashing the firmware that includes the complete game, and connecting to play. The joystick outputs are dead-zoned and centered on the board, while the WebSocket connection keeps all players in sync at 60 Hz. You'll get a wiring diagram, parts list, and step-by-step assembly instructions to get your console running in minutes.
Wiring diagram
Gather all the parts
Assemble it in 7 steps
1. Lay out the parts
Put the SSK1, the joystick module and the two push buttons on a breadboard or your desk. You need about 9 jumper wires. Leave the USB cable unplugged while wiring.
2. Power the joystick from 3V3
Joystick GND → G (ground). Joystick +5V → 3V3 (power). Even though the pin is labelled +5V, it must go to 3V3.
- On 5V the stick's outputs go above 3.3 V and can damage the ESP32's analog input pins (GPIO 1 and 2).
3. Connect the joystick signals
VRx → GPIO 1 (left/right). VRy → GPIO 2 (forward/back). SW → GPIO 7 (stick click). GPIO 1 and 2 are analog pins that keep working while WiFi is on.
- If the stick feels sideways or upside down, don't rewire: the one-time Controller setup in the game fixes any orientation.
4. Wire button A (punch / fire)
One leg → GPIO 4, the other leg → G. No resistor is needed: the board turns on its internal pull-up, so pressed reads LOW.
- On a 4-leg button, use two diagonally opposite legs so the switch is always between them.
5. Wire button B (sprint / handbrake)
One leg → GPIO 6, the other leg → G, the same way as button A.
6. Power up with the stick centred
Plug a USB-C cable into the SSK1's Flashing / Logging port. Don't touch the stick for the first second: the board measures its centre position at boot.
- The board's red power LED lights when it has power.
7. Join the WiFi and play
Join the WiFi "Outlaws" (password schematik) and open http://192.168.4.1 (or http://outlaws.local). The first time, follow the Controller setup: push the stick forward, then right, then press the button you want to fire with. The keyboard works too.
Review all connections
1. Connections between "joy1" and "ESP32"
2. Connections between "btnA" and "ESP32"
3. Connections between "btnB" and "ESP32"
Deploy the firmware
// Outlaws - hosted entirely on the SSK1 (ESP32-S3). Schematik edition: the game is built into
// the firmware (src/web_assets_*.cpp), so only firmware is flashed - no filesystem upload.
//
// 1. The board joins your WiFi (include/secrets.h) and prints its address, e.g.
// http://outlaws.local. If that fails within 15 s it opens its own network:
// SSID "Outlaws", password "schematik", at http://192.168.4.1.
// 2. Open that address on any laptop/phone on the same network.
// 3. The board serves the game from flash and streams one controller line at 60 Hz
// to every connected page over a WebSocket on port 81 (and on USB serial):
//
// jx,jy,sw,a,b
//
// jx/jy joystick, -1.000 .. 1.000, centred and dead-zoned on the board
// sw joystick click (1 = pressed) a, b push buttons (1 = pressed)
//
// The page can send "c" to re-centre the joystick.
//
// Wiring - everything runs from 3V3. The joystick module's supply pin is labelled +5V,
// but it MUST go to 3V3: at 5 V its outputs would exceed what the ADC pins tolerate.
// Joystick VRx GPIO 1, VRy GPIO 2 (ADC1, works with WiFi on), SW GPIO 7, +5V -> 3V3, GND -> G
// Button A GPIO 4 <-> G Button B GPIO 6 <-> G
#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <WebSocketsServer.h>
#include <esp_heap_caps.h>
#include "web_assets.h"
#if __has_include("secrets.h")
#include "secrets.h"
#else
#define HOME_WIFI_SSID ""
#define HOME_WIFI_PASSWORD ""
#endif
#define PIN_JOY_X 1
#define PIN_JOY_Y 2
#define PIN_JOY_SW 7
#define PIN_BTN_A 4
#define PIN_BTN_B 6
static const char *HOSTNAME = "outlaws"; // -> http://outlaws.local
static const char *AP_SSID = "Outlaws";
static const char *AP_PASS = "schematik"; // >= 8 chars, or nullptr for an open network
static const uint32_t STREAM_US = 1000000 / 60;
static const float DEADZONE = 0.08f;
WebServer http(80);
WebSocketsServer ws(81);
int centreX = 2048, centreY = 2048;
float joyX = 0, joyY = 0;
uint32_t loops = 0, loopRate = 0, sent = 0, sendRate = 0;
// Debounced active-low input.
struct Button {
uint8_t pin; bool state = false; bool raw = false; uint32_t since = 0;
explicit Button(uint8_t p) : pin(p) {}
void begin() { pinMode(pin, INPUT_PULLUP); }
bool read() {
bool now = digitalRead(pin) == LOW;
if (now != raw) { raw = now; since = millis(); }
else if (now != state && millis() - since >= 8) state = now;
return state;
}
};
Button btnA(PIN_BTN_A), btnB(PIN_BTN_B), btnSw(PIN_JOY_SW);
int readAxis(uint8_t pin) {
int sum = 0;
for (int i = 0; i < 4; i++) sum += analogRead(pin);
return sum / 4;
}
void centreJoystick() {
long sx = 0, sy = 0;
for (int i = 0; i < 32; i++) { sx += readAxis(PIN_JOY_X); sy += readAxis(PIN_JOY_Y); delay(2); }
centreX = sx / 32; centreY = sy / 32;
// A stick held over (or an unplugged, floating pin) would give a useless centre.
if (centreX < 1200 || centreX > 2900) centreX = 2048;
if (centreY < 1200 || centreY > 2900) centreY = 2048;
Serial.printf("# joystick centre %d,%d\n", centreX, centreY);
}
// Raw ADC -> -1..1 around the measured centre, with a dead zone and full travel reached
// a little before the mechanical end stop.
float axis(int raw, int centre) {
float span = (raw >= centre ? 4095 - centre : centre) * 0.90f;
float v = (raw - centre) / (span > 1 ? span : 1);
if (v > 1) v = 1; if (v < -1) v = -1;
float mag = fabsf(v);
if (mag < DEADZONE) return 0;
return (v > 0 ? 1 : -1) * (mag - DEADZONE) / (1 - DEADZONE);
}
void calibrate() {
centreJoystick();
Serial.println("# READY");
}
// ---- the game's files ----------------------------------------------------------------------
// Built into the firmware by web/scripts/embed-firmware.mjs, because Schematik flashes firmware
// only. Each file is one or more parts in flash. At boot every file is joined into one block in
// PSRAM (the whole game is about 0.25 MB), which serves faster than reading flash part by part;
// if PSRAM is short, a file goes out straight from flash instead.
struct Entry { const WebAsset *asset; uint8_t *data; };
static Entry files[WEB_ASSET_MAX];
static int fileCount = 0;
static uint32_t webBytes = 0, cachedBytes = 0;
static void loadFiles() {
for (int i = 0; i < WEB_ASSET_COUNT && i < WEB_ASSET_MAX; i++) {
const WebAsset *a = &WEB_ASSETS[i];
uint8_t *data = (uint8_t *)heap_caps_malloc(a->size, MALLOC_CAP_SPIRAM);
if (data) {
uint32_t at = 0;
for (int k = 0; k < a->partCount; k++) { memcpy(data + at, a->parts[k].data, a->parts[k].size); at += a->parts[k].size; }
cachedBytes += a->size;
}
files[fileCount++] = {a, data};
webBytes += a->size;
}
Serial.printf("# game: %d files, %u KB (%u KB in PSRAM)\n", fileCount, (unsigned)(webBytes / 1024), (unsigned)(cachedBytes / 1024));
}
static const Entry *entry(const String &path) {
for (int i = 0; i < fileCount; i++) if (path == files[i].asset->path) return &files[i];
return nullptr;
}
static const char *mime(const String &path) {
if (path.endsWith(".html")) return "text/html";
if (path.endsWith(".js")) return "text/javascript";
if (path.endsWith(".css")) return "text/css";
if (path.endsWith(".svg")) return "image/svg+xml";
if (path.endsWith(".woff2")) return "font/woff2";
if (path.endsWith(".woff")) return "font/woff";
if (path.endsWith(".png")) return "image/png";
if (path.endsWith(".json")) return "application/json";
return "application/octet-stream";
}
static void sendBody(const uint8_t *data, size_t size) {
WiFiClient client = http.client();
while (size && client.connected()) {
size_t sent = client.write(data, size < 2872 ? size : 2872);
if (!sent) break;
data += sent; size -= sent;
}
}
// Serves `path` or its gzip twin (every game file is stored gzipped).
static bool sendFile(String path) {
if (path.endsWith("/")) path += "index.html";
const Entry *e = entry(path + ".gz");
const bool gzip = e;
if (!e) e = entry(path);
if (!e) return false;
// Hashed assets never change; index.html must always be fresh.
http.sendHeader("Cache-Control", path.startsWith("/a/") ? "max-age=31536000, immutable" : "no-cache");
if (gzip) http.sendHeader("Content-Encoding", "gzip");
http.setContentLength(e->asset->size);
http.send(200, mime(path), "");
if (e->data) sendBody(e->data, e->asset->size);
else for (int k = 0; k < e->asset->partCount; k++) sendBody(e->asset->parts[k].data, e->asset->parts[k].size);
return true;
}
// Every GET that is not one of the routes in setup() is a game file, or goes home.
class GameFiles : public RequestHandler {
public:
#if ESP_ARDUINO_VERSION_MAJOR >= 3
// Schematik builds with Arduino-ESP32 core 3.x, where the handler API takes the server and const String &.
bool canHandle(WebServer &, HTTPMethod method, const String &) override { return method == HTTP_GET; }
bool handle(WebServer &server, HTTPMethod, const String &uri) override {
#else
bool canHandle(HTTPMethod method, String) override { return method == HTTP_GET; }
bool handle(WebServer &server, HTTPMethod, String uri) override {
#endif
if (!sendFile(uri)) { server.sendHeader("Location", "/"); server.send(302, "text/plain", ""); }
return true;
}
};
void onSocket(uint8_t client, WStype_t type, uint8_t *payload, size_t length) {
if (type == WStype_CONNECTED) {
Serial.printf("# page connected (client %u, %u total)\n", client, ws.connectedClients());
} else if (type == WStype_DISCONNECTED) {
Serial.printf("# page disconnected (client %u)\n", client);
} else if (type == WStype_TEXT && length && payload[0] == 'c') {
calibrate();
}
}
void setup() {
Serial.begin(115200);
btnA.begin(); btnB.begin(); btnSw.begin();
analogReadResolution(12);
analogSetPinAttenuation(PIN_JOY_X, ADC_11db);
analogSetPinAttenuation(PIN_JOY_Y, ADC_11db);
loadFiles();
bool joined = false;
if (strlen(HOME_WIFI_SSID)) {
WiFi.mode(WIFI_STA);
WiFi.setHostname(HOSTNAME);
#if ESP_ARDUINO_VERSION_MAJOR >= 3
WiFi.enableIPv6(); // core 3.x: IPv6 must be requested before connecting (renamed from enableIpV6)
#endif
WiFi.begin(HOME_WIFI_SSID, HOME_WIFI_PASSWORD);
Serial.printf("# joining WiFi \"%s\"", HOME_WIFI_SSID);
for (uint32_t t0 = millis(); millis() - t0 < 15000 && WiFi.status() != WL_CONNECTED; delay(250)) Serial.print('.');
Serial.println();
joined = WiFi.status() == WL_CONNECTED;
}
if (joined) {
// With an IPv6 address, mDNS can also answer AAAA queries; without one, Chrome waits
// ~5 s for an AAAA answer before using IPv4. Must be enabled after the link is up.
#if ESP_ARDUINO_VERSION_MAJOR < 3
WiFi.enableIpV6();
#endif
delay(1500);
Serial.printf("# WiFi joined: open http://%s.local or http://%s\n", HOSTNAME, WiFi.localIP().toString().c_str());
} else {
WiFi.disconnect(true);
WiFi.mode(WIFI_AP);
WiFi.softAP(AP_SSID, AP_PASS, 6, 0, 4);
Serial.printf("# WiFi AP \"%s\" (password \"%s\") at http://%s\n", AP_SSID, AP_PASS ? AP_PASS : "", WiFi.softAPIP().toString().c_str());
}
WiFi.setSleep(false); // lowest WebSocket latency
if (MDNS.begin(HOSTNAME)) { MDNS.addService("http", "tcp", 80); MDNS.addService("ws", "tcp", 81); }
// The page opens its controller WebSocket by IP, skipping a slow .local lookup.
http.on("/host", HTTP_GET, [] {
http.sendHeader("Cache-Control", "no-store");
http.sendHeader("Access-Control-Allow-Origin", "*");
http.send(200, "text/plain", (WiFi.getMode() & WIFI_MODE_STA) && WiFi.status() == WL_CONNECTED ? WiFi.localIP().toString() : WiFi.softAPIP().toString());
});
// Live resource usage and raw inputs, for curiosity and wiring checks.
http.on("/stats", HTTP_GET, [] {
char json[560];
snprintf(json, sizeof json,
"{\"heap_free\":%u,\"heap_total\":%u,\"heap_min\":%u,\"psram_free\":%u,\"psram_total\":%u,"
"\"web_files\":%d,\"web_bytes\":%u,\"sketch\":%u,\"sketch_space\":%u,\"cpu_mhz\":%u,"
"\"loop_hz\":%u,\"ws_clients\":%u,\"ws_msgs_per_s\":%u,\"rssi\":%d,\"uptime_s\":%u,"
"\"joy_raw\":[%d,%d],\"joy_centre\":[%d,%d],\"joy\":[%.3f,%.3f],\"sw\":%d,\"a\":%d,\"b\":%d}",
ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getMinFreeHeap(), ESP.getFreePsram(), ESP.getPsramSize(),
fileCount, (unsigned)webBytes, ESP.getSketchSize(), ESP.getFreeSketchSpace() + ESP.getSketchSize(),
ESP.getCpuFreqMHz(), loopRate, ws.connectedClients(), sendRate, WiFi.RSSI(), (unsigned)(millis() / 1000),
readAxis(PIN_JOY_X), readAxis(PIN_JOY_Y), centreX, centreY, joyX, joyY,
btnSw.state ? 1 : 0, btnA.state ? 1 : 0, btnB.state ? 1 : 0);
http.send(200, "application/json", json);
});
http.addHandler(new GameFiles()); // after the routes above, so they win
http.onNotFound([] { http.sendHeader("Location", "/"); http.send(302, "text/plain", ""); });
http.begin();
ws.begin();
ws.onEvent(onSocket);
calibrate();
}
void loop() {
static uint32_t windowStart = millis();
if (millis() - windowStart >= 1000) {
loopRate = loops; sendRate = sent;
loops = sent = 0; windowStart = millis();
}
loops++;
http.handleClient();
ws.loop();
while (Serial.available()) if (Serial.read() == 'c') calibrate();
// Joystick at ~500 Hz with a light low-pass; buttons are debounced on every pass.
static uint32_t lastJoy = 0;
if (micros() - lastJoy >= 2000) {
lastJoy = micros();
joyX += 0.35f * (axis(readAxis(PIN_JOY_X), centreX) - joyX);
joyY += 0.35f * (axis(readAxis(PIN_JOY_Y), centreY) - joyY);
}
bool a = btnA.read(), b = btnB.read(), sw = btnSw.read();
static uint32_t lastSend = 0;
if (micros() - lastSend >= STREAM_US) {
lastSend = micros();
char line[48];
snprintf(line, sizeof line, "%.3f,%.3f,%d,%d,%d",
fabsf(joyX) < 0.004f ? 0.0f : joyX, fabsf(joyY) < 0.004f ? 0.0f : joyY,
sw ? 1 : 0, a ? 1 : 0, b ? 1 : 0);
if (ws.connectedClients()) { ws.broadcastTXT(line); sent++; }
static uint8_t serialDiv = 0;
if (++serialDiv >= 6) { serialDiv = 0; Serial.println(line); } // 10 Hz on USB for wiring checks
}
delay(1);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




