Motor Shield on the Arduino MEGA 2560

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Thu Nov 29, 2012 2:33 pm

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


Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Thu Nov 29, 2012 3: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 8:11 am


Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Thu Nov 29, 2012 5:52 pm

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

Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Thu Nov 29, 2012 5:55 pm

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

Re: Motor Shield on the Arduino MEGA 2560

Postby adafruit_support_bill » Thu Nov 29, 2012 10: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: 16639
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Thu Nov 29, 2012 11:54 pm

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 8:11 am


Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Fri Nov 30, 2012 8: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 8:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby adafruit_support_bill » Fri Nov 30, 2012 8: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: 16639
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Fri Nov 30, 2012 2:39 pm

Thank you for all the help
lt.surge
 
Posts: 15
Joined: Wed Oct 17, 2012 8:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby lt.surge » Sat Dec 01, 2012 3: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 8:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby adafruit_support_bill » Sun Dec 02, 2012 8: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
    #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: 16639
Joined: Sat Feb 07, 2009 9:11 am

Re: Motor Shield on the Arduino MEGA 2560

Postby Dan.SE » Wed Dec 05, 2012 12: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: Tue Dec 04, 2012 11:26 pm

Next

Return to Arduino

Who is online

Users browsing this forum: No registered users and 23 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
Android[6]
 
BeagleBone[23]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]