Firmware for ESP32-based pendulum assist controllers that drive a stepper-based crank mechanism.
The project uses:
FastAccelStepperfor motion controlPlatformIOwith the Arduino framework- Ethernet plus a built-in Wi-Fi access point on
WT32-ETH01 - A built-in Wi-Fi access point on
YD-ESP32-23/ESP32-S3-N16R8 - Serial logging at
115200
The controller does the following:
- Homes the crankshaft on startup using a single
0°sensor - Watches a left-side pendulum sensor and estimates swing timing
- Detects when swing energy is too low or pulses disappear
- Schedules a full
360°assist move aligned to the predicted pendulum phase - Exposes live state, logs, and runtime tuning through a web interface
WT32-ETH01YD-ESP32-23withESP32-S3-N16R8
WT32-ETH01STEP:GPIO33DIR:GPIO5ENABLE:GPIO17
YD-ESP32-23STEP:GPIO4DIR:GPIO5ENABLE:GPIO6
ENABLE active low:true
WT32-ETH01- Pendulum sensor:
GPIO14 - Home sensor:
GPIO4
- Pendulum sensor:
YD-ESP32-23- Pendulum sensor:
GPIO7 - Home sensor:
GPIO15
- Pendulum sensor:
The current firmware is written for a digital hall sensor such as:
A3144
Important:
- The analog
49Eis not supported by this firmware as-is. - On classic ESP32, the practical analog pins available here are tied to
ADC2, which conflicts with Wi-Fi use. Since this project runs its own Wi-Fi AP, the digital hall path is the intended setup.
GPIO4andGPIO5are ESP32 strapping pins.- External hardware must not force invalid levels on these pins during reset, or the board may fail to boot.
- Sensor polarity is configurable in the web UI and stored in NVS.
- The
WT32-ETH01pin map is only valid on a plainWT32-ETH01carrier. Some custom carrier boards repurposeGPIO4/GPIO14. YD-ESP32-23does not provide the onboard Ethernet path used byWT32-ETH01.
On boot the firmware:
- Starts serial logging
- Loads persisted settings from NVS
- Initializes the stepper driver
- Starts networking for the selected board
- Starts the web server
- Homes the crankshaft using the home sensor
- Waits for repeated pendulum motion to lock onto timing
The firmware exposes the web UI over:
WT32-ETH01: Ethernet via DHCP and the board's own Wi-Fi APYD-ESP32-23: the board's own Wi-Fi AP only
- SSID:
PendulumAssist - Password:
pendulum123
The AP IP is normally:
192.168.4.1
The Ethernet hostname on WT32-ETH01 is:
pendulum-assist
The web UI provides:
- Live controller state
- Estimated swing period and left-side window time
- Motor position and move telemetry
- Command buttons for
Home,Force Assist, andStop Motion - Runtime configuration for assist direction, homing direction, sensor polarity, debounce, timing thresholds, and motion limits
- Recent debug log output
Configuration changes made in the web UI are persisted to NVS.
Install:
- PlatformIO Core or PlatformIO IDE
This project currently uses the environments defined in platformio.ini:
wt32-eth01wt32-eth01-sensor-testyd-esp32-23yd-esp32-23-sensor-test- framework:
arduino
From the project root:
pio run -e wt32-eth01To build the YD-ESP32-23 firmware:
pio run -e yd-esp32-23To build the dedicated manual sensor test firmware:
pio run -e wt32-eth01-sensor-test
pio run -e yd-esp32-23-sensor-testConnect the selected board over USB/serial and run:
pio run -e wt32-eth01 -t uploadFor YD-ESP32-23:
pio run -e yd-esp32-23 -t uploadTo upload the dedicated sensor test firmware:
pio run -e wt32-eth01-sensor-test -t upload
pio run -e yd-esp32-23-sensor-test -t uploadIf needed, specify the port explicitly:
pio run -e <environment> -t upload --upload-port <PORT>Open the serial monitor with:
pio device monitorThe project is configured for:
- baud rate:
115200
For the sensor test firmware, a typical session is:
pio run -e wt32-eth01-sensor-test -t upload
pio device monitor -b 115200For YD-ESP32-23, use the corresponding environment:
pio run -e yd-esp32-23-sensor-test -t upload
pio device monitor -b 115200- Verify the stepper driver wiring matches the configured pins.
- Verify the home sensor really marks mechanical
0°. - Confirm the pendulum sensor is a digital hall sensor and wired to the correct board pin.
- Power the board and open the serial monitor.
- Open the web UI over Ethernet or
http://192.168.4.1onWT32-ETH01, or overhttp://192.168.4.1onYD-ESP32-23. - Confirm homing succeeds.
- If homing moves the wrong way, change
Home Search Directionin the UI. - If the assist moves the wrong direction, change
Assist Directionin the UI. - Tune
Weak Window,Missed Pulse Slack, and the assist speed/acceleration limits conservatively on the bench first.
A dedicated firmware image is available for manual bench testing of the inputs.
Purpose:
- Wait for you to trigger the sensors by hand
- Print
ACTIVE/INACTIVEtransitions over serial - Count changes for each input
- Mark the mandatory inputs as passed once each has been seen in both states
Inputs observed:
WT32-ETH01- Pendulum sensor on
GPIO14 - Home sensor on
GPIO4 - Optional auxiliary input on
GPIO12
- Pendulum sensor on
YD-ESP32-23- Pendulum sensor on
GPIO7 - Home sensor on
GPIO15 - Optional auxiliary input on
GPIO12
- Pendulum sensor on
Behavior:
- Pendulum and home inputs are configured as
INPUT_PULLUPand treated as active-low GPIO12is monitored as an optional raw input- The test prints a periodic status summary and a final
SENSOR TEST PASSmessage when both mandatory inputs have toggled active and inactive
Use it like this:
pio run -e wt32-eth01-sensor-test -t upload
pio device monitor -b 115200Or for YD-ESP32-23:
pio run -e yd-esp32-23-sensor-test -t upload
pio device monitor -b 115200Then:
- Trigger and release the pendulum sensor by hand.
- Trigger and release the home sensor by hand.
- Optionally toggle
GPIO12.
- The home sensor provides one absolute reference at
0°. - A full assist move is one full revolution:
400steps per assist cycle by default. - The controller estimates swing timing from repeated pendulum sensor passes.
- A short left-side window or a missing expected pulse can trigger a scheduled assist.
These are adjustable in the web UI:
Assist DirectionHome Search DirectionPendulum Sensor PolarityHome Sensor PolarityAuto AssistDebounceLock CyclesPeriod Min / MaxWeak WindowMissed Pulse SlackSchedule GuardAssist AccelerationAssist Max SpeedHome Speed / Creep / Acceleration
- src/main.cpp: minimal entry point
- src/PendulumApplication.cpp: top-level app wiring
- src/PendulumController.cpp: motion, homing, pulse tracking, assist scheduling
- src/WebInterface.cpp: HTTP API, AP/Ethernet startup, route handling
- src/WebUiPage.cpp: embedded dashboard page
- src/Logger.cpp: in-memory log buffer and JSON export
- include/AppTypes.h: shared types and defaults
- The firmware compiles successfully, but it has not been hardware-validated in this repository.
- Analog hall support for
49Eis not implemented. - The control model assumes pendulum timing is stable enough to predict the assist phase from recent pulses.
- Missed steps are not actively detected; homing is the absolute reference.
YD-ESP32-23support is Wi-Fi AP only. The firmware does not provide Ethernet on that board.
- Bench-test homing with the mechanism disconnected or unloaded if possible.
- Verify the sensor polarity and direction settings first.
- Capture real pendulum timing logs and retune the assist thresholds from observed data.
- Add fault handling for motor stalls or repeated homing failures if this moves toward production use.