Pages

Tuesday, January 16, 2018

How to use an Osepp Motor controller shield

A few weeks ago I bought an Osepp motor controller shield for the robot I'm building. All I needed it to do was control four Roomba vacuum motors, which I thought would be pretty simple. There weren't any instructions that came with the shield, but I figured it wouldn't be to hard to find some online.
But it was. I found almost nothing.

I did get it working eventually though, mostly through trial and error, so now I can explain to other people how it works. (Well, at least how to control DC motors with it.)

First of all, here is a diagram of the board:

This looks complicated, but it's actually quite simple to understand. I could explain what everything does individually, but that would take too long and not be very interesting. Instead, try this simple circuit.

Materials:
  • Arduino
  • Osepp motor shield
  • small DC motor
  • 6 volt power supply (a pack of AA batteries will do)
  1. Start by mounting the motor shield on the Arduino board. Carefully slide all of the leads on the bottom of the shield into the black terminals on the Arduino. They should be around two thirds of the way in. Don't try to force them further, as doing this could make them bend and possibly brake off.
  2. Next, take the two leads from the motor and insert them into the motor one connectors on the shield. Polarity doesn't matter for now. Grab a screwdriver and tighten the screw terminals until the motor leads are secure.
  3. Plug the 6v power source into motor VSrc on the top left corner of the board, with the positive terminal on the right and negative on the left. A light should come on.
  4. Finally, plug a USB cord leaing to you're computer into the USB port on the Arduino board. Open the Arduino IDE and follow the steps to program it, or copy the entire program. Upload it onto the Arduino and watch it go!
  5. Running a DC motor with the motor shield
The Programming
Type the following code into the Arduino IDE, or, if you prefer, copy and paste it.

    #include <AFMotor.h>
    
    AF_DCMotor myMotor(1, MOTOR34_64KHZ); // create motor #2, 64KHz pwm
    
    void setup() {
      Serial.begin(9600);           // set up Serial library at 9600 bps
     
      myMotor.setSpeed(100);     // set the speed to 200 (maximum speed is 255)
    }
    
    void loop() {
      myMotor.run(FORWARD);                   //run motor forwards
      delay(1000);
      myMotor.run(BACKWARD);
      delay(1000);
      myMotor.run(RELEASE);
      delay(1000);   
}




Let's go over all those commands.
  • #include <AFmotor.h> this command tells the arduino IDE to include commands from the adafruit motor controller library. It must always go at the beginning of the program.
  • AF_DCMotor myMotor(1, MOTOR34_64KHZ); this command tells the program to include a motor named myMotor connected to the motor one connectors, which runs at 64 kilohertz. You can change the name of the motor and what connector it's in, but just keep it like this for now.
  • myMotor.setSpeed(100); this sets the running speed of myMotor. It can be used once in the setup area, or to change the speed in the loop area.
  • myMotor.run(FORWARD/BACKWARD/RELEASE); use this command to turn on or off motors and decide which direction they turn. FORWARD and BACKWARD turn the motor on, and RELEASE turns the motor off.
  • delay(1000); this command sets a delay in milliseconds.
Now you can make your own programs! This isn't all you can do with the motor shield, but it's all I know how to do. For more information on commands and programming look at https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino. You can skip the non-programming parts, as it was written for a different (but code-compatible) shield.

4 comments: