PCB Assembly Challenges


flux

Prepared the JLCPCB PCB planning handoff package. Important: the current layout is intentionally unfinished and contains airwires, dangling/floating copper, and local overlaps; the handoff brief tells JLCPCB not to fabricate until they finish routing and achieve clean DRC.
Send JLCPCB the handoff brief first, then these files and the editable Flux project URL. Ask them to return clean final Gerbers, BOM/CPL, and a DRC report after completing the U1/jumper area.
Complete handoff documentation
Export DRC violations
Audit JLC BOM
Document jumper mappings
Run final ERC

Firmware Starter — TMCC WiFi DCC 5A Module
Platform & Toolchain
  • MCU: ESP32-WROOM-32UE
  • Framework: Arduino for ESP32
  • Build system: PlatformIO
  • Purpose: WiThrottle/JMRI client scaffold plus DRV8873 DCC output control.
Pin Mapping

Table


FunctionESP32 GPIOSchematic netDirectionNotes
DCC waveformGPIO25DCC_SIGOutputDrives DRV8873 EN/IN1 and U2 inverter input. Use RMT peripheral for accurate DCC timing.
DCC invertedn/aDCC_SIGNOutput via U274LVC1G04 generates complement into DRV8873 PH/IN2.
H-bridge sleepGPIO26DRV_SLEEPOutputHardware pulldown keeps bridge asleep at boot; drive HIGH after init.
H-bridge faultGPIO27DRV_FAULTInput pullupDRV8873 nFAULT, active-low open drain with 10 kΩ pull-up.
Current senseGPIO36 / SENSOR_VPISENSEADC inputDRV8873 IPROPI1/2 summed through 820 Ω to GND. Approx V = I_highside_sum/1100*820.
UART0 RXGPIO3 / RXD0UART_RXD0InputExternal USB-UART TX connects here through J3.
UART0 TXGPIO1 / TXD0UART_TXD0OutputExternal USB-UART RX connects here through J3.
Boot strapGPIO0BOOT_IO0InputPull low during reset for UART download mode.
Enable/resetENENInput10 kΩ pull-up and 1 µF RC delay; J3 can reset module.
Dependencies & Project Setup

Ini


