Stepper motor wont run smoothly on ESPhome? But does on arduino

Im using a Nema 17 stepper motor model: 17HS4401S. its running from a A4988 stepper driver.
When i run it from home assistant it doesnt move smoothly. it vibrates and sounds like its skipping steps. making the torque pretty bad too. At first i thought it was the wiring but i diconnected the step and dir pin, plugged it into a arduino and ran it and it was quite and smooth with no issues. is there something wrong with my code? or soemthing im msising when it coems to running steppers on ESPhome? its with a ESP8266 btw (D1 mini version)

captive_portal:
    

stepper:
  - platform: a4988
    id: my_stepper
    step_pin: D1
    sleep_pin: D7
    dir_pin: D0
    max_speed: 250 steps/s
    acceleration: 100
    deceleration: 100

number:
  - platform: template
    name: Stepper Control
    min_value: -100000
    max_value: 100000
    step: 1
    set_action:
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return x;'

It runs software pwm that is not suitable.

Change the step pin to gpio 2 and try again

1 Like

Gave that a try, says GPIO2 for d1mini is D4. tried it and it didnt change anyhting. also tried with other pins liek TX and Rx, same deal.

Had to check and it is not running pwm but just giving high pulses.

How do you power the motor, driver board and the esp? If you take 3.3V from esp to the driver it may be that esp 3.3v regulator is not powerfull enough.

How long is the wire for the step pin and did you change it for arduino test?

That may be it, cause the Arduino does out put logic levels of 5V where as ESP is 3.3V. As for wires they arent any more than 3 inches. they should be causing any issues.

If you don’t have separate 3.3v regulator you can power the driver board from arduino and have the esp connected to driver itself with signals.

Just connect the grounds to each other’s between arduino and esp.

Arduino 3.3 regulator is not good either so alternatively you can power the driver board with 5 voltage but have a diode in series so it will make a small voltage drop. Then the 3.3v signal from esp to ~4.3 v powered driver board will more reliably follow the high pulses.