Dual MC33926 Motor Driver Shield for Arduino won't compile

I have a brand new Arduino Uno R3 verified working, running Arduino IDE v1.0.5 on windows 7 64bit. I am trying to get the demo sketch for Pololu Dual MC33926 Motor Driver Shield for Aduino, P.N. #2503 and it will not compile!
Here is my sketch copied verbatim:

[code]#include “DualMC33926MotorShield.h”

DualMC33926MotorShield md;
void stopIfFault()
{
if (md.getFault())
{
Serial.println(“fault”);
while(1);
}
}
void setup()
{
Serial.begin(115200);
Serial.println(“Dual MC33926 Motor Shield”);
md.init();
}
void loop()
{
for (int i = 0; i <= 400; i++)
{
md.setM1Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
delay(2);
}
for (int i = 400; i >= -400; i–)
{
md.setM1Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
}
delay(2);
}
for (int i = -400; i <= 0; i++)
{
md.setM1Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M1 current: ");
Serial.println(md.getM1CurrentMilliamps());
}
delay(2);
}
for (int i = 0; i <= 400; i++)
{
md.setM2Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
for (int i = 400; i >= -400; i–)
{
md.setM2Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
for (int i = -400; i <= 0; i++)
{
md.setM2Speed(i);
stopIfFault();
if (abs(i)%200 == 100)
{
Serial.print("M2 current: ");
Serial.println(md.getM2CurrentMilliamps());
}
delay(2);
}
}
}
[/code]

I also copied the libraries from git hub and verified imported into Arduino:

#include "DualMC33926MotorShield.h"

// Constructors ////////////////////////////////////////////////////////////////

DualMC33926MotorShield::DualMC33926MotorShield()
{
  //Pin map
  _nD2 = 4;
  _M1DIR = 7;
  _M2DIR = 8;
  _nSF = 12;
  _M1FB = A0; 
  _M2FB = A1;
}

DualMC33926MotorShield::DualMC33926MotorShield(unsigned char M1DIR, unsigned char M1PWM, unsigned char M1FB,
                                               unsigned char M2DIR, unsigned char M2PWM, unsigned char M2FB,
                                               unsigned char nD2, unsigned char nSF)
{
  //Pin map
  //PWM1 and PWM2 cannot be remapped because the library assumes PWM is on timer1
  _nD2 = nD2;
  _M1DIR = M1DIR;
  _M2DIR = M2DIR;
  _nSF = nSF;
  _M1FB = M1FB; 
  _M2FB = M2FB;
}

// Public Methods //////////////////////////////////////////////////////////////
void DualMC33926MotorShield::init()
{
// Define pinMode for the pins and set the frequency for timer1.

  pinMode(_M1DIR,OUTPUT);
  pinMode(_M1PWM,OUTPUT);
  pinMode(_M1FB,INPUT);
  pinMode(_M2DIR,OUTPUT);
  pinMode(_M2PWM,OUTPUT);
  pinMode(_M2FB,INPUT);
  pinMode(_nD2,OUTPUT);
  digitalWrite(_nD2,HIGH); // default to on
  pinMode(_nSF,INPUT);

  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
  // Timer 1 configuration
  // prescaler: clockI/O / 1
  // outputs enabled
  // phase-correct PWM
  // top of 400
  //
  // PWM frequency calculation
  // 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
  TCCR1A = 0b10100000;
  TCCR1B = 0b00010001;
  ICR1 = 400;
  #endif
}
// Set speed for motor 1, speed is a number betwenn -400 and 400
void DualMC33926MotorShield::setM1Speed(int speed)
{
  unsigned char reverse = 0;
  
  if (speed < 0)
  {
    speed = -speed;  // Make speed a positive quantity
    reverse = 1;  // Preserve the direction
  }
  if (speed > 400)  // Max PWM dutycycle
    speed = 400;
  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
  OCR1A = speed;
  #else
  analogWrite(_M1PWM,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
  #endif
  if (reverse)
    digitalWrite(_M1DIR,HIGH);
  else
    digitalWrite(_M1DIR,LOW);
}

// Set speed for motor 2, speed is a number betwenn -400 and 400
void DualMC33926MotorShield::setM2Speed(int speed)
{
  unsigned char reverse = 0;
  
  if (speed < 0)
  {
    speed = -speed;  // Make speed a positive quantity
    reverse = 1;  // Preserve the direction
  }
  if (speed > 400)  // Max PWM dutycycle
    speed = 400;
  #if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
  OCR1B = speed;
  #else
  analogWrite(_M2PWM,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
  #endif
  if (reverse)
    digitalWrite(_M2DIR,HIGH);
  else
    digitalWrite(_M2DIR,LOW);
}

// Set speed for motor 1 and 2
void DualMC33926MotorShield::setSpeeds(int m1Speed, int m2Speed)
{
  setM1Speed(m1Speed);
  setM2Speed(m2Speed);
}

// Return motor 1 current value in milliamps.
unsigned int DualMC33926MotorShield::getM1CurrentMilliamps()
{
  // 5V / 1024 ADC counts / 525 mV per A = 9 mA per count
  return analogRead(_M1FB) * 9;
}

// Return motor 2 current value in milliamps.
unsigned int DualMC33926MotorShield::getM2CurrentMilliamps()
{
  // 5V / 1024 ADC counts / 525 mV per A = 9 mA per count
  return analogRead(_M2FB) * 9;
}

// Return error status
unsigned char DualMC33926MotorShield::getFault()
{
  return !digitalRead(_nSF);
}

[code]#ifndef DualMC33926MotorShield_h
#define DualMC33926MotorShield_h

#include <Arduino.h>

class DualMC33926MotorShield
{
public:
// CONSTRUCTORS
DualMC33926MotorShield(); // Default pin selection.
DualMC33926MotorShield(unsigned char M1DIR, unsigned char M1PWM, unsigned char M1FB,
unsigned char M2DIR, unsigned char M2PWM, unsigned char M2FB,
unsigned char nD2, unsigned char nSF); // User-defined pin selection.

// PUBLIC METHODS
void init(); // Initialize TIMER 1, set the PWM to 20kHZ. 
void setM1Speed(int speed); // Set speed for M1.
void setM2Speed(int speed); // Set speed for M2.
void setSpeeds(int m1Speed, int m2Speed); // Set speed for both M1 and M2.
unsigned int getM1CurrentMilliamps(); // Get current reading for M1. 
unsigned int getM2CurrentMilliamps(); // Get current reading for M2.
unsigned char getFault(); // Get fault reading.

private:
unsigned char _nD2;
unsigned char _M1DIR;
unsigned char _M2DIR;
static const unsigned char _M1PWM = 9;
static const unsigned char _M2PWM = 10;
unsigned char _nSF;
unsigned char _M1FB;
unsigned char _M2FB;
};

#endif
[/code]

I cannot copy the output error messages from Arduino IDE and there are far too many to type in here, but basically I think there is some inconsistentcy in Arduino.h which snowballs down the line.

https://picasaweb.google.com/106842392549922890199/20130522?authuser=0&authkey=Gv1sRgCOWFmKSVovC56AE&feat=directlink

Hi.

I’m sorry you are having trouble with your shield. It sounds like the library is not correctly installed. You can find instructions on how to install the libraries under the “Programming Your Arduino” section of the shield’s user’s guide, which can be found under “Resources” tab of its product page:

pololu.com/catalog/product/2503/resources

If you still have trouble after installing the library, please let me know.

- Taylor

yEAH, still wont compile. Copied and pasted your example verbatim into Arduino IDE v1.0.5 I am using a Arduino Uno Rev3 under Windows 7, 64 bit.

I notice the offending error messages all reference files in the forward slash (linux style) method, as opposed to the backslash method common to Windows.

Could you tell me exactly how you are installing the library? Could you also provide a screen shot of the directory Documents/Arduino/libraries/DualMC33926MotorShield? Lastly, did you copy the library code from github and paste it into an editor yourself? If so, that might explain the problems you are having. Could you try downloading the zip file from github and extracting the files according to the instructions?

-Taylor

I navigate to the github repository, click on the files: DualMC33926MotorShield.cpp and DualMC33926MotorShield.h. I copy the code and paste into a new txt document using Windows notepad and save as plain txt with the requisite extension, in the directory as shown.

Ok, so I have deleted the files and reinstalled, downloading the .zip file and unzipping into the Arduino libraries directory.
There are some errors but it compiles successfully!


I will let you know if I have further issue. Thank you!

Thank you, thank you, thank you!!! Unzipping the file into my Arduino lib directory fixed my issues! Now I am on my way to making this the heart of my sumobot! One more question: what are the values for max reverse and max forward speeds? Here is my example test program.

[code]#include “DualMC33926MotorShield.h”

DualMC33926MotorShield md;

void setup()
{
md.init();
}
void loop()
{
md.setM1Speed(400);
md.setM2Speed(400);
delay(400);
md.setM1Speed(0);
md.setM2Speed(0);
delay(400);
}
[/code]

[quote=“mannyr7”]One more question: what are the values for max reverse and max forward speeds? Here is my example test program.
[/quote]
A cursory glance at the library suggests that “speed is a number betwenn -400 and 400”.
The library takes the input speed (and negates it if it’s negative, as well as saves the direction) and sets speed to 400 if you enter a number greater than 400. (Lines 64-70 and 87-93 in the library, if you’re interested.)