Raspberry Pi - Stepper Motor Control & Breakout Board
Monday, December 31, 2012 at 3:20PM
Robert Savage in Embedded Computing, Java, Pi4J, Raspberry Pi, Raspberry Pi, java, motor, pi, pi4j, raspberry, raspi, stepper


Many of the previous Raspberry Pi projects I had been working on were based on fairly simple GPIO logic to turn things on and off.  Today I wanted a little more of a challenge so I started working to control a stepper motor from my Raspberry Pi using Java.  Fortunately I had previously obtained one of John Jay's Stepper Motor Breakout Board kits which includes all the necessary components (including the stepper motor) to get started.  

The kit includes:
  • 1 @ printed circuit board
  • 1 @ ULN2803 8 Channel Darlington Driver IC (Adafruit)
  • 1 @ 18 pin DIP socket (Amazon)
  • 8 @ green LEDs
  • 1 @ Jumper and Jumper header
  • 1 @ resistor array/network
  • 1 @ capacitor
  • 1 @ 26 pin PCB mount female header (not pictured)
  • 1 @ peel-and-stick on rubber bumper  (not pictured) 
  • 1 @ 28BYJ-48 5 VDC stepper motor (Amazon | Adafruit)
This kit is very easy to assemble and very reasonably priced.  
It is available now on eBay. << Click here to see John Jay's eBay listings >> 


Please visit John's website for further instructions and photos on assembly:
<< http://mypishop.com/Stepper.html >>

Shopping List


The stepper motor is controlled by pulsing the GPIO pins from LOW to HIGH states in a sequence that causes the motor to spin.  Each time a GPIO pin state is HIGH an electromagnet is engaged inside the stepper motor to cause a rotational force on the center rotor. With the proper sequence and timing you achieve motor rotation. 

Here is a fantastic article with photos and illustrations to help learn more about stepper motors and stepping techniquest:


Below are photos of the assembled board and attached stepper motor.

Stepper Motor Ports

This breakout board includes two ports for controlling two separate stepper motors.




You can purchase an additional stepper motor to use on the second port here:

28BYJ-48 5 VDC stepper motor (Amazon | Adafruit) 




GPIO Wiring Diagram

The two stepper motor controllers are mapped to GPIO pins on the Raspberry Pi's P1 header as depicted in the diagram below.  The GPIO numbering in the diagrams below is based on the WiringPi  / Pi4J numbering scheme.  See below for a mapping chart for other numbering schemes. 

GPIO Pin Cross-Reference Chart

Below is a cross reference chart to better help define the GPIO pin numbers used under the various pin numbering schemes.

JP1 Jumper Information

A jumper is provided on the board to supply 5 VDC to the stepper motors directly from the 5 VDC output from the Raspberry Pi.  If you would prefer to provide 5 VDC from an external power supply, please remove the jumper from JP1 and connect your power source to JP1 pins 2 and 3.  See the diagrams below.

Make sure that you place the jumper between pins 1 and 2.  


Never attach JP1 pins 1 and 3 together as this will cause a direct short on the 5 VDC power line from the Raspberry Pi.  This would likely render the Pi defective.   

Java Sample Program using Pi4J to Control Stepper Motor

Below is a sample Java program for controlling the stepper motor.  The Pi4J project now includes a new stepper motor interface and component implementation for GPIO based stepper motors.  This makes it really simple to control a stepper motor from Java.  (Note that the stepper motor implementation is available in 0.0.5 and later versions of Pi4J.)

The source for this example is provided with the Pi4J installation package and can also be found on Github:

Final Thoughts

This was my first time working with a stepper motor and having this kit certainly made it much easier to understand and get started.  For me the timing was the trickiest thing to get right.  Fortunately with a little trial and error I was able to get it working.  Here is a quick video demonstrating the final working project.

Happy New Year!


Article originally appeared on SHA (http://www.savagehomeautomation.com/).
See website for complete article licensing information.