Motor Shield v1.2 compatible Leonardo

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
fandujar
 
Posts: 3
Joined: Thu Oct 24, 2013 10:31 am

Motor Shield v1.2 compatible Leonardo

Post by fandujar »

I have an arduino leonardo and motor shield v1.2, and they are not compatibles.
How can i connect both of them using a protoboard for use motor shield v1.2 in

Do you have any diagram to see how to map between leonardo pins and engine shield?

Thanks

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v1.2 compatible Leonardo

Post by adafruit_support_bill »

It is more complicated than simply mapping pins. The AF_Motor Library uses timers to control the PWM frequency for speed control. You would need to modify the library and re-write the timer code to match the 32U4 timers in the Leonardo.

It would be much simpler to either use one of the compatible Arduinos (Mega 1280 & 2560, Diecimila, Duemilanove, and UNO) or switch to the V2 motor shield which works with all Arduinos. http://www.adafruit.com/products/1438

fandujar
 
Posts: 3
Joined: Thu Oct 24, 2013 10:31 am

Re: Motor Shield v1.2 compatible Leonardo

Post by fandujar »

Thanks for your answer.
I have found a library for 32U4, and what I need is to know how to map the pins.
Can you help me to know what pins to map between leonardo and motor shield in a protoboard??

Thanks.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v1.2 compatible Leonardo

Post by adafruit_support_bill »

I have found a library for 32U4
What library did you find? You can't map the pins unless you know what timers are used.

fandujar
 
Posts: 3
Joined: Thu Oct 24, 2013 10:31 am

Re: Motor Shield v1.2 compatible Leonardo

Post by fandujar »

Code: Select all

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

// updated for Arduino 1.0.2 by mem 22 Nov 2012

#ifndef _AFMotor_h_
#define _AFMotor_h_

#include <inttypes.h>
#include <avr/io.h>

//#define MOTORDEBUG 1

#define MICROSTEPS 16         // 8 or 16

#if defined(__AVR_ATmega8__) || \
    defined(__AVR_ATmega48__) || \
    defined(__AVR_ATmega88__) || \
    defined(__AVR_ATmega168__) || \
    defined(__AVR_ATmega328P__)
#define MOTOR12_64KHZ _BV(CS20)  // no prescale
#define MOTOR12_8KHZ _BV(CS21)   // divide by 8
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS22)  // divide by 64

#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define MOTOR12_64KHZ _BV(CS10)  // no prescale
#define MOTOR12_8KHZ _BV(CS11)   // divide by 8
#define MOTOR12_2KHZ _BV(CS11) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS12)  // divide by 64

[i]#elif defined(__AVR_ATmega32U4__) // Leonardo (mem 22 Nov 2012)[/i]
#define MOTOR12_64KHZ _BV(CS00)  // no prescale
#define MOTOR12_8KHZ _BV(CS01)   // divide by 8
#define MOTOR12_2KHZ _BV(CS01) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS02)  // divide by 64
#endif

#if defined(__AVR_ATmega8__) || \
    defined(__AVR_ATmega48__) || \
    defined(__AVR_ATmega88__) || \
    defined(__AVR_ATmega168__) || \	
    defined(__AVR_ATmega328P__)	
#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
#else
#define MOTOR34_64KHZ _BV(CS40)  // no prescale
#define MOTOR34_8KHZ _BV(CS41)   // divide by 8
#define MOTOR34_1KHZ _BV(CS41) | _BV(CS40)  // divide by 64
#endif

#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4

#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3
#define MICROSTEP 4

/*
#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB

#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4

#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7

#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB
*/

// Arduino pin names
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8

class AFMotorController
{
  public:
    AFMotorController(void);
    void enable(void);
    friend class AF_DCMotor;
    void latch_tx(void);
};

class AF_DCMotor
{
 public:
  AF_DCMotor(uint8_t motornum, uint8_t freq =  MOTOR34_8KHZ);
  void run(uint8_t);
  void setSpeed(uint8_t);

 private:
  uint8_t motornum, pwmfreq;
};

class AF_Stepper {
 public:
  AF_Stepper(uint16_t, uint8_t);
  void step(uint16_t steps, uint8_t dir,  uint8_t style = SINGLE);
  void setSpeed(uint16_t);
  uint8_t onestep(uint8_t dir, uint8_t style);
  void release(void);
  uint16_t revsteps; // # steps per revolution
  uint8_t steppernum;
  uint32_t usperstep, steppingcounter;
 private:
  uint8_t currentstep;

};

uint8_t getlatchstate(void);

#endif
Last edited by adafruit_support_bill on Mon Oct 28, 2013 11:40 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.

User avatar
adafruit_support_bill
 
Posts: 88136
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield v1.2 compatible Leonardo

Post by adafruit_support_bill »

Where did you get the library? That is not our supported version.
Whoever made the changes for the Leonardo should be able to tell you how to connect it.

User avatar
inventor
 
Posts: 9
Joined: Sat Jun 29, 2013 8:12 pm

Re: Motor Shield v1.2 compatible Leonardo

Post by inventor »

Work Modified for the Leonardo by Michael Margolis

https://github.com/j0hnds/sketchbook/tr ... es/AFMotor

thanks

User avatar
esteban_franco
 
Posts: 4
Joined: Fri May 05, 2017 3:12 pm

Re: Motor Shield v1.2 compatible Leonardo

Post by esteban_franco »

hi fandujar,
i need to download the fowlder you had post because i have the same problem as you had. Could you give me another link because the last link you wrote doesn`t have any download bottom. Or if you have another way to help me wrote to my gmail ([email protected])
thanks ,
esteban

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

Return to “Arduino Shields from Adafruit”