Home > BeagleBone > BeagleBone – Stepping Out

BeagleBone – Stepping Out

A stepper motor is an electro mechanical device which converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in discrete step increments when electrical pulses are applied to it in the proper sequence. The motors rotation has several direct relationships to these applied input pulses. The sequence of the applied pulses is directly related to the direction of motor shafts rotation. The speed of the motor shafts rotation is directly related to the frequency of the input pulses and the length of rotation is directly related to the number of input pulses applied.

That’s quite the explanation. Most anything that requires motion control will use a step motor. So how do we get a BeagleBone to work a step motor?  We need four things:

  1. Step Motor – The motor steps (rotates) when the power is applied to the motor’s windings.
  2. Driver – The driver receives a command, interprets it, and send the necessary power to the step motor to achieve a step.
  3. Controller- A device (microprocessor) capable of sending a command to the driver.
  4. User Interface (UI) – A physical or virtual device that provides a user with effective interaction and control of the step motor.
Stepper Motor Driver Board ULN2003 for Arduino/AVR/ARM

Stepper Motor Driver Board ULN2003 for Arduino/AVR/ARM

There are all sorts of variations when it comes to integrating these four pieces. For example you could run a UI on a BeagleBoard that communicates, using one of a number of methods (i.e. USB, Ethernet), with a dedicated controller. That controller is cabled to a driver which in turn is wired to a motor. All well and good but I wanted a simpler and cheaper example.

In this example the BeagleBone will provide the UI and controller. The initial UI will be a shell script. While not very interactive it’s demonstrates that everything works. I’ll get more sophisticated later. The BeagleBone’s GPIO interface will be used to send commands to the driver.

I picked up an inexpensive driver and step motor intended for use with an Arduino. The driver board accepts a four bit command from an controller and in turn applies the necessary power pulse to step the motor. At the heart of the driver is a ULN2003AN integrated circuit. The board can supply between 5V to 12V to the motor from an independent power supply. It also has a bank of LED’s that correspond to the input signals received from the controller. They provide a nice visual when stepping.

Some step motor details:

  • Model: 28KYJ-48
  • Voltage: 5VDC
  • Phase: 4
  • Step Angle: 5.625° (1/64)
  • Reduction ratio: 1/64
It takes 4096 steps to rotate the spindle 360°. It is impossible to see a single step. When testing it pays to have something distinct on the spindle to show it is turning.

Physically connecting BeagleBone to the driver board is straight forward. Pick a free GPIO pin on the expansion header and run a wire from it to one of the input pins on the driver board. The driver board requires power. I tried powering it from the 5V and ground pins on expansion header P9, and an independent 5V power supply. Each worked well. Having wired a GPIO pin to the driver board you can use Linux’s sysfs GPIO interface to use it. Set the GPIO pin high and the corresponding LED on the driver board will illuminate. Set it low and the LED turns off.

Completing the wiring and toggling the LED’s did take long. Here’s now I wired the BeagleBone to the driver.

BeagleBone Drive Board
Signal Nane Pin Pin
VDD_5V  P9.3 +
GND  P9.1
GPIO1_6 p8.3 IN1
GPIO0_27 p8.17 IN2
GPIO1_15 p8.15 IN3
GPIO1_13 p8.11 IN4

The motor steps when a specific combination of wires running to the motor are powered. This is just a pulse of power. Just enough to get the motor to step. This driver and motor use a very simple protocol. Applying a signal to an input pin causes power to be sent to the motor on a corresponding wire.

Stepper Motor Driver Board ULN2003 for Arduino/AVR/ARM

Stepper Motor Driver Board

MCU IO Code Wire Color
IN1  A Blue
IN2  B Pink
IN3  C Yellow
IN4  D Orange

The motor steps when specific combinations of its wires are powered and the same combination is used to signal the driver. Discovering the correct stepping commands took a lot of searching on the Internet. The vast majority of information describes Arduino examples that rely on underlying Arduino libraries. I finally found this link and within a few minutes my motor was stepping.

The following codes define the step commands.

8 Step : A – AB – B – BC – C – CD – D – DA
4 Step : AB – BC – CD – DA (Usual application)

Step Command IN4 IN3 IN2 IN1
A 01H 0 0 0 1
AB 03H 0 0 1 1
B 02H 0 0 1 0
BC 06H 0 1 1 0
C 04H 0 1 0 0
CD 0CH 1 1 0 0
D 08H 1 0 0 0
DA 09H 1 0 0 1

Here’s a shell script that will step my motor one full rotation.

#!/bin/sh

timeout=10000

in1=38 # GPIO1_6  (p8.3)
in2=27 # GPIO0_27 (p8.17)
in3=47 # GPIO1_15 (p8.15)
in4=45 # GPIO1_13 (p8.11)

AB() {
        echo high > /sys/class/gpio/gpio$in1/direction
        echo high > /sys/class/gpio/gpio$in2/direction
        echo low > /sys/class/gpio/gpio$in3/direction
        echo low > /sys/class/gpio/gpio$in4/direction
}
BC() {
        echo low > /sys/class/gpio/gpio$in1/direction
        echo high > /sys/class/gpio/gpio$in2/direction
        echo high > /sys/class/gpio/gpio$in3/direction
        echo low > /sys/class/gpio/gpio$in4/direction
}

CD() {
        echo low > /sys/class/gpio/gpio$in1/direction
        echo low > /sys/class/gpio/gpio$in2/direction
        echo high > /sys/class/gpio/gpio$in3/direction
        echo high > /sys/class/gpio/gpio$in4/direction
}

DA() {
        echo high > /sys/class/gpio/gpio$in1/direction
        echo low > /sys/class/gpio/gpio$in2/direction
        echo low > /sys/class/gpio/gpio$in3/direction
        echo high > /sys/class/gpio/gpio$in4/direction
}

off() {
        echo low > /sys/class/gpio/gpio$in1/direction
        echo low > /sys/class/gpio/gpio$in2/direction
        echo low > /sys/class/gpio/gpio$in3/direction
        echo low > /sys/class/gpio/gpio$in4/direction
}

test() {
        for input in $in1 $in2 $in3 $in4
        do
                echo high > /sys/class/gpio/gpio$input/direction
                sleep 1
                echo low > /sys/class/gpio/gpio$input/direction
        done
}

step=0

while [ $step -lt 4096 ]
do
        echo "step: $step"

        AB
        usleep $timeout

        BC
        usleep $timeout

        CD
        usleep $timeout

        DA
        usleep $timeout

        step=`expr $step + 8`
done

off

Let’s see it in action.

Advertisements
Categories: BeagleBone Tags:
  1. Akshay
    February 17, 2013 at 4:28 am

    Hi, I have bought the beaglebone board and i have the same stepper motor you have. I have very simple question…I know I need some sort of bus to connect the stepper motor board to beaglebone board…can you tell me where I can get such bus ?
    or
    How easily I can make this type of bus

    Thanks

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: