| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 |
|---|
This project demonstrates ultra-low-power pulse counting using the ULP FSM coprocessor on ESP32-family chips. It counts pulses on a GPIO while the main CPU is running or in deep sleep, and saves results to NVS.
- ULP FSM pulse counting with debouncing
- Deep sleep and wakeup on pulse threshold
- NVS storage of pulse count
- Battery voltage monitoring
- Fast bootloader wakeup
- GPIO event simulation
- ESP32, ESP32-S2, or ESP32-S3 development board
- Input signal connected to GPIO0 (default; configurable)
- Button or pulse generator for GPIO0
main/pulse_cnt_main.c: Main application logicmain/battery.c: Battery monitoringmain/ulp/: ULP assembly source filespytest_ulp_fsm.py: Automated hardware tests
Project configuration is managed using ESP-IDF's menuconfig utility. You can set options such as ULP wakeup period, GPIO pin selection, battery thresholds, bootloader behavior, and network settings.
Wi-Fi SSID/password and MQTT broker details must also be configured via menuconfig under the relevant networking and MQTT sections. This ensures your device can connect to your network and publish pulse data.
To configure:
- Run:
idf.py menuconfig - Navigate through the menu to adjust:
- ULP wakeup period
- GPIO pin for pulse input
- Battery voltage threshold
- Bootloader options (e.g., skip validation in deep sleep)
- Save and exit. Your settings will be stored in
sdkconfig.
You can also edit sdkconfig.defaults for default values.
- Install ESP-IDF and set up your environment
- Build the project:
idf.py build - Flash to your device:
idf.py -p <PORT> flash
- Connect your board to your computer
- Open serial monitor:
idf.py -p <PORT> monitor - Press the button on GPIO0 to generate pulses
- Observe pulse counting, deep sleep, and wakeup events in the serial output
Not ULP wakeup, initializing ULP
Entering deep sleep
ULP wakeup, saving pulse count
Read pulse count from NVS: 384
Pulse count from ULP: 5
Wrote updated pulse count to NVS: 389
Entering deep sleep
... (repeats)
Automated hardware tests are provided in pytest_ulp_fsm.py using the pytest-embedded framework.
- Install dependencies:
pip install pytest pytest-embedded pytest-embedded-idf - Connect your device and ensure firmware is flashed
- Run:
pytest pytest_ulp_fsm.py
With default configuration (20ms ULP wakeup period), average current in deep sleep on ESP32 is ~16uA.