[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps =
    links2004/WebSockets@^2.6.1
Complete Firmware Source

Cpp


#include <Arduino.h>
#include <WiFi.h>
#include <WebSocketsClient.h>
#include "driver/rmt.h"

// Pin definitions from schematic
#define DCC_SIG_PIN       25
#define DRV_SLEEP_PIN     26
#define DRV_FAULT_PIN     27
#define ISENSE_ADC_PIN    36
#define BOOT_PIN           0

// WiFi / WiThrottle placeholders
const char* WIFI_SSID = "YOUR_SSID";
const char* WIFI_PASSWORD = "YOUR_PASSWORD";
const char* JMRI_HOST = "192.168.1.10";
const uint16_t JMRI_PORT = 12090;

WebSocketsClient ws;

// DRV8873 current sense: IPROPI ~= I_HS / 1100, R = 820 ohm.
constexpr float ADC_REF_V = 3.3f;
constexpr int ADC_MAX = 4095;
constexpr float IPROPI_R_OHMS = 820.0f;
constexpr float IPROPI_RATIO = 1100.0f;
constexpr float OVERCURRENT_A = 5.5f;

void bridgeSleep(bool asleep) {
  digitalWrite(DRV_SLEEP_PIN, asleep ? LOW : HIGH);
}

float readBridgeCurrentAmps() {
  int raw = analogRead(ISENSE_ADC_PIN);
  float volts = (raw * ADC_REF_V) / ADC_MAX;
  return (volts / IPROPI_R_OHMS) * IPROPI_RATIO;
}

void checkFaults() {
  bool fault = digitalRead(DRV_FAULT_PIN) == LOW;
  float currentA = readBridgeCurrentAmps();
  if (fault || currentA > OVERCURRENT_A) {
    bridgeSleep(true);
    Serial.printf("Bridge disabled: fault=%d current=%.2f A\n", fault, currentA);
  }
}

void initDccRmt() {
  rmt_config_t config = {};
  config.rmt_mode = RMT_MODE_TX;
  config.channel = RMT_CHANNEL_0;
  config.gpio_num = (gpio_num_t)DCC_SIG_PIN;
  config.clk_div = 80; // 1 us ticks from 80 MHz APB
  config.mem_block_num = 1;
  config.tx_config.loop_en = false;
  config.tx_config.carrier_en = false;
  config.tx_config.idle_output_en = true;
  config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
  rmt_config(&config);
  rmt_driver_install(config.channel, 0, 0);
}

void sendDccPreambleDemo() {
  // Demo only: produces several DCC '1' bits, each half-bit ~58 us.
  rmt_item32_t items[16];
  for (int i = 0; i < 16; i++) {
    items[i].level0 = 1;
    items[i].duration0 = 58;
    items[i].level1 = 0;
    items[i].duration1 = 58;
  }
  rmt_write_items(RMT_CHANNEL_0, items, 16, true);
}

void wsEvent(WStype_t type, uint8_t* payload, size_t length) {
  switch (type) {
    case WStype_CONNECTED:
      Serial.println("Connected to JMRI/WebSocket placeholder");
      break;
    case WStype_TEXT:
      Serial.printf("JMRI message: %.*s\n", (int)length, payload);
      // TODO: parse WiThrottle protocol and convert speed/function packets to DCC packets.
      break;
    case WStype_DISCONNECTED:
      Serial.println("JMRI disconnected");
      break;
    default:
      break;
  }
}

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting WiFi");
  for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; i++) {
    delay(250);
    Serial.print('.');
  }
  Serial.println();
  if (WiFi.status() == WL_CONNECTED) {
    Serial.printf("WiFi connected: %s\n", WiFi.localIP().toString().c_str());
  } else {
    Serial.println("WiFi not connected; DCC demo still available over serial.");
  }
}

void setup() {
  Serial.begin(115200);
  delay(200);
  Serial.println("TMCC WiFi DCC 5A module firmware starting");

  pinMode(DRV_SLEEP_PIN, OUTPUT);
  bridgeSleep(true); // keep H-bridge off during setup
  pinMode(DRV_FAULT_PIN, INPUT_PULLUP);
  pinMode(DCC_SIG_PIN, OUTPUT);
  digitalWrite(DCC_SIG_PIN, LOW);

  analogReadResolution(12);
  analogSetPinAttenuation(ISENSE_ADC_PIN, ADC_11db);

  initDccRmt();
  initWiFi();

  ws.begin(JMRI_HOST, JMRI_PORT, "/");
  ws.onEvent(wsEvent);
  ws.setReconnectInterval(5000);

  bridgeSleep(false); // enable DRV8873 after GPIO/RMT are stable
}

void loop() {
  ws.loop();
  checkFaults();

  static uint32_t lastDemo = 0;
  if (millis() - lastDemo > 1000) {
    lastDemo = millis();
    sendDccPreambleDemo();
    Serial.printf("Current estimate: %.2f A\n", readBridgeCurrentAmps());
  }
}
Build & Flash Instructions
  1. Install PlatformIO.
  2. Create a project with the platformio.ini above and place the source in src/main.cpp.
  3. Connect a 3.3 V USB-UART adapter to J3: GND, TX->RXD0, RX->TXD0, EN, IO0.
  4. To enter bootloader: hold IO0 low, pulse EN low, then release EN and IO0.
  5. Build: pio run
  6. Flash: pio run -t upload
  7. Monitor: pio device monitor
Open Firmware Items
  • Replace the demo DCC preamble with a complete NMRA DCC packet generator.
  • Implement actual WiThrottle protocol parsing for JMRI.
  • Calibrate ADC current threshold on real hardware and validate DRV8873 thermal behavior.
  • Platform & Toolchain

  • Pin Mapping

  • Dependencies & Project Setup

  • Complete Firmware Source

  • Build & Flash Instructions

  • Open Firmware Items