Added ON-OFF button support #204

Open
opened 2026-04-05 17:52:13 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @gorbit99 on 3/23/2024

This PR adds in support for non-blocking momentary push button based ON-OFF functionality using the ESP's deep sleep feature.

The code was tested on an ESP8266 (specifically a D1 mini) and an ESP32-C3 (supermini esp32c3). For the latter, attaching a push button between GND and any of the RTC GPIOs (GPIO0-5), the code should work, but for the ESP8266, the following hardware needs to be added:

kép

GPIO13 can be set to any of the safe pins (4, 5, 12, 13, 14), however the other ones are already used by the default SlimeVR setup. I have tried to make the setup work with a MOSFET instead of a transistor, but didn't manage to yet.

The on-off behaviour can be activated by defining ON_OFF_BUTTON_PIN inside defines.h. For example:

#define ON_OFF_BUTTON_PIN D7

for a D1 mini.

Functionality

When the tracker is on, holding down the button for 1 second puts it to deep sleep (this is debounced). When it's in deep sleep, pressing the button once will wake it up, resetting it.

The tracker attempts to deinitialize the imus attached to it. Using an ESP32, it's also possible to define a pin that acts as an enable pin for the IMU (or other hardware), for possibly a voltage regulator or mosfet, that completely depowers the IMU. This functionality is not available on ESP8266, due to it lacking deep sleep pin hold functionality. To use this feature, one needs to define BUTTON_IMU_ENABLE_PIN and optionally BUTTON_IMU_ENABLE_ACTIVE_LEVEL (defaults to HIGH if not defined).

Additionally the tracker can be made to automatically shut off after a certain period of inactivity or if the battery voltage drops below a certain threshold. Both of these are meant to stop the tracker from depleting the battery to dangerous levels if accidentally left on. To use these features, define BUTTON_AUTO_SLEEP_TIME_SECONDS and BUTTON_BATTERY_VOLTAGE_THRESHOLD respectively.

While it varies, this setup should drop the power consumption to somewhere around 100-200uA, or even lower, if the IMU is completely depowered.

Battery consumption

Things that need checking:

  • Are the deinitialization routines for the IMUs correct
*Originally created by @gorbit99 on 3/23/2024* This PR adds in support for non-blocking momentary push button based ON-OFF functionality using the ESP's deep sleep feature. The code was tested on an ESP8266 (specifically a D1 mini) and an ESP32-C3 (supermini esp32c3). For the latter, attaching a push button between GND and any of the RTC GPIOs (GPIO0-5), the code should work, but for the ESP8266, the following hardware needs to be added: ![kép](https://github.com/SlimeVR/SlimeVR-Tracker-ESP/assets/5338164/1202d788-fe1d-4084-814f-1d11a1ee6cbc) GPIO13 can be set to any of the safe pins (4, 5, 12, 13, 14), however the other ones are already used by the default SlimeVR setup. ~~I have tried to make the setup work with a MOSFET instead of a transistor, but didn't manage to yet.~~ The on-off behaviour can be activated by defining ON_OFF_BUTTON_PIN inside defines.h. For example: ```cpp #define ON_OFF_BUTTON_PIN D7 ``` for a D1 mini. # Functionality When the tracker is on, holding down the button for 1 second puts it to deep sleep (this is debounced). When it's in deep sleep, pressing the button once will wake it up, resetting it. The tracker attempts to deinitialize the imus attached to it. Using an ESP32, it's also possible to define a pin that acts as an enable pin for the IMU (or other hardware), for possibly a voltage regulator or mosfet, that completely depowers the IMU. This functionality is not available on ESP8266, due to it lacking deep sleep pin hold functionality. To use this feature, one needs to define `BUTTON_IMU_ENABLE_PIN` and optionally `BUTTON_IMU_ENABLE_ACTIVE_LEVEL` (defaults to HIGH if not defined). Additionally the tracker can be made to automatically shut off after a certain period of inactivity or if the battery voltage drops below a certain threshold. Both of these are meant to stop the tracker from depleting the battery to dangerous levels if accidentally left on. To use these features, define `BUTTON_AUTO_SLEEP_TIME_SECONDS` and `BUTTON_BATTERY_VOLTAGE_THRESHOLD` respectively. While it varies, this setup should drop the power consumption to somewhere around 100-200uA, or even lower, if the IMU is completely depowered. # Battery consumption Things that need checking: - Are the deinitialization routines for the IMUs correct
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/SlimeVR-Tracker-ESP#204