## 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));
}