Skip to content

Firmware

Prerequisites

  • PlatformIO (CLI or VS Code extension)
  • USB cable for ESP32

Build and Flash

  1. Clone the repository

    Terminal window
    git clone https://git.supported.systems/rf/mcpositioner.git
    cd mcpositioner/firmware
  2. Build the firmware

    Terminal window
    pio run
  3. Flash to ESP32

    Terminal window
    pio run -t upload
  4. Monitor serial output (optional)

    Terminal window
    pio device monitor

Configuration

Edit include/config.h before building:

WiFi Settings

#define WIFI_SSID "your-network"
#define WIFI_PASSWORD "your-password"

Motor Parameters

// Steps per revolution (including microstepping)
#define THETA_STEPS_PER_REV 3200 // 200 * 16 microstepping
#define PHI_STEPS_PER_REV 3200
// Gear ratios (if using reduction gearing)
#define THETA_GEAR_RATIO 1.0
#define PHI_GEAR_RATIO 1.0
// Motor current (mA)
#define MOTOR_CURRENT_MA 800

TMC2209 Settings

// UART addresses
#define THETA_TMC_ADDR 0x00
#define PHI_TMC_ADDR 0x01
// StallGuard threshold (lower = more sensitive)
#define STALL_VALUE 50
// Homing speed (steps/sec)
#define HOMING_SPEED 500

Pin Assignments

// Theta axis
#define THETA_STEP_PIN 16
#define THETA_DIR_PIN 17
#define THETA_EN_PIN 4
// Phi axis
#define PHI_STEP_PIN 21
#define PHI_DIR_PIN 22
#define PHI_EN_PIN 23
// Shared UART
#define TMC_UART_TX 18
#define TMC_UART_RX 19

HTTP API

The firmware exposes these endpoints at http://positioner.local:

EndpointMethodDescription
/statusGETCurrent position and state
/movePOSTAbsolute move: {"theta_deg": 90, "phi_deg": 45}
/move/relativePOSTRelative move: {"d_theta": 5, "d_phi": 10}
/homePOSTHoming: {"axis": "both"}
/stopPOSTEmergency stop
/configGET/POSTMotion parameters

Dependencies

The firmware uses these PlatformIO libraries (auto-installed):

LibraryPurpose
AccelStepperSmooth acceleration profiles
TMCStepperTMC2209 UART configuration
ESPAsyncWebServerHTTP API
ArduinoJsonJSON parsing
ESPmDNSNetwork discovery

Troubleshooting

Can’t connect to WiFi

  • Check SSID and password in config.h
  • Verify ESP32 is within range
  • Check serial monitor for connection status

mDNS not working

  • Some networks block mDNS
  • Use IP address directly (shown in serial monitor on boot)
  • Set MCPOSITIONER_HOST environment variable

Motors don’t respond

  • Check UART wiring (TX/RX may be swapped)
  • Verify TMC2209 addresses match config
  • Check motor power supply

StallGuard unreliable

  • Adjust STALL_VALUE (lower = more sensitive)
  • Increase motor current
  • Decrease homing speed
  • Ensure mechanical stops are solid

OTA Updates

The firmware supports over-the-air updates:

Terminal window
pio run -t upload --upload-port positioner.local