ESP32 PCB Design Assistance


I need a PCB where the center is an ESP32. There's 2 motors connected via CAN (3.3v, tx, rx, ground, on 2.54mm spacing female), an external servo driver board, which needs ground, tx, rx (all female header pins). The battery connects to a 14.8 power bus on the PCB. From this 14.8 power bus, we connect to a small buck converter (3.3V, power and ground from PCB 14.8V) (external, not on PCB), which in then powers the ESP 32. The 14.8 power bus also powers another external, not on the pcb, buck converter which returns back 12.2 V to a new power bus, which just needs to receive up to 20amps via female. From this power bus, we power the servo driver as well ( via 2 male headers, gnd and 12.2v, on the PCB)

Firmware Starter — ESP32-WROOM-32E
Platform & Toolchain
  • MCU/module: ESP32-WROOM-32E-N4
  • Framework: Arduino for ESP32
  • Build system: PlatformIO
Pin Mapping

Table


FunctionESP32 GPIOSchematic netConnected toDirectionNotes
Motor 1 TXGPIO17MOTOR1_TXJ1 pin 2OutputUART TX from ESP32 to external motor board.
Motor 1 RXGPIO16MOTOR1_RXJ1 pin 3InputUART RX into ESP32 from external motor board.
Motor 2 TXGPIO25MOTOR2_TXJ2 pin 2OutputSecond logic serial channel; implemented in software serial in this starter.
Motor 2 RXGPIO26MOTOR2_RXJ2 pin 3InputSecond logic serial channel; implemented in software serial in this starter.
Servo TXGPIO33SERVO_TXJ3 pin 2OutputUART TX to external servo driver board.
Servo RXGPIO32SERVO_RXJ3 pin 3InputUART RX from external servo driver board.
ENENENR1/C3 reset delayInputHardware enable/reset circuit.
BootGPIO0BOOT0R2 pull-upInputPull low only for bootloader/download mode.
IO12 strapGPIO12ESP32_IO12_BOOT_PDR3 pull-downInputKept low at boot for 3.3 V flash operation.
platformio.ini

Ini


[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
    plerup/EspSoftwareSerial@^8.2.0
Complete Firmware Source

Cpp


#include <Arduino.h>
#include <WiFi.h>
#include <SoftwareSerial.h>

// Schematic pin mapping
#define MOTOR1_TX_PIN 17
#define MOTOR1_RX_PIN 16
#define MOTOR2_TX_PIN 25
#define MOTOR2_RX_PIN 26
#define SERVO_TX_PIN  33
#define SERVO_RX_PIN  32

#define DEBUG_BAUD 115200
#define MOTOR_UART_BAUD 115200
#define SERVO_UART_BAUD 115200

// Hardware UARTs on original ESP32
HardwareSerial Motor1Serial(2);  // UART2: RX=GPIO16, TX=GPIO17
HardwareSerial ServoSerial(1);   // UART1: RX=GPIO32, TX=GPIO33

// Extra software serial channel for Motor 2. For high baud/low jitter, move this to another hardware UART or add a UART expander.
SoftwareSerial Motor2Serial(MOTOR2_RX_PIN, MOTOR2_TX_PIN);

const char* WIFI_SSID = "YOUR_SSID";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  Serial.print("Connecting to WiFi");
  for (int i = 0; i < 20 && WiFi.status() != WL_CONNECTED; ++i) {
    delay(500);
    Serial.print('.');
  }

  if (WiFi.status() == WL_CONNECTED) {
    Serial.printf("\nWiFi connected, IP=%s\n", WiFi.localIP().toString().c_str());
  } else {
    Serial.println("\nWiFi not connected; continuing offline.");
  }
}

void sendLine(Stream& port, const char* line) {
  port.print(line);
  port.print('\n');
}

void bridgeIncoming(Stream& from, const char* label) {
  while (from.available()) {
    int c = from.read();
    Serial.printf("[%s] %c", label, (char)c);
  }
}

void setup() {
  Serial.begin(DEBUG_BAUD);
  delay(200);
  Serial.println("ESP32 Power Bus Controller firmware starting");

  Motor1Serial.begin(MOTOR_UART_BAUD, SERIAL_8N1, MOTOR1_RX_PIN, MOTOR1_TX_PIN);
  Motor2Serial.begin(MOTOR_UART_BAUD);
  ServoSerial.begin(SERVO_UART_BAUD, SERIAL_8N1, SERVO_RX_PIN, SERVO_TX_PIN);

  initWiFi();

  sendLine(Motor1Serial, "PING_MOTOR_1");
  sendLine(Motor2Serial, "PING_MOTOR_2");
  sendLine(ServoSerial, "PING_SERVO");
}

void loop() {
  static unsigned long lastPingMs = 0;
  unsigned long now = millis();

  bridgeIncoming(Motor1Serial, "M1");
  bridgeIncoming(Motor2Serial, "M2");
  bridgeIncoming(ServoSerial, "SERVO");

  if (now - lastPingMs >= 1000) {
    lastPingMs = now;
    sendLine(Motor1Serial, "STATUS?");
    sendLine(Motor2Serial, "STATUS?");
    sendLine(ServoSerial, "STATUS?");
  }

  if (WiFi.status() != WL_CONNECTED) {
    // Keep running local serial links; reconnect opportunistically.
    static unsigned long lastReconnectMs = 0;
    if (now - lastReconnectMs > 10000) {
      lastReconnectMs = now;
      initWiFi();
    }
  }
}
Build & Flash

Bash


pio run
pio run -t upload
pio device monitor
To enter bootloader mode manually: hold GPIO0/BOOT low during reset, then release after upload starts. The current schematic has a pull-up on GPIO0 but no pushbutton, so use an external jumper or add a BOOT switch if convenient.
  • Platform & Toolchain

  • Pin Mapping

  • platformio.ini

  • Complete Firmware Source

  • Build & Flash