Stepper motor with Arduino motor shield

We have a bunch of Ardunio-brand motor shields and I wanted to jot down what it took to drive a stepper motor with them. The documentation really only tells you how to hook up DC motors, though it does say you can just use the outputs to drive a stepper. I thought that meant I should use pins 3, 11, 12, and 13 for the four coils of my stepper, but that didn’t quite work out. I was confused about how to energize each of the outputs so I finally just sent all 16 combinations of those pins to see which combos are the ones I needed. Here’s what I found. For the list below, A+, A-, B+, and B- refer to the outputs on the board and the pin order is 3, 11, 12, 13. 1 means high, 0 means low. The integer in parentheses is the decimal equivalent to the binary.

  • B-: 1000 (4)
  • B+: 1001 (5)
  • A-: 1000 (8)
  • A+: 1010 (10)

If you consider the four coils to be the cardinal directions, I put north on B-, south on B+, east on A-, and west on A+. To get half steps:

  • NE: 1100 (12)
  • SE: 1101 (13)
  • SW: 1111 (15)
  • NW: 1110 (14)

So to do the standard 8 steps when doing half steps, the decimal order is

4, 12, 8, 13, 5, 15, 10, 14

Here’s some quick code for turning decimals into firing the correct pins:

void fixbool(int n) {
digitalWrite(3, HIGH && (n & B1000));
digitalWrite(11, HIGH && (n & B100));
digitalWrite(12, HIGH && (n & B10));
digitalWrite(13, HIGH && (n & B1));
}

Advertisements

About Andy "SuperFly" Rundquist

Professor of physics at Hamline University in St. Paul, MN
This entry was posted in arduino. Bookmark the permalink.

One Response to Stepper motor with Arduino motor shield

  1. i like your blog and post

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