---

Friday, September 25, 2015

The Phobot board and Stepper Motors

The MonkMakes Phobot motor controller board is designed primarily to control a pair of DC motors, to make roving robots that can be controlled over the Internet using the Particle Photon Arduino-ish IoT module. However, you can also use it to drive a bipolar stepper motor.



The stepper motor I used was this 12V motor from Adafruit.

Wire one coil of the stepper (yellow and read wires for my motor) to the M4 screw terminals and the other coil (gray and green) to M3. You will also need a 12V DC power supply wires to screw terminals GND and Vin on the Phobot board.


The Phobot will provide 12V to the stepper motor, but also provide a regulated 5V supply to the Photon, so your Photon's USB port does not need to be connected.

All that remains is to write some code. So log into particle.io and then start a new App. Paste the following code into it:

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

You will also need to add the PhoBot library to the app, by selecting the Libraries button on the Particle IDE and then search for Phobot. Click on the INCLUDE IN APP button to add the library to your new app.



Click on the lightening bolt to deploy the app to your Photon. As soon as the app has finished installing, the motor should start turning, first in one direction and then the other.

Try changing the value of the second parameter to forward and reverse in loop from 5 to 10 and the motor will turn at half the speed. You can also try altering the number of steps (the first parameter).

Note that a period of 5ms is a little fast for this motor, so if you want to avoid steps being missed, it probably needs to be 10ms or more.

You can buy the Phobot board from Seeedstudio Adafruit and also find it on Amazon.com and Amazon.co.uk.

No comments: