Simple code for stepper code -> jittery movement #16727
Replies: 3 comments 1 reply
-
Did you check the implementations here? The whole code is not shown (e.g. what is settting now?) In your loop the python infrastructure such as garbage collection likely is affwecting the timing of the pulses giving jitter and noise, whereas the PWM is much more consistent on pulses. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link. I didn't know about it. I did found AccelStepper (which is mentioned in the link); I had the intention to give it a try. I'll try some of the libs there. Nevertheless, I'm curious what I'm doing wrong in my code. I looked at a lot of libs for Arduino. Besides the fancy acceleration & co mechanism, I didn't spot any other "tricks". |
Beta Was this translation helpful? Give feedback.
-
Thanks guys! 1/ As a curiosity, I adjusted the code to work w/ microseconds instead of milliseconds. The jitter reduced, but it was still there. 2/ My attempt to keep the pin ON during an amount of time (i.e. to simulate a duty cycle of the PWM) seems to be in vain, and even hurting. I saw that people do: 3/ I switched to using a timer. And the following piece of code works like a charm: pin = Pin(16, Pin.OUT)
timer = Timer(-1)
timer.init(freq=freq,callback=_timer_callback)
def _timer_callback(t):
global pin
pin.on()
pin.off() It's funny 🙂. I develop computers as day job, and not microcontrollers. In a previous microcontroller home project (w/ ESP8266), my reflex was to use timers + callback and avoid the In this case it seems to be the opposite: timers 👍, loop() 👎. 4/ I tested the first lib = micropython-stepper in the list as recommended in the previous post. It works well; has a good API; is async. I think this is what I'll use for my project. 5/ I'm amazed how sensible the stepper movement is. I mean, when the framework of my M5Stack core does some house keeping tasks (e.g. bothering me w/ this kind of error message |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have an M5Stack Core (w/ ESP32) a board w/ stepper motor drivers. Their corresponding library (src) works, but unfortunately it doesn't allow precise positioning. It allows me only setting the speed/pulse frequency (in Hz). This freq is fed into a
PWM
that controls the pin.I tried to write a small piece of code that removes the
PWM
and commands the pulses in theloop()
function:This works, but I find that the move/sound is quite jittery/unhealthy (compared w/ their lib). I made UI buttons to adjust the
freq
andpercentageOn
. The "sound" of the motor does change, but still it is not smooth.Any hints about what I'm doing wrong?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions