I am attempting to get my stepper motor to rotate 90 degrees, stop for a second, and repeat these steps.

Please note I am a beginner, but I have taken physics courses so I do understand most basic electronics concepts such as voltage, amperage, series, parallel, resistance, etc...

So the way I am setting this up is with a raspberry pi connected connected to an a4988 Pololu stepper motor driver which outputs 2 amps at optimal cooling and 12v, with a bipolar stepper motor that is rated at 2/amps per phase and is receiving 12v. The motors are being powered by a 30 amp, 12v power supply.

Everything is wired according to the attached diagram, and has been tested many times. Many different scripts have been used, and currently we are using a Python script from the RPI that runs 50 steps (90 degrees), then waits one second. This code works and is correct, because sometimes it works. When running, the motor does heat up, but not hot to the touch. Additionally, when powered but not running code, it buzzes and clicks sometimes, not moving. Online sources said this was okay.

It seems to be very random when it works and when it does not work, for example when testing the current going through one of the coil wires using a multimeter wired in series, the motor works perfectly, but when the multimeter is not there, the motor freaks out, buzzes, and changes direction erratically, one theory of mine as to why this is is due to the added resistance, in which case putting a resistor in series may fix the problem, but doesn't seem to address the root of the issue.

Other actions taken: -Using an arduino uno instead of Pi, same issues -Running the code using different ways, different libraries etc. -switched to different motor, and driver. -re-wired everything multiple times -adjusting the voltage control screw on the driver. -provided adequate cooling to the PSU and driver (2 120mil computer fans)


-- wiring layout

https://i.imgur.com/undefined.jpeg -- picture of setup


-- code used

any help or suggestions would be greatly appreciated, too many hours have gone into this. LMK if any additional info is needed.

  • 1
    \$\begingroup\$ I've inlined two of the images for you. Can you upload your second one as jpg rather than jpeg and inline it yourself? Code should really be pasted in using the code tag so it can be copied and edited in answers. Yours is simple enough this time. \$\endgroup\$ – Transistor Jul 15 '18 at 21:07
  • 1
    \$\begingroup\$ Why don't you insert a delay in between your two GPIO output lines in the for loop? I don't know if your driver needs it, but perhaps a "closer to 50%" duty cycle might help? Have you tried that, yet? Or is there a good reason not to try it? \$\endgroup\$ – jonk Jul 15 '18 at 21:07
  • \$\begingroup\$ Agreed. You are turning 21 on and instantly turning it off. The stepper driver might not register the pulse. \$\endgroup\$ – Transistor Jul 15 '18 at 21:09
  • \$\begingroup\$ "random works/not_works" suggests a ground-loop problem....these all-in-one chips have a logic-ground common with stepper supply ground. Very large transient step-pulse currents can play havoc with logic-control inputs. And transients also can disturb floating inputs of a near-by microcontroller. \$\endgroup\$ – glen_geek Jul 15 '18 at 22:14
  • \$\begingroup\$ Sorry for the bad formatting, and as said elsewhere, delays between cycles and powers have been tried to the same effect. @glen_geek do you have any idea on how to go about fixing the issue you described? Thanks all. \$\endgroup\$ – Jake Chunn Jul 15 '18 at 23:01

Several possibilities:

You might try adding delays to get 50% duty cycle as suggested by jonk.

You might also try adding acceleration and deceleration ramps to your code and using an Arduino library that supports them (like AccelStepper).

Also, context switching on the Raspberry Pi will cause non-uniformity in the timing of the step pulse train which translates to asking the motor to accelerate and decelerate very quickly which may exceed the motor's torque capabilities. Stepper motor's torque generally drops with rotational speed but usually has a resonance band where torque drops to near zero at a certain speed range. Putting a flywheel on the shaft (or other load with a bit of angular inertia) can minimize the resonance effect.

  • \$\begingroup\$ Userspace bit banging is not a sound way to drive a stepper motor, at least not above discerete-step speeds. But it sounds like there's something else wrong even before that. \$\endgroup\$ – Chris Stratton Jul 15 '18 at 21:41
  • \$\begingroup\$ We have placed inertia on the shaft, it seemingly has no effect, and your recommended code is one of many variations which we have tried, any amounts of delays have no effect on the erratically. I think Chris is right. \$\endgroup\$ – Jake Chunn Jul 15 '18 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.