Motor Shield on the Arduino MEGA 2560
Moderators: adafruit_support_bill, adafruit

Motor Shield on the Arduino MEGA 2560

by lt.surge on Thu Nov 29, 2012 3:33 pm

Does the Motorshield work on an Arduino MEGA 2560?
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit on Thu Nov 29, 2012 3:53 pm

yes
User avatar
adafruit
 
Posts: 11717
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Thu Nov 29, 2012 4:01 pm

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.
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit_support_bill on Thu Nov 29, 2012 5:20 pm

Can you post photos of the front & back of the shield?
User avatar
adafruit_support_bill
 
Posts: 31041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Thu Nov 29, 2012 6:52 pm

Photos
Attachments
Back.jpg
Back of Shield
Back.jpg (359.85 KiB) Viewed 1895 times
Front.jpg
front of shield
Front.jpg (364.23 KiB) Viewed 1895 times
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Thu Nov 29, 2012 6:55 pm

The Shield attached to the Arduino MEGA
Attachments
Arduino.jpg
Shield on top of the mega
Arduino.jpg (311.09 KiB) Viewed 1895 times
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit_support_bill on Thu Nov 29, 2012 11:52 pm

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?
User avatar
adafruit_support_bill
 
Posts: 31041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Fri Nov 30, 2012 12:54 am

It seems only motor 1 will run and motor 2,3 and 4 will not run on the code posted above,
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit_support_bill on Fri Nov 30, 2012 7:19 am

And all 4 will run on the UNO with the same shield?
User avatar
adafruit_support_bill
 
Posts: 31041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Fri Nov 30, 2012 9:14 am

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.
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit_support_bill on Fri Nov 30, 2012 9:45 am

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.
User avatar
adafruit_support_bill
 
Posts: 31041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield on the Arduino MEGA 2560

by lt.surge on Fri Nov 30, 2012 3:39 pm

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

by lt.surge on Sat Dec 01, 2012 4:55 pm

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?
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

by adafruit_support_bill on Sun Dec 02, 2012 9:24 am

The "MOTOR12_xxxKHZ" constants are for motors 1 & 2 only. The tutorial says:
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.

Apparantly the "ignore" part is not accurate for the Mega.

The library defines Additional frequencies for motors 3 & 4:
Code: Select all | TOGGLE FULL SIZE
    #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


You might give them a try. I'll try to round up some motors and check it out later this afternoon.
User avatar
adafruit_support_bill
 
Posts: 31041
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield on the Arduino MEGA 2560

by Dan.SE on Wed Dec 05, 2012 1:32 am

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
Dan.SE
 
Posts: 1
Joined: Wed Dec 05, 2012 12:26 am