Teensy 2.0 and DRV8835 motor controller board

Status
Not open for further replies.

bps

Active member
I am building a little robot using a Teensy 2.0 (because of its physical size) and a Pololu DRV8835 motor control board. I have encountered a problem which the folks at Pololu are having problems with. Using their sample code (and my code derived from it) I cannot get the motors to rotate both ways. When I pass negative values to the speed functions, the motors turn. When I pass positive values to the functions, they don't. I have set up an UNO using the same wiring a code (different motors though) and all's well. I attach the Pololu sample code. I've tried changing the wiring, changing the pins (making the appropriate hanges in the cpp file which is where the changes get made rather than through PinMode()s of #defines) and nothing seems to work. I'm stumped. Could anyone suggest anything? Could this be a problem with the Teensy 2.0?

Here's the code:

#include <DRV8835MotorShield.h>

/*
* This example uses the DRV8835MotorShield library to drive each motor with the
* Pololu DRV8835 Dual Motor Driver Shield for Arduino forward, then backward.
* The yellow user LED is on when a motor is set to a positive speed and off when
* a motor is set to a negative speed.
*/

#define LED_PIN 11

DRV8835MotorShield motors;

void setup()
{
pinMode(LED_PIN, OUTPUT);

// uncomment one or both of the following lines if your motors' directions need to be flipped
//motors.flipM1(true);
//motors.flipM2(true);
}

void loop()
{
// run M1 motor with positive speed

digitalWrite(LED_PIN, HIGH);

for (int speed = 0; speed <= 400; speed++)
{
motors.setM1Speed(speed);
delay(2);
}

for (int speed = 400; speed >= 0; speed--)
{
motors.setM1Speed(speed);
delay(2);
}

// run M1 motor with negative speed

digitalWrite(LED_PIN, LOW);

for (int speed = 0; speed >= -400; speed--)
{
motors.setM1Speed(speed);
delay(2);
}

for (int speed = -400; speed <= 0; speed++)
{
motors.setM1Speed(speed);
delay(2);
}

// run M2 motor with positive speed

digitalWrite(LED_PIN, HIGH);

for (int speed = 0; speed <= 400; speed++)
{
motors.setM2Speed(speed);
delay(2);
}

for (int speed = 400; speed >= 0; speed--)
{
motors.setM2Speed(speed);
delay(2);
}

// run M2 motor with negative speed

digitalWrite(LED_PIN, LOW);

for (int speed = 0; speed >= -400; speed--)
{
motors.setM2Speed(speed);
delay(2);
}

for (int speed = -400; speed <= 0; speed++)
{
motors.setM2Speed(speed);
delay(2);
}

delay(500);
}
 
Status
Not open for further replies.
Back
Top