Diseño de PCB para Control Remoto
esp32devTable
| Function | GPIO | Net | Direction | Notes |
|---|---|---|---|---|
| Joystick X | 32 | JOY_X | ADC input | ADC1, compatible con WiFi |
| Joystick Y | 33 | JOY_Y | ADC input | ADC1, compatible con WiFi |
| Battery sense | 35 | BAT_SENSE | ADC input | ADC1 input-only, divisor 100k/100k |
| USB sense | 34 | VBUS_SENSE | ADC input | ADC1 input-only, divisor 100k/100k |
| Joystick switch | 25 | JOY_SW | Digital input | Pulsador a GND, usar pull-up interno |
| Button 1 | 18 | BTN1 | Digital input | Pulsador a GND, usar pull-up interno |
| Button 2 | 19 | BTN2 | Digital input | Pulsador a GND, usar pull-up interno |
| Button 3 | 21 | BTN3 | Digital input | Pulsador a GND, usar pull-up interno |
| Button 4 | 22 | BTN4 | Digital input | Pulsador a GND, usar pull-up interno |
| Low battery LED | 23 | LOW_BAT_LED | Digital output | HIGH enciende LED rojo D4 |
Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 upload_speed = 921600
src/main.cppCpp
#include <Arduino.h> // Pin definitions from schematic #define JOY_X_PIN 32 #define JOY_Y_PIN 33 #define BAT_SENSE_PIN 35 #define VBUS_SENSE_PIN 34 #define JOY_SW_PIN 25 #define BTN1_PIN 18 #define BTN2_PIN 19 #define BTN3_PIN 21 #define BTN4_PIN 22 #define LOW_BAT_LED_PIN 23 // ADC scaling // Battery and VBUS dividers are 100k/100k, so input voltage = ADC node * 2. #define ADC_MAX_COUNTS 4095.0f #define ADC_REF_VOLTS 3.3f #define DIVIDER_RATIO 2.0f // Battery thresholds for 1S LiPo #define BAT_LOW_VOLTS 3.50f #define BAT_CRITICAL_VOLTS 3.30f static unsigned long lastReportMs = 0; static const uint32_t REPORT_INTERVAL_MS = 100; float readAdcVoltage(int pin) { int raw = analogRead(pin); return (raw / ADC_MAX_COUNTS) * ADC_REF_VOLTS; } float readBatteryVoltage() { return readAdcVoltage(BAT_SENSE_PIN) * DIVIDER_RATIO; } float readVbusVoltage() { return readAdcVoltage(VBUS_SENSE_PIN) * DIVIDER_RATIO; } int readButtonActiveLow(int pin) { return digitalRead(pin) == LOW ? 1 : 0; } void setup() { Serial.begin(115200); delay(300); Serial.println("ESP32 robot-car remote control starting"); analogReadResolution(12); analogSetAttenuation(ADC_11db); // allows readings up to about 3.3V on ADC pin pinMode(JOY_SW_PIN, INPUT_PULLUP); pinMode(BTN1_PIN, INPUT_PULLUP); pinMode(BTN2_PIN, INPUT_PULLUP); pinMode(BTN3_PIN, INPUT_PULLUP); pinMode(BTN4_PIN, INPUT_PULLUP); pinMode(LOW_BAT_LED_PIN, OUTPUT); digitalWrite(LOW_BAT_LED_PIN, LOW); } void loop() { unsigned long now = millis(); if (now - lastReportMs < REPORT_INTERVAL_MS) { return; } lastReportMs = now; int joyX = analogRead(JOY_X_PIN); int joyY = analogRead(JOY_Y_PIN); float batteryV = readBatteryVoltage(); float vbusV = readVbusVoltage(); bool lowBattery = batteryV < BAT_LOW_VOLTS; bool criticalBattery = batteryV < BAT_CRITICAL_VOLTS; bool usbConnected = vbusV > 4.0f; digitalWrite(LOW_BAT_LED_PIN, lowBattery ? HIGH : LOW); int joySw = readButtonActiveLow(JOY_SW_PIN); int b1 = readButtonActiveLow(BTN1_PIN); int b2 = readButtonActiveLow(BTN2_PIN); int b3 = readButtonActiveLow(BTN3_PIN); int b4 = readButtonActiveLow(BTN4_PIN); Serial.printf( "JOY_X=%d JOY_Y=%d JSW=%d B1=%d B2=%d B3=%d B4=%d VBAT=%.2fV VBUS=%.2fV USB=%d LOW=%d CRIT=%d\n", joyX, joyY, joySw, b1, b2, b3, b4, batteryV, vbusV, usbConnected ? 1 : 0, lowBattery ? 1 : 0, criticalBattery ? 1 : 0 ); }
Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
platformio.ini
Complete Firmware Source: `src/main.cpp`
Build & Flash Instructions
Next Firmware Step