Version: 1.0.1
Release Date: 2014-08-15
www.pololu.com
This is a library for the Arduino that interfaces with the Pololu DRV8835 Dual Motor Driver Shield for Arduino. It makes it simple to drive two brushed, DC motors.
Download the archive from GitHub, decompress it, and drag the “DRV8835MotorShield” folder to your arduino-xx/libraries directory. Then restart the Arduino environment, so the libraries can be updated to include the library and its examples.
The Pololu DRV8835 Dual Motor Driver Shield for Arduino can be purchased on Pololu’s website.
This shield should work with all Arduino boards and clones that behave like a standard Arduino board. We have specifically tested this shield (using this Arduino library) with:
- Arduino Uno R3
- Arduino Leonardo
- Arduino Mega 2560
- Arduino Due
- Arduino Duemilanove (ATmega328P)
This library configures Timer 1 on the Uno R3, Leonardo, and Duemilanove to generate a 20 kHz PWM frequency for the motors. The library uses analogWrite on any board that does not use an ATmega168, ATmega328P or ATmega32U4. On the Mega 2560 and Due, analogWrite generates 489 Hz and 1 kHz PWM frequencies, respectively, with the default timer configuration.
Open this example code sketch by selecting File→Examples→DRV8835MotorShield→DRV8835MotorShieldDemo.
The demo ramps motor 1 from stopped to full speed forward, ramps down to full speed reverse, and back to stopped. Then, it does the same with the other motor.
void setM1Speed(int speed)
- Set speed and direction for motor 1. Speed should be between -400 and 400. The motors brake at 0 speed. Positive speeds correspond to motor current flowing from M1A to M1B. Negative speeds correspond to motor current flowing from M1B to M1A.
void setM2Speed(int speed)
- Set speed and direction for motor 2. Speed should be between -400 and 400. The motors brake at 0 speed. Positive speeds correspond to motor current flowing from M2A to M2B. Negative speeds correspond to motor current flowing from M2B to M2A.
void setSpeeds(int m1Speed, int m2Speed)
- Set speed and direction for motor 1 and 2.
void flipM1(bool flip)
- Flip the direction meaning of the speed passed to the setSpeeds function for motor 1. The default direction corresponds to flipM1(false) having been called.
void flipM2(bool flip)
- Flip the direction meaning of the speed passed to the setSpeeds function for motor 2. The default direction corresponds to flipM2(false) having been called.
- 1.0.1 (2014-08-15): Fix pin initializations so the Arduino Due doesn’t drive the motors when the sketch starts.
- 1.0.0 (2014-08-15): Original release.