0

So I am trying to work on a mini battle bot project. However, it has been a while since I have worked with my Arduino electronics. So I am going through and learning how to do each thing before putting it all together. So far I have learned how to use the IR remote and got that working. I got my brushless motor with esc working with the Arduino. Now I am trying to get my dc motors working for the wheel component. I am just trying to get one motor running from the motor shield as proof of concept essentially. So here is the run down.

I have 8xAA batteries in series with each AA running at 1.5 volts for a total of 12 volts. I have verified this with my multimeter. The dc motors need 9-18 volts to run, so 12 should have it running. However, I will probably step that up to 18 volts for maximum power and run 4 dc motors since I am guessing my project will be a little heavy, so I need as much power as possible. I have the 8xAA batteries connected correctly with positive to the positive and negative to negative on the motor shield. I have checked my soldering connection and the pins are not bent and it looks straight and good. I made sure I firmly pressed down to get it onto the Arduino. Motor is connected to m2 as per the code. I don't understand why this isn't working as it should work. I have tried using this form: Why is my Adafruit motor shield not spinning my motors?

And that did not solve it. I originally was using a 9 volt battery but that form told me to use more than 9 volts and to use AA batteries, so I did that. I also checked my connections and made sure soldering is good. Here is my code:

#include <AFMotor.h>

// DC motor on M2
AF_DCMotor motor(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor party!");

  // turn on motor #2
  motor.setSpeed(200);
  motor.run(RELEASE);
}

int i;

// Test the DC motor
void loop() {
  motor.run(FORWARD);
}

I have connected my motor to the battery directly and motor runs just fine. I have checked the voltage of my battery and it is great, not below the 12 volts and not above 13 volts. I have opened up serial monitor and I do see 'motor party' so I know the code is running. I looked for errors down below and saw none. The port I have checked and it is correct. Motor shield is made by Adafruit. I do have the correct library installed, in fact I just installed it today so I have up to date library. The lights on the Arduino light up and the light indicating power on the motor shield also light up when my AA batteries are plugged in. When I plug it in, lights light up but motor doesn't run. Here are a few pictures.

https://i.sstatic.net/cSo3x.jpg

I am have a hard time figuring this out, so if anyone can help me, thanks in advance.

7
  • 1
    I would double check the wiring. The motor controller is pretty tough. Most likely you would know if you blew it up. Is there a drive enable light on the motor shield? Does it come on? If not, try replacing with motor drive with an LED or measure the pin with a meter. Commented Jul 29, 2019 at 0:05
  • I have tripled checked the wiring, it is all good as you can see in the picture. About the drive enable light, I see a "power" led that does light up when the AA batteries are connected to it. Other than that, I do not see one. For measuring the pin, do you mean measure m2 on the shield? If so, I have tried that but my multimeter reads 0 when set to 20 volts DC. Partially why I think it is broken, but I never seen any smoke or anything to really tell me that I 'blew it up.'
    – Bob G.
    Commented Jul 29, 2019 at 1:15
  • I just added 2 more pictures to the end, via the site I gave. These show it plugged in as well as a close up while plugged in.
    – Bob G.
    Commented Jul 29, 2019 at 1:29
  • 1
    I haven't used this board but it does look pretty nice. I found tech info on it here it uses a couple of 6612 dual h-bridges. It looks like each motor uses a PWM (speed) signal and two directional control signals which look generated on board and controlled over SPI Commented Jul 29, 2019 at 6:11
  • 2
    This AF Documentation uses different commands. Commented Jul 29, 2019 at 6:13

2 Answers 2

2

The commands you are using don't match the ones listed for this board. Here is the AF Documentation for the Motor Shield Board V2.

Try

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *motor = AFMS.getMotor(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor party!");

  // turn on motor #2
  AFMS.begin();
}

int i;

// Test the DC motor
void loop() {
  motor->run(FORWARD);
}

Note: In this library, getMotor() returns creates a pointer; so, you have to use "->" rather and "." to access the motor run() method.

3

As noted by markshancock, you are using an older version of the Adrafruit Motor Shield library meant for the version 1 of the board (you have the version 2.3), and according to their forum they are not compatible (they use different communication protocols) use the newer version of the library https://forums.adafruit.com/viewtopic.php?f=31&p=276888

3
  • So yes a new library and different code did the trick. It now works, however, I want to give the right person credit here which you said "as noted by markshancock" so I will give him the credit if he posts an answer, if not then I will give you the thumbs up and check mark. I do see that this new code uses OOP so I assume I have to create a new object for each motor?
    – Bob G.
    Commented Jul 29, 2019 at 15:57
  • Oh, I see with the documentation, it just said I can give it another name and initialize it with a different motor, so I don't need to create an entirely new object.
    – Bob G.
    Commented Jul 29, 2019 at 16:02
  • Thanks @BobG. Glad to hear that was the issue. I added an answer as you requested :) Commented Jul 30, 2019 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.