Motor Shield on the Arduino MEGA 2560
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Motor Shield on the Arduino MEGA 2560
Does the Motorshield work on an Arduino MEGA 2560?
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
Okay well I tried this
#include <AFMotor.h>
AF_DCMotor motor(4, MOTOR12_1KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}
void loop() {
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
but it doesn't do anything but when I ran the code from the adafruit tutorial for motor 2 it worked. I know that the motor shield and the motor is working fine because when I ran the same code using an Arduino UNO It works.
#include <AFMotor.h>
AF_DCMotor motor(4, MOTOR12_1KHZ); // create motor #2, 64KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}
void loop() {
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(1000);
Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}
but it doesn't do anything but when I ran the code from the adafruit tutorial for motor 2 it worked. I know that the motor shield and the motor is working fine because when I ran the same code using an Arduino UNO It works.
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield on the Arduino MEGA 2560
Can you post photos of the front & back of the shield?
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
Photos
- Attachments
-
- Back of Shield
- Back.jpg (359.85 KiB) Viewed 3381 times
-
- front of shield
- Front.jpg (364.23 KiB) Viewed 3381 times
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
The Shield attached to the Arduino MEGA
- Attachments
-
- Shield on top of the mega
- Arduino.jpg (311.09 KiB) Viewed 3381 times
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield on the Arduino MEGA 2560
Looks like a good clean build. It appears that you have 4 motors connected. Do any of them run on the Mega? If so, which ones?
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
It seems only motor 1 will run and motor 2,3 and 4 will not run on the code posted above,
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield on the Arduino MEGA 2560
And all 4 will run on the UNO with the same shield?
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
yes the shield works fine on the Uno I tried the shield on a different MEGA and I still get the same problem so I am not sure if its the board or the shield.
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield on the Arduino MEGA 2560
I'll round up the parts and try to reproduce this. I've got a robot tournament tomorrow, so it will probably take me a couple of days.
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
Thank you for all the help
- lt.surge
- Posts: 15
- Joined: Wed Oct 17, 2012 9:11 am
Re: Motor Shield on the Arduino MEGA 2560
I have been playing with the code and it seems that all the motor works when I initialize them like this
AF_DCMotor motor(4);
and ommit the , Motor12_1KHZ
now I am not 100% sure why, but it seems to at least turn the motors. Now I have a slight question, do all 4 motors run on the same frequency of 1KHZ pwm?
AF_DCMotor motor(4);
and ommit the , Motor12_1KHZ
now I am not 100% sure why, but it seems to at least turn the motors. Now I have a slight question, do all 4 motors run on the same frequency of 1KHZ pwm?
- adafruit_support_bill
- Posts: 88151
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield on the Arduino MEGA 2560
The "MOTOR12_xxxKHZ" constants are for motors 1 & 2 only. The tutorial says:
The library defines Additional frequencies for motors 3 & 4:
You might give them a try. I'll try to round up some motors and check it out later this afternoon.
Apparantly the "ignore" part is not accurate for the Mega.For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, orMOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and ignore any setting given.
The library defines Additional frequencies for motors 3 & 4:
Code: Select all
#define MOTOR34_64KHZ _BV(CS00) // no prescale
#define MOTOR34_8KHZ _BV(CS01) // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
- dan.se
- Posts: 1
- Joined: Wed Dec 05, 2012 12:26 am
Re: Motor Shield on the Arduino MEGA 2560
I too am experiencing the identical symptoms referenced by the original poster (lt.surge). I have an Arduino Mega 2560 Rev 2, and an Adafruit V1.0 Motor Shield, using IDE 1.0.1, and the Motor Shield library downloaded from the GitHub website within the past few days. Instead of motors, I connected back-to-back LEDs to each port, plus a resistor in series with each LED to limit current. LEDs were wired in both directions across each motor port so I could visually see a "high" signal, and its polarity.
Using the sample "Tick Tock" code, port M1 worked in both directions. None of the other three ports functioned in either direction. I then modified the tick-tock program to drive all four ports at the same time for troubleshooting purposes.
A quick bit of diagnostic work while the "tick-tock" program was running showed IC1-1 ("1-2 ENABLE") enabled (high, 4.8Vdc), but not any of the other "Enable" ports (IC1-9, "3-4EN"), (IC2-1, "1-2EN"), or IC2-9, "3-4EN"). The ENABLE pins for each of the non-functioning ports' ENABLE pins showed approximately 2.0 Vdc on them, which would lead me to believe the Mega 2560 ports connected to the respective Motor Shield ENABLE pins were likely tri-stated in a high-Z condition.
After modifying the "tick-tock" program motor initialization code as suggested by lt.surge, all four ports are functional to the extent they illuminate my LED "motors" correctly.
Changing this:
AF_DCMotor motor1(1, MOTOR12_1KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_1KHZ); // create motor #2, 64KHZ pwm
AF_DCMotor motor3(3, MOTOR12_1KHZ); // create motor #3, 64KHZ pwm
AF_DCMotor motor4(4, MOTOR12_1KHZ); // create motor #4, 64KHZ pwm
to this:
AF_DCMotor motor1(1); // create motor #1
AF_DCMotor motor2(2); // create motor #2
AF_DCMotor motor3(3); // create motor #3
AF_DCMotor motor4(4); // create motor #4
... worked. All four ports now light the LEDs and change the direction of polarity per my program.
I've not yet done any testing involving changing the PWM duty cycle or frequency. That's next.
It appears there's something different about the Mega 2560 that doesn't like the way the Motor Shield library code attempts to initialize the motors.
Still more diagnostic work to do .. but at least all four ports are now functioning to some extent.
Dan
Using the sample "Tick Tock" code, port M1 worked in both directions. None of the other three ports functioned in either direction. I then modified the tick-tock program to drive all four ports at the same time for troubleshooting purposes.
A quick bit of diagnostic work while the "tick-tock" program was running showed IC1-1 ("1-2 ENABLE") enabled (high, 4.8Vdc), but not any of the other "Enable" ports (IC1-9, "3-4EN"), (IC2-1, "1-2EN"), or IC2-9, "3-4EN"). The ENABLE pins for each of the non-functioning ports' ENABLE pins showed approximately 2.0 Vdc on them, which would lead me to believe the Mega 2560 ports connected to the respective Motor Shield ENABLE pins were likely tri-stated in a high-Z condition.
After modifying the "tick-tock" program motor initialization code as suggested by lt.surge, all four ports are functional to the extent they illuminate my LED "motors" correctly.
Changing this:
AF_DCMotor motor1(1, MOTOR12_1KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_1KHZ); // create motor #2, 64KHZ pwm
AF_DCMotor motor3(3, MOTOR12_1KHZ); // create motor #3, 64KHZ pwm
AF_DCMotor motor4(4, MOTOR12_1KHZ); // create motor #4, 64KHZ pwm
to this:
AF_DCMotor motor1(1); // create motor #1
AF_DCMotor motor2(2); // create motor #2
AF_DCMotor motor3(3); // create motor #3
AF_DCMotor motor4(4); // create motor #4
... worked. All four ports now light the LEDs and change the direction of polarity per my program.
I've not yet done any testing involving changing the PWM duty cycle or frequency. That's next.
It appears there's something different about the Mega 2560 that doesn't like the way the Motor Shield library code attempts to initialize the motors.
Still more diagnostic work to do .. but at least all four ports are now functioning to some extent.
Dan
Please be positive and constructive with your questions and comments.