diff --git a/esphome/components/a4988/a4988.cpp b/esphome/components/a4988/a4988.cpp index 99b677a9ab..4100563412 100644 --- a/esphome/components/a4988/a4988.cpp +++ b/esphome/components/a4988/a4988.cpp @@ -11,6 +11,7 @@ void A4988::setup() { if (this->sleep_pin_ != nullptr) { this->sleep_pin_->setup(); this->sleep_pin_->digital_write(false); + this->sleep_pin_state_ = false; } this->step_pin_->setup(); this->step_pin_->digital_write(false); @@ -27,7 +28,12 @@ void A4988::dump_config() { void A4988::loop() { bool at_target = this->has_reached_target(); if (this->sleep_pin_ != nullptr) { + bool sleep_rising_edge = !sleep_pin_state_ & !at_target; this->sleep_pin_->digital_write(!at_target); + this->sleep_pin_state_ = !at_target; + if (sleep_rising_edge) { + delayMicroseconds(1000); + } } if (at_target) { this->high_freq_.stop(); diff --git a/esphome/components/a4988/a4988.h b/esphome/components/a4988/a4988.h index 10fb5e0015..5be0f3ce69 100644 --- a/esphome/components/a4988/a4988.h +++ b/esphome/components/a4988/a4988.h @@ -21,6 +21,7 @@ class A4988 : public stepper::Stepper, public Component { GPIOPin *step_pin_; GPIOPin *dir_pin_; GPIOPin *sleep_pin_{nullptr}; + bool sleep_pin_state_; HighFrequencyLoopRequester high_freq_; };