Leonardo hack for AFmotor lib shield v1

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
lisleman
 
Posts: 117
Joined: Wed Aug 06, 2014 5:53 pm

Leonardo hack for AFmotor lib shield v1

Post by lisleman »

Last week I was browsing the DIY electronics section of Micro Center and bought a motor shield by OSEPP. I was surprised that when I went to the OSEPP site for technical details, they directed me to AdaFruit. The AFmotor library is offered for the motor shield V1.x (I was also surprised to learn AdaFruit version 2 would have been much better for me. Oh well).

I quickly discovered the library is incompatible with the Leonardo which I plan to use. I searched and read many posting about timers and registers to control the PWM outputs. I tried to modify the library for Leonardo timers but in the end my modifications only worked on M4. Two of the motor objects crashed the program.

I thought it might be helpful to other DIYers to offer the "fixes" I finally used.

First off - this fix does not apply to stepper type motors. I only have DC and servo motors so I didn't bother with steppers.

The motor shield assigns the PWM output of the following pins to the motor objects:
M1 pin 11
M2 pin 3
M3 pin 6
M4 pin 5
servos pins 9 and 10

The fix is straight forward.
Replace the frequency changing/setting register stuff in AFMotor.cpp with just the assigned pinMode call, i.e.. pinMode(11, OUTPUT). Then replace the register assign (OCRxA, OCRxB) with a call to analogWrite(), i.e. analogWrite(11, s).

Fortunately the motor control functions (FORWARD, BACKWARD, RELEASE) work fine as is.

I suspect the stepper functions would require more timer register work than I care to attempt. I just deleted the stepper section from the library.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Leonardo hack for AFmotor lib shield v1

Post by adafruit_support_mike »

lisleman wrote:Last week I was browsing the DIY electronics section of Micro Center and bought a motor shield by OSEPP. I was surprised that when I went to the OSEPP site for technical details, they directed me to AdaFruit.
That happens occasionally, and leads to uncomfortable conversations when people get here.

We have no quarrel with other people selling their versions of our designs. That's what Open Hardware means. Thing is, you have to make a lot of your own decisions to turn a design into a product, and we don't know how anyone else made those decisions. Suggestions that work for our products might kill someone else's based on the same design.

Bottom line, only the people who selected the parts and ordered fabrication know enough about a product to support it.

I'm glad to hear you got the shield to work.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”