Slot Machine PCB Design Request
Execution stopped by user.
1:53:02
WiFi, HTTPClientTable
| Function | GPIO/Pin | Connected To | Direction | Notes |
|---|---|---|---|---|
| Money In pulse | GPIO34 | MONEY_IN / optocoupler output | Input | Input-only ESP32 pin, counts incoming money pulses |
| Money Out pulse | GPIO35 | MONEY_OUT / optocoupler output | Input | Input-only ESP32 pin, counts payout pulses |
| BOOT button | GPIO0 | BOOT net / S1 | Input | Held low during reset for ROM bootloader |
| RESET button | EN | RESET_N / S2 | Input | Active-low module reset |
| 3.3 V supply | 3V3 | 3V3 rail | Power | Module logic supply |
| 5 V input | 5V | SYS_5V rail | Power | Devkit input pin fed from onboard power tree |
platformio.ini with this content:Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 upload_speed = 921600 lib_deps =
src/main.cpp with this content:Cpp
#include <Arduino.h> #include <WiFi.h> #include <HTTPClient.h> static constexpr int MONEY_IN_PIN = 34; static constexpr int MONEY_OUT_PIN = 35; static constexpr int BOOT_PIN = 0; static constexpr int STATUS_LED_PIN = 2; static const char* WIFI_SSID = "YOUR_WIFI_SSID"; static const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD"; static const char* SERVER_URL = "http://YOUR_SERVER/api/slot-events"; volatile uint32_t moneyInPulses = 0; volatile uint32_t moneyOutPulses = 0; volatile uint32_t lastMoneyInUs = 0; volatile uint32_t lastMoneyOutUs = 0; uint32_t lastPublishMs = 0; uint32_t lastWifiRetryMs = 0; void IRAM_ATTR onMoneyInPulse() { const uint32_t now = micros(); if (now - lastMoneyInUs > 2000) { moneyInPulses++; lastMoneyInUs = now; } } void IRAM_ATTR onMoneyOutPulse() { const uint32_t now = micros(); if (now - lastMoneyOutUs > 2000) { moneyOutPulses++; lastMoneyOutUs = now; } } void connectWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting to WiFi"); for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; ++i) { delay(250); Serial.print('.'); digitalWrite(STATUS_LED_PIN, !digitalRead(STATUS_LED_PIN)); } Serial.println(); if (WiFi.status() == WL_CONNECTED) { Serial.print("Connected, IP = "); Serial.println(WiFi.localIP()); digitalWrite(STATUS_LED_PIN, HIGH); } else { Serial.println("WiFi not connected, continuing offline"); digitalWrite(STATUS_LED_PIN, LOW); } } void publishCounts(uint32_t inCount, uint32_t outCount) { if (WiFi.status() != WL_CONNECTED) { return; } HTTPClient http; http.begin(SERVER_URL); http.addHeader("Content-Type", "application/json"); const String payload = String("{\"money_in\":") + inCount + String(",\"money_out\":") + outCount + String("}"); const int httpCode = http.POST(payload); Serial.print("POST result: "); Serial.println(httpCode); if (httpCode > 0) { Serial.println(http.getString()); } http.end(); } void setup() { pinMode(STATUS_LED_PIN, OUTPUT); digitalWrite(STATUS_LED_PIN, LOW); Serial.begin(115200); delay(200); Serial.println("Slot telemetry firmware starting"); pinMode(MONEY_IN_PIN, INPUT); pinMode(MONEY_OUT_PIN, INPUT); pinMode(BOOT_PIN, INPUT); attachInterrupt(digitalPinToInterrupt(MONEY_IN_PIN), onMoneyInPulse, FALLING); attachInterrupt(digitalPinToInterrupt(MONEY_OUT_PIN), onMoneyOutPulse, FALLING); connectWiFi(); } void loop() { const uint32_t nowMs = millis(); if (WiFi.status() != WL_CONNECTED && (nowMs - lastWifiRetryMs) > 10000) { lastWifiRetryMs = nowMs; connectWiFi(); } if ((nowMs - lastPublishMs) > 1000) { lastPublishMs = nowMs; noInterrupts(); const uint32_t inSnapshot = moneyInPulses; const uint32_t outSnapshot = moneyOutPulses; interrupts(); Serial.print("money_in="); Serial.print(inSnapshot); Serial.print(", money_out="); Serial.println(outSnapshot); publishCounts(inSnapshot, outSnapshot); } }
pio runpio run -t uploadpio device monitor -b 115200Platform & Toolchain
Pin Mapping
Dependencies & Project Setup
Complete Firmware Source
Build & Flash Instructions