AccelStepper
AccelStepper copied to clipboard
Entering deep sleep on an esp32 re-enables outputs
I have a project running on an esp32 where I only need to move a motor every few minutes, and I'm using deep sleep to reduce the power consumption. However, the motor is still powered (which probably uses more power than the esp32 itself), so I tried to call stepper.disableOutputs()
, but it turns out that somehow the output pins are re-enabled when the esp32 enters deep sleep.
Here is some code to reproduce the problem:
#include <AccelStepper.h>
#define IN1 5
#define IN2 18
#define IN3 19
#define IN4 21
// Create an instance of AccelStepper
AccelStepper stepper(AccelStepper::HALF4WIRE, IN1, IN3, IN2, IN4);
void setup() {
// Initialize the serial port
Serial.begin(115200);
stepper.moveTo(123);
stepper.runToPosition();
stepper.disableOutputs();
sleep(3); // Wait for three seconds to have time to observe the outputs.
// Outputs are now all low
Serial.println("Entering deep sleep");
esp_deep_sleep(10000000);
// Some outputs are enabled again, reflecting the last motor position before disabling outputs.
}
I'm not sure this is relevant, but this project is using a unipolar 28BYJ-48 stepper motor.
Any idea what could be causing this issue, and how it could be possible to disable outputs while the esp is in deep sleep?