0
\$\begingroup\$

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)

https://i.imgur.com/Ku2UgAxl.jpg

-- wiring layout

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

https://i.imgur.com/Fx7ErH1.jpg

-- code used

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

\$\endgroup\$
8
  • 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, 2018 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, 2018 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, 2018 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, 2018 at 22:14
  • 1
    \$\begingroup\$ Connect ENABLE pin to GND - on diagram it is floating so may result in random working. Additionaly connect SLEEP and RESET to Vdd. \$\endgroup\$
    – ufok
    Jul 15, 2021 at 8:52

2 Answers 2

1
\$\begingroup\$

Several possibilities:

You might try adding delays to get 50% duty cycle as suggested by jonk.
...
GPIO.output(21,true)
time.sleep(0.01)
GPIO.output(21,false)
time.sleep(0.01)
...

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.

\$\endgroup\$
2
  • 1
    \$\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\$ Jul 15, 2018 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, 2018 at 22:59
1
\$\begingroup\$

This is echoing several observations / suggestions from others as well as having done stepper control using A4988's more than once my laundry list (in order) would be;

  • Connect the floating pins on the driver (read the datasheet)
  • Check your grounding, check that your two grounds are properly joined and not fighting each other / torturing the chip / trying to float away from each other.
  • Look at decoupling / smoothing capacitors and ferrites on the logic side of things, stepper drivers are electrically very noisy especially when microstepping.
  • Check the A4988 isn't overheating, they can manage 2A absolute maximum on a well-designed PCB with good cooling, but mounted on a standard small StepStick style board they have almost zero hope of avoiding thermal shutdown, even with the popular little heatsinks people stick on them.
  • Don't use non-realtime / userspace code to drive a timing-critical device like a stepper, it will bite you eventually even if it "mostly works".
  • If you don't understand why realtime control is important for controlling physical devices like motors, do some learning on the subject.
  • Adding a microcontroller between the Pi and the driver, with accurate realtime code / using hardware timers to generate accurately timed waveforms with sensible duty cycles and acceleration/deceleration is a nicer way of achieving what you need. There's plenty of open source examples of this out there on 3D printers, CNC mills/routers etc. etc. etc.
  • The suggestions about more even timings in your code are good, even if they didn't fix your underlying problem you should understand why they are good.
  • If you have access to an oscilloscope, probe around for noisy lines and poorly shaped waveforms.
  • If you don't have access to an oscilloscope, get it.
\$\endgroup\$

Your Answer

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

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