├── README.md ├── keywords.txt ├── DRV8833.h ├── examples ├── DRV8833_Test │ └── DRV8833_Test.ino ├── DRV8833_Test_2 │ └── DRV8833_Test_2.ino ├── DRV8833_Test_PWM_2 │ └── DRV8833_Test_PWM_2.ino └── DRV8833_Test_PWM │ └── DRV8833_Test_PWM.ino └── DRV8833.cpp /README.md: -------------------------------------------------------------------------------- 1 | # DRV8833 2 | A Arduino-based library for the Pololu DRV8833 dual motor driver carrier 3 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | DRV8833 KEYWORD1 2 | motorAReverse KEYWORD2 3 | motorAForward KEYWORD2 4 | motorAStop KEYWORD2 5 | motorBReverse KEYWORD2 6 | motorBForward KEYWORD2 7 | motorBStop KEYWORD2 8 | attachMotorA KEYWORD2 9 | attachMotorB KEYWORD2 10 | -------------------------------------------------------------------------------- /DRV8833.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833 - Library for the DRV8833 dual motor driver carrier. 3 | * The DRV8833 can be found here: https://www.pololu.com/product/2130 4 | * The DRV8833 data sheet can be found here: https://www.pololu.com/file/download/drv8833.pdf?file_id=0J534 5 | * 6 | * Library: DRV8833 7 | * File: DRV8833.h 8 | * 9 | * Describes the class for the library. 10 | * v1.0 11 | * 12 | * Created March 16, 2015, by Aleksandr J. Spackman. 13 | * 14 | * This code is not yet in the public domain. 15 | * 16 | */ 17 | 18 | #ifndef DRV8833_H 19 | #define DRV8833_H 20 | 21 | #include "Arduino.h" 22 | 23 | class DRV8833 24 | { 25 | public: 26 | // Constructor for the class: 27 | DRV8833(); 28 | 29 | // Motor control functions: 30 | void motorAReverse(); 31 | void motorAReverse(int speed); 32 | void motorAForward(); 33 | void motorAForward(int speed); 34 | void motorAStop(); 35 | 36 | void motorBReverse(); 37 | void motorBReverse(int speed); 38 | void motorBForward(); 39 | void motorBForward(int speed); 40 | void motorBStop(); 41 | 42 | // Functions to attach motors: 43 | void attachMotorA(int a1 /* Input pin A1 */, int a2 /* Input pin A2 */); 44 | void attachMotorB(int b1 /* Input pin B1 */, int b2 /* Input pin B2 */); 45 | 46 | private: 47 | // Fields for the class: 48 | int a1, a2, b1, b2; 49 | boolean motorAAttached = false; 50 | boolean motorBAttached = false; 51 | }; 52 | 53 | #endif // DRV8833_H 54 | -------------------------------------------------------------------------------- /examples/DRV8833_Test/DRV8833_Test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833_Test 3 | * Simple test for the DRV8833 library. 4 | * The DRV8833 is a dual motor driver carrier made by Pololu. 5 | * You can find it here: https://www.pololu.com/product/2130 6 | * 7 | * Attach the positive wire of a motor to the Aout1 and the negative 8 | * wire to the Aout2 pins on the DRV8833. 9 | * Attach the Arduino's ground to the one of the GND pins on the DRV8833. 10 | * Attach a 9V battery's positive connection to the Vin pin 11 | * on the DRV8833, and the negative connection to one of the GND pins. 12 | * 13 | * Created March 16, 2015, by Aleksandr J. Spackman. 14 | */ 15 | 16 | #include 17 | 18 | // Create an instance of the DRV8833: 19 | DRV8833 driver = DRV8833(); 20 | 21 | // Pin numbers. Replace with your own! 22 | // Attach the Arduino's pin numbers below to the 23 | // Ain1 and Ain2 DRV8833 pins. 24 | const int inputA1 = 9, inputA2 = 10; 25 | 26 | void setup() { 27 | // put your setup code here, to run once: 28 | 29 | // Start the serial port: 30 | Serial.begin(9600); 31 | 32 | // Wait for the serial port to connect. Needed for Leonardo. 33 | while (!Serial); 34 | 35 | // Attach a motor to the input pins: 36 | driver.attachMotorA(inputA1, inputA2); 37 | Serial.println("Ready!"); 38 | 39 | } 40 | 41 | void loop() { 42 | // put your main code here, to run repeatedly: 43 | 44 | Serial.println("Forward:"); 45 | // Put the motor in forward: 46 | driver.motorAForward(); 47 | // Wait to see the effect: 48 | delay(500); 49 | 50 | // Pause the motor for stability: 51 | driver.motorAStop(); 52 | 53 | Serial.println("Reverse:"); 54 | // Put the motor in reverse: 55 | driver.motorAReverse(); 56 | // Wait to see the effect: 57 | delay(500); 58 | 59 | Serial.println("Stop:"); 60 | // Stop the motor: 61 | driver.motorAStop(); 62 | // Wait to see the effect: 63 | delay(500); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /examples/DRV8833_Test_2/DRV8833_Test_2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833_Test_2 3 | * Two-motor test for the DRV8833 library. 4 | * The DRV8833 is a dual motor driver carrier made by Pololu. 5 | * You can find it here: https://www.pololu.com/product/2130 6 | * 7 | * Attach the positive wire of a motor to the Aout1 and the negative 8 | * wire to the Aout2 pins on the DRV8833. 9 | * Attach the positive wire of a motor to the Bout1 and the negative 10 | * wire to the Bout2 pins on the DRV8833. 11 | * Attach the Arduino's ground to the one of the GND pins on the DRV8833. 12 | * Attach a 9V battery's positive connection to the Vin pin 13 | * on the DRV8833, and the negative connection to one of the GND pins. 14 | * 15 | * Created March 31, 2015, by Aleksandr J. Spackman. 16 | */ 17 | 18 | #include 19 | 20 | // Create an instance of the DRV8833: 21 | DRV8833 driver = DRV8833(); 22 | 23 | // Pin numbers. Replace with your own! 24 | // Attach the Arduino's pin numbers below to the 25 | // Ain1, Ain2, Bin1, and Bin2 DRV8833 pins. 26 | const int inputA1 = 5, inputA2 = 6, inputB1 = 9, inputB2 = 10; 27 | 28 | void setup() { 29 | // put your setup code here, to run once: 30 | 31 | // Start the serial port: 32 | Serial.begin(9600); 33 | 34 | // Wait for the serial port to connect. Needed for Leonardo. 35 | while (!Serial); 36 | 37 | // Attach the motors to the input pins: 38 | driver.attachMotorA(inputA1, inputA2); 39 | driver.attachMotorB(inputB1, inputB2); 40 | Serial.println("Ready!"); 41 | 42 | } 43 | 44 | void loop() { 45 | // put your main code here, to run repeatedly: 46 | 47 | Serial.println("Forward:"); 48 | // Put the motors in forward: 49 | driver.motorAForward(); 50 | driver.motorBForward(); 51 | // Wait to see the effect: 52 | delay(500); 53 | 54 | // Pause the motors for stability: 55 | driver.motorAStop(); 56 | driver.motorBStop(); 57 | 58 | Serial.println("Reverse:"); 59 | // Put the motors in reverse: 60 | driver.motorAReverse(); 61 | driver.motorBReverse(); 62 | // Wait to see the effect: 63 | delay(500); 64 | 65 | Serial.println("Stop:"); 66 | // Stop the motors: 67 | driver.motorAStop(); 68 | driver.motorBStop(); 69 | // Wait to see the effect: 70 | delay(500); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /examples/DRV8833_Test_PWM_2/DRV8833_Test_PWM_2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833_Test_PWM_2 3 | * PWM (Pulse Width Modulation) test for the DRV8833 library. 4 | * The DRV8833 is a dual motor driver carrier made by Pololu. 5 | * You can find it here: https://www.pololu.com/product/2130 6 | * 7 | * Attach the positive wire of a motor to the Aout1 and the negative 8 | * wire to the Aout2 pins on the DRV8833. 9 | * Attach the positive wire of a motor to the Bout1 and the negative 10 | * wire to the Bout2 pins on the DRV8833. 11 | * Attach the Arduino's ground to the one of the GND pins on the DRV8833. 12 | * Attach a 9V battery's positive connection to the Vin pin 13 | * on the DRV8833, and the negative connection to one of the GND pins. 14 | * Attach the center pin of a potentiometer to analog 0, one side 15 | * pin to ground, and one side pin to +5V. 16 | * 17 | * Created March 31, 2015, by Aleksandr J. Spackman. 18 | */ 19 | 20 | #include 21 | 22 | // Create an instance of the DRV8833: 23 | DRV8833 driver = DRV8833(); 24 | 25 | // Pin numbers. Replace with your own! 26 | // For this example sketch, these pin numbers MUST be PWM. 27 | // Attach the Arduino's pin numbers below to the 28 | // Ain1, Ain2, Bin1, and Bin2 DRV8833 pins. 29 | const int inputA1 = 5, inputA2 = 6, inputB1 = 9, inputB2 = 10; 30 | 31 | // The speed of the motors: 32 | int motorSpeed = 0; 33 | 34 | // The potentiometer's pin: 35 | const int potPin = A0; 36 | 37 | void setup() { 38 | // put your setup code here, to run once: 39 | 40 | // Start the serial port: 41 | Serial.begin(9600); 42 | 43 | // Wait for the serial port to connect. Needed for Leonardo. 44 | while (!Serial); 45 | 46 | // Attach the motors to the input pins: 47 | driver.attachMotorA(inputA1, inputA2); 48 | driver.attachMotorB(inputB1, inputB2); 49 | Serial.println("Ready!"); 50 | 51 | } 52 | 53 | void loop() { 54 | // put your main code here, to run repeatedly: 55 | int reading = analogRead(potPin); 56 | 57 | motorSpeed = map(reading, 0, 1023, 0, 255); 58 | Serial.print(reading); 59 | Serial.print('\t'); 60 | Serial.println(motorSpeed); 61 | 62 | // Put the motors in forward using the speed: 63 | driver.motorAForward(motorSpeed); 64 | driver.motorBForward(motorSpeed); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /examples/DRV8833_Test_PWM/DRV8833_Test_PWM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833_Test_PWM 3 | * PWM (Pulse Width Modulation) test for the DRV8833 library. 4 | * The DRV8833 is a dual motor driver carrier made by Pololu. 5 | * You can find it here: https://www.pololu.com/product/2130 6 | * 7 | * Attach the positive wire of a motor to the Aout1 and the negative 8 | * wire to the Aout2 pins on the DRV8833. 9 | * Attach the positive wire of a motor to the Bout1 and the negative 10 | * wire to the Bout2 pins on the DRV8833. 11 | * Attach the Arduino's ground to the one of the GND pins on the DRV8833. 12 | * Attach a 9V battery's positive connection to the Vin pin 13 | * on the DRV8833, and the negative connection to one of the GND pins. 14 | * 15 | * Created March 31, 2015, by Aleksandr J. Spackman. 16 | */ 17 | 18 | #include 19 | 20 | // Create an instance of the DRV8833: 21 | DRV8833 driver = DRV8833(); 22 | 23 | // Pin numbers. Replace with your own! 24 | // For this example sketch, these pin numbers MUST be PWM. 25 | // Attach the Arduino's pin numbers below to the 26 | // Ain1, Ain2, Bin1, and Bin2 DRV8833 pins. 27 | const int inputA1 = 5, inputA2 = 6, inputB1 = 9, inputB2 = 10; 28 | 29 | // The speed of the motors: 30 | const int motorSpeed = 128; // Half speed (255 / 2). 31 | 32 | void setup() { 33 | // put your setup code here, to run once: 34 | 35 | // Start the serial port: 36 | Serial.begin(9600); 37 | 38 | // Wait for the serial port to connect. Needed for Leonardo. 39 | while (!Serial); 40 | 41 | // Attach the motors to the input pins: 42 | driver.attachMotorA(inputA1, inputA2); 43 | driver.attachMotorB(inputB1, inputB2); 44 | Serial.println("Ready!"); 45 | 46 | } 47 | 48 | void loop() { 49 | // put your main code here, to run repeatedly: 50 | 51 | Serial.println("Forward:"); 52 | // Put the motors in forward using the speed: 53 | driver.motorAForward(motorSpeed); 54 | driver.motorBForward(motorSpeed); 55 | // Wait to see the effect: 56 | delay(500); 57 | 58 | // Pause the motors for stability: 59 | driver.motorAStop(); 60 | driver.motorBStop(); 61 | 62 | Serial.println("Reverse:"); 63 | // Put the motors in reverse using the speed: 64 | driver.motorAReverse(motorSpeed); 65 | driver.motorBReverse(motorSpeed); 66 | // Wait to see the effect: 67 | delay(500); 68 | 69 | Serial.println("Stop:"); 70 | // Stop the motors: 71 | // You don't specify a speed for stop(). 72 | driver.motorAStop(); 73 | driver.motorBStop(); 74 | // Wait to see the effect: 75 | delay(500); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /DRV8833.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DRV8833 - Library for the DRV8833 dual motor driver carrier. 3 | * The DRV8833 can be found here: https://www.pololu.com/product/2130 4 | * The DRV8833 data sheet can be found here: https://www.pololu.com/file/download/drv8833.pdf?file_id=0J534 5 | * 6 | * Library: DRV8833 7 | * File: DRV8833.cpp 8 | * 9 | * Defines the class for the library. 10 | * v1.0 11 | * 12 | * Created March 16, 2015, by Aleksandr J. Spackman. 13 | * 14 | * This code is not yet in the public domain. 15 | * 16 | */ 17 | 18 | #include "Arduino.h" 19 | #include "DRV8833.h" 20 | 21 | DRV8833::DRV8833() 22 | { 23 | // Does nothing. 24 | // Use attachMotorA() and attachMotorB(). 25 | } 26 | 27 | void DRV8833::motorAReverse() 28 | { 29 | if (this->motorAAttached) // If motor A is attached... 30 | { 31 | // ...then put it in reverse. 32 | digitalWrite(this->a1, LOW); 33 | digitalWrite(this->a2, HIGH); 34 | } 35 | } 36 | 37 | void DRV8833::motorAReverse(int speed) 38 | { 39 | if (this->motorAAttached) // If motor A is attached... 40 | { 41 | // ...then put it in reverse. 42 | digitalWrite(this->a1, LOW); 43 | analogWrite(this->a2, speed); 44 | } 45 | } 46 | 47 | void DRV8833::motorAForward() 48 | { 49 | if (this->motorAAttached) // If motor A is attached... 50 | { 51 | // ...then put it in forward. 52 | digitalWrite(this->a1, HIGH); 53 | digitalWrite(this->a2, LOW); 54 | } 55 | } 56 | 57 | void DRV8833::motorAForward(int speed) 58 | { 59 | if (this->motorAAttached) // If motor A is attached... 60 | { 61 | // ...then put it in forward. 62 | analogWrite(this->a1, speed); 63 | digitalWrite(this->a2, LOW); 64 | } 65 | } 66 | 67 | void DRV8833::motorAStop() 68 | { 69 | if (this->motorAAttached) // If motor A is attached... 70 | { 71 | // ...then stop it. 72 | digitalWrite(this->a1, HIGH); 73 | digitalWrite(this->a2, HIGH); 74 | } 75 | } 76 | 77 | void DRV8833::motorBReverse() 78 | { 79 | if (this->motorBAttached) // If motor B is attached... 80 | { 81 | // ...then put it in reverse. 82 | digitalWrite(this->b1, LOW); 83 | digitalWrite(this->b2, HIGH); 84 | } 85 | } 86 | 87 | void DRV8833::motorBReverse(int speed) 88 | { 89 | if (this->motorBAttached) // If motor B is attached... 90 | { 91 | // ...then put it in reverse. 92 | digitalWrite(this->b1, LOW); 93 | analogWrite(this->b2, speed); 94 | } 95 | } 96 | 97 | void DRV8833::motorBForward() 98 | { 99 | if (this->motorBAttached) // If motor B is attached... 100 | { 101 | // ...then put it in forward. 102 | digitalWrite(this->b1, HIGH); 103 | digitalWrite(this->b2, LOW); 104 | } 105 | } 106 | 107 | void DRV8833::motorBForward(int speed) 108 | { 109 | if (this->motorBAttached) // If motor B is attached... 110 | { 111 | // ...then put it in forward. 112 | analogWrite(this->b1, speed); 113 | digitalWrite(this->b2, LOW); 114 | } 115 | } 116 | 117 | void DRV8833::motorBStop() 118 | { 119 | if (this->motorBAttached) // If motor B is attached... 120 | { 121 | // ...then stop it. 122 | digitalWrite(this->b1, HIGH); 123 | digitalWrite(this->b2, HIGH); 124 | } 125 | } 126 | 127 | void DRV8833::attachMotorA(int a1, int a2) 128 | { 129 | if (!this->motorAAttached) // If motor A is NOT attached... 130 | { 131 | // ...attach motor A to the input pins. 132 | pinMode(a1, OUTPUT); 133 | pinMode(a2, OUTPUT); 134 | this->a1 = a1; 135 | this->a2 = a2; 136 | 137 | // Show the motor is attached. 138 | this->motorAAttached = true; 139 | 140 | // Initialize as LOW. 141 | digitalWrite(this->a1, LOW); 142 | digitalWrite(this->a2, LOW); 143 | } 144 | } 145 | 146 | void DRV8833::attachMotorB(int b1, int b2) 147 | { 148 | if (!this->motorBAttached) // If motor B is NOT attached... 149 | { 150 | // ...attach motor A to the input pins. 151 | pinMode(b1, OUTPUT); 152 | pinMode(b2, OUTPUT); 153 | this->b1 = b1; 154 | this->b2 = b2; 155 | 156 | // Show the motor is attached. 157 | this->motorBAttached = true; 158 | 159 | // Initialize as LOW. 160 | digitalWrite(this->b1, LOW); 161 | digitalWrite(this->b2, LOW); 162 | } 163 | } 164 | --------------------------------------------------------------------------------