by lspikol on Wed Nov 14, 2012 7:44 pm

I am using the motor shield attached to an Arduino Leonardo to run a 4 motor robot platform.When I turn on the power the right rear motor immediately starts. When I run a motor test program the other 3 motors run correctly but the right rear motor shuts down and runs when the other 3 motors shut down.Any ideas why this is occurring??

Posts: 2
Joined: Wed Nov 14, 2012 7:24 pm

by adafruit_support_bill on Wed Nov 14, 2012 8:17 pm

The Leonardo is not completely compatible with Atmega 328-based Arduinos and we haven't tested compatibility with all shields. As the product description states:
It is probably not going to work with nearly any shields other than the proto shield. We haven't gone through and tested it with all the Adafruit shields and don't guarantee it will work until we've sat down and done a lot of testing and coding, so keep that in mind!
User avatar
Posts: 25319
Joined: Sat Feb 07, 2009 9:11 am

by lspikol on Wed Nov 14, 2012 11:42 pm

Thanks-I will try it with an uno.
Posts: 2
Joined: Wed Nov 14, 2012 7:24 pm

by Adeering on Fri Nov 23, 2012 9:03 am

Is there any word about making the shields work with the leonardo, working on a project that would benefit from the leonardo, but need the motor shield.
Posts: 11
Joined: Wed Nov 14, 2012 2:29 am

by moridinbg on Tue Dec 04, 2012 2:38 pm

Today I encountered the same issue. Too bad it's my first encounter with Arduino :D
I have got a Leonardo board and the motor shield, that have to work together. I don't have neither the time, nor the money to buy a Uno (and waste the Leonardo).

After extensive research and some AVR crash-course it looks like pins 3 and 11 are easy, insted of Timer2 they are on Timer0, which on the Leo is 8 bit too. Then when comparing datasheets I noticed that the Leo sets OC0A sets on match, clears on TOP, while the Uno setst OC2A on match and clears it on BOTTOM. Is this difference going to cause trouble?

Pins 5 and 6 seem a bit more tricky, as it's Timer4 that sets them and it's a 10 bit high speed timer with the option to work in 8 bit mode. Again, if I understand the datasheet correctly, unless the extra 2 bits (accessed in a 2-step way, due to the 8bit bus) are set, it works in 8-bit mode.
Then the configuration registers are set a bit differently (4 8-bit registers). There is a wave-form generation mode, but it differs again. "Update of OCR4x at TOP" "TOV4 Flag Set on TOP", while for the timer on the Uno its BOTTOM/MAX. Again I am not sure if this will be a problem.

I am modifing the AFMotor.cpp and will try. The trouble is the only motors I have now are 4V bipolar steppers and the shield is rated for 4.5V+ so maybe the modifications would be enaugh to get the shield working, but it won't be able to power the motor, or it is able to power it, but the modifications won't work. Either way if it doesn't work I won't have a way to know why :mrgreen:

The changed code is here:
It's only the inline functions defined after

If this actually works I will make it into a patch and make a pull request.
Posts: 2
Joined: Tue Dec 04, 2012 2:21 pm

by moridinbg on Tue Dec 04, 2012 11:49 pm

Not surprisingly Timer2 was successfuly replaced with Timer0 and I am driving one stepper up to 300RPM.

For the future generations:
The documentation states that the complimentary pin to OC4A - pin 5 is connected when COM4A1..0 is set to 01. This way the shield doesn't turn the steppers. If it's 10 it works.
Timer4 works like e regular 8bit timer and the only thing required to put in in Fast-PWM mode is to set the relevant COM4x1..0 and PWM4x.

This way both stepper output works on the Arduino Leonardo board with no hardware modifications and a few additions to the library code.

The tested by me code:
Posts: 2
Joined: Tue Dec 04, 2012 2:21 pm

by on Sun Mar 31, 2013 4:51 pm

moridinbg wrote:Not surprisingly Timer2 was successful replaced with Timer0 and I am driving one stepper up to 300RPM.
The tested by me code:

I've tried your code and MOTOR1-2 works well, but MOTOR4 doesn't show sign of life. MOTOR3 values are very strange, but the code motor should spin with speed 200, but motor 3 stop, starts, stop with different time intervals....
Do you know what might be a problem?
Here is my test code

Code: Select all
#include <AFMotor.h>

AF_DCMotor motor(4);

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

  // turn on motor

void loop() {
  uint8_t i;

Also can you share complete code of the modified library ?
Posts: 2
Joined: Sun Mar 31, 2013 4:40 pm

by on Sun Mar 31, 2013 5:50 pm
Posts: 2
Joined: Sun Mar 31, 2013 4:40 pm