0
\$\begingroup\$

So im currently trying to use a NEMA17 stepper motor with a A4988 driver. My objective is to control the speed and position of my motor according to sensor readings to position a contraption towards a light source. I found out that i can control it using servo controls using the arduino servo library. However, when using servo controls, positioning the motor with increments of 1 makes the motor rattle a lot. I tried using analogue write, but it seems the value that's written to the motor doesn't affect the speed. Most tutorials i see online involve turning on and off a pin in rapid succession 200 times to fully rotate the motor which is not really efficient in terms of code. Which method should i pick to control my motor?

\$\endgroup\$
4
  • \$\begingroup\$ Do averaging before sending correct value to eliminate the jitter. It takes 100 values to reduce by 10 (sqrt) if it is random noise, otherwise investigate source of noise like hum and use STP cable. You can probably use full steps for speed and fractional steps for improving accuracy if needed but slower. Watch out for stray light interference and focus with an aperture if possible, \$\endgroup\$
    – D.A.S.
    Commented Jun 2, 2021 at 17:39
  • \$\begingroup\$ not really efficient in terms of code ... why is it not efficient? ... please provide an example of inefficient code, if you can \$\endgroup\$
    – jsotola
    Commented Jun 2, 2021 at 18:32
  • \$\begingroup\$ Loops are pretty easy to code. What do you thing should be done differently? If you want to be doing something else while stepping, maybe write multi-threaded code. Also stepper drivers are sensitive to the level of the direction pin and the edge of the step pin. This is digital not analogue. \$\endgroup\$
    – IanJ
    Commented Jun 2, 2021 at 23:46
  • \$\begingroup\$ They usually use a loop to pulse the stepper pin for a certain amount of time to achieve the effect. I found using the servo library to be simpler than cycling digitalWrite(HIGH) digitalWrite(LOW) in a looping command because it uses 1 line of code instead of multiple lines \$\endgroup\$ Commented Jun 3, 2021 at 2:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.