0

Running 3 or 4 DC motors on Adafruit V2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Running 3 or 4 DC motors on Adafruit V2

by Richman101 on Thu Feb 14, 2019 4:50 pm

I have an Arduino Uno v3 and Adafruit Motor Shield v2.3. I can successfully run 2 DC motors connected to the same terminal block on either side of the board (Port M1 & M2 or Port M3 & M4). However I can not run 2 DC motors when connected to the terminal blocks on the opposite sides of the board (ie: Port M1 & M3). My goal is to run 3 or 4 separate DC motors on this Shield since it states I can run 4.

I started with the Example in the Adafruit Motorshield Library using port M1 and modified it accordingly. When I add a second port to the opposite side of the board (M3 or M4) I get the following error when I try and compile the code:

redefinition of 'Adafruit_DCMotor* myMotor'

I'm new at this and tried to find an example of someone running 4 DC's on the Adafruit but couldn't find anything. I'm also quite aware that I'm probably doing something stupid or over looked something obvious - I just can't find the problem. If anyone can help me out I'd appreciate it.

My code is below and the last line gets the error code.

Thanks

Rich
_________

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

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)

// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1

Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor = AFMS.getMotor(3);

Error Message: redefinition of 'Adafruit_DCMotor* myMotor'

Richman101
 
Posts: 3
Joined: Thu Feb 14, 2019 4:03 pm

Re: Running 3 or 4 DC motors on Adafruit V2

by adafruit_support_bill on Thu Feb 14, 2019 5:02 pm

Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor = AFMS.getMotor(3);

Error Message: redefinition of 'Adafruit_DCMotor* myMotor'

As the message says, you are re-defining the variable named myMotor. If you want to have 2 different motor pointer variables, you need to give them different names:

Code: Select all | TOGGLE FULL SIZE
Adafruit_DCMotor *myMotor_1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor_3 = AFMS.getMotor(3);

adafruit_support_bill
 
Posts: 72771
Joined: Sat Feb 07, 2009 10:11 am

Re: Running 3 or 4 DC motors on Adafruit V2

by Richman101 on Thu Feb 14, 2019 7:33 pm

Hey - Thanks for the help. I new it was something simple. It's my third day working with Arduino/Adafruit and it's easy to get lost with the definitions. I'll give it a try tomorrow but assume it will fix the bug.

Thanks again

Richman101
 
Posts: 3
Joined: Thu Feb 14, 2019 4:03 pm

Re: Running 3 or 4 DC motors on Adafruit V2

by Richman101 on Fri Feb 15, 2019 12:13 pm

Bill
Thanks for the answer - worked like a charm. I now have 4 independently controlled DC motors operated by 4 separate 0-4V analog input signals. Thanks again for helping.

Rich

Richman101
 
Posts: 3
Joined: Thu Feb 14, 2019 4:03 pm

Re: Running 3 or 4 DC motors on Adafruit V2

by adafruit_support_bill on Fri Feb 15, 2019 12:51 pm

Good to hear that is working. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 72771
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.