Stepper motors and the Raspberry Pi

October 12, 2012 at 2:30 am 4 comments

In looking at projects to do with the Raspberry Pi, I’ve been digging into stepper motor control through the on-board GPIO. There seems to be quite a few options for this, everything from directly controlling the phases to the motor, to using a daughterboard that is purpose-built for motor control.

The advantage of the direct control mode is that its wicked cheap: a few transistors to that you can use to control the much larger current needed to drive the motor phases. There is a great Youtube video of a circuit doing this task and it seems to work, though it’s clearly a little on the rough side. It’s even controlled by a python script. 🙂

On the other side is a separate motor driver that is controlled over a I2C, USB or RS485 interface. The advantage is a feature-rich motion control solution that is (in most cases) a separate processor handling the motor functions. The Steprocker looks good for this, but the disadvantage is that the cost is non-trivial, and almost always several multiples of the cost of the Pi itself, especially if a bridge from GPIO to RS485 or I2C is needed.

So I’m looking for some middle ground that does not involve building a stack of cards to drive a 3-, 4- or 5-axis system, but also handles the very base function of driving the stepper current. So far, I think the simplest solution will be to connect a number of A4988 stepper drivers to the GPIO on the Pi, probably using a Pololu carrier board. This gives some micro-stepping control while reducing the number of GPIO pins needed to drive the motor. The boards are roughly $13 each… not bad at all.

Next step is to sort out which motors to use and the power supply to drive it. Once I have it worked out I’ll post the circuit diagram.


Entry filed under: Uncategorized.

Raspberry Pi WiFi and USB Keyboard issues on the Pi

4 Comments Add your own

  • 1. Daniel Amesberger  |  October 17, 2012 at 12:20 pm

    Nice! Just consider that the Raspberry Pi is not a realtime system. So if you are generating the direction/step signals of your A4988 with RPi I/Os and it does anything else than executing your stepping code, the motors will delay/lose steps and do not reach their final position. If you are doing syncronous multi-axis systems things get even more complex. I played a lot with the I/Os during API development for my RasPiComm (you linked to, thanx 😉 ) and exact timings are hard to do if you want to do anything else (calculate/send receive data via TCP/IP,…) on the RPi. The Steprocker is not cheap but considering the features it is really nice. You have Stall-Guards and power saving/optimization features and a dedicated MCU doing all the logic stuff, another chip generating the step/dir control with ramping and all the details (for up to 3 axis) and another chip creating the waveforms. So this is really quite a high-end system. And there are a load of other, cheaper solutions available, but I’m not aware of any with all these features at such a modest price. And you can connect two other motors via the step/direction outputs.
    For your design/cost considerations I would at least recommend a simple microcontroller between the RPi and the stepper drivers ($3 will do), connect the serial port of the Raspi to the MCU (PIC, Atmel, almost anything will do), and generate the step/direction inputs from there. This will enable you to do the ramping (soft start/stop of the motors) and simultanous axis movements under real-time conditions, and you can receive/buffer commands sent from your RPi.
    All the best for your project!

  • 2. ttongue2012  |  October 17, 2012 at 1:16 pm

    Thanks for the comments! I’m really looking forward to the RasPiComm being available, I think it’s going to be more in-line with my interests than the GertBoard, though it certainly has some interesting features as well.

    Your points are well taken with regard to the non-RT nature of the Pi. At work, I spend most of my time with AllMotion products for motion control, and they do a fine job for really rigorous motion control, but I have a real desire to work from the “bottom up” in my spare time to get a better fundamental feeling for all thats going on. So the progression you suggest (moving up to an independent MCU) is likely to be the next step after I try the Allegro based chips directly with the Pi and then pick the sand from my teeth. :). I feel like doing that first step will make my choices on the MCU side a bit more intelligent (at least, I hope so!).

    Thanks again!

  • 3. Eros Nicolau  |  February 12, 2013 at 12:20 am

    Hey, man, that’s exactly what I’m trying to achieve: to control multiple Polulu drivers from a Raspberry Pi B. Any luck / updates with that? 🙂

    • 4. ttongue2012  |  February 23, 2013 at 4:08 am

      So I’m slowly pecking away at this problem. I tried using the Pololu board with an Arduino and it worked PERFECTLY, so I think the issue is actually that the 3.3V line levels coming out of the Pi are simply not high enough to trigger the steps on the Pololu, despite the spec indicating this should be fine. Next I’m going to try a line level shifter to bring the Pi signals up to 5V… I’m betting thats going to work. More on this soon!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Flickr Photos

%d bloggers like this: