Photon / Stepper Motor - only spins 1 direction [RESOLVED]

Hey everyone,

I recently bought a Photon, Stepper Motor, and Phobot Board to control a motor remotely. Since this is my first project with C, I just followed Simon Monk’s tutorial (link here and code copied below). After flashing the software, the motor started spinning successfully in one direction.

However, it’s supposed to then reverse direction and spin the other way… but it just freezes momentarily and makes a buzzing noise. So it’s only spinning successfully in one direction right now. Any ideas?

#include "PhoBot/PhoBot.h"

PhoBot p = PhoBot(12.0, 12.0);

void setup() {
}

void loop() {
    forward(100, 5);
    reverse(100, 5);
}

void forward(int numSteps, int period) {
    for (int i = 0; i < numSteps; i++) {
        p.setMotors("M3-F-100");
        p.setMotors("M4-B-100");
        delay(period);
        p.setMotors("M3-F-100");
        p.setMotors("M4-F-100");
        delay(period);
        p.setMotors("M3-B-50");
        p.setMotors("M4-F-50");
        delay(period);
        p.setMotors("M3-B-50");
        p.setMotors("M4-B-50");
        delay(period);
    }
}

void reverse(int numSteps, int period) {
    for (int i = 0; i < numSteps; i++) {
        p.setMotors("M3-B-100");
        p.setMotors("M4-B-100");
        delay(period);
        p.setMotors("M3-B-100");
        p.setMotors("M4-F-100");
        delay(period);
        p.setMotors("M3-F-50");
        p.setMotors("M4-F-50");
        delay(period);
        p.setMotors("M3-F-50");
        p.setMotors("M4-B-50");
        delay(period);
    }
}

Nevermind! I found a datasheet for this stepper motor online.

Turns out I had mixed up the wires. Black and Green wires are part of one motor coil, and Blue and Red are part of the second motor coil.

After wiring each pair to M4 and M3 respectively on the Phobot board, the motor is now spinning successfully in both directions.

I had an issue where the 28BYJ-48 with ULN2003 (as pictured here: Controlling a stepper motor using Stepper library - Photon crashes with 'usage fault') only turned in one direction. I found this topic on the Arduino forum that suggested swapping the middle two pins which got it working perfectly (on 4.8v USB power off VIN of the Photon).

http://forum.arduino.cc/index.php?topic=143276.0

Just in case someone else stumbles across a similar problem!