Skip to content

Arduino/Platformio library for the DRV8833 motor driver. Supports i2c via PCA9685.

License

Notifications You must be signed in to change notification settings

madskjeldgaard/arduino-drv8833

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlatformIO Registry

DRV8833 Arduino Library

This library provides an interface for controlling the DRV8833 dual H-bridge motor driver chip using the Arduino framework. Each DRV8833 chip can drive two DC motors or one stepper motor. Albeit this currently is mostly written with DC motors in mind.

This library additionally supports using the motor driver in a popular setup where it is connected to a PCA9685 i2c chip to allow controlling it via i2c.

Works well with something like this Adafruit board but should also just work with any DRV8833 setup.

Features

  • Platformio library
  • Set the speed and direction of each motor either using integers or floats.
  • Set the decay mode of each H-bridge (fast or slow) to improve performance of brushed DC motors.
  • Put the DRV8833 to sleep to save power.
  • Supports chips connected via i2c (using the PCA9685 chip, like in this board for example)
  • Wake the DRV8833 from sleep.

Usage

Include the library in your Arduino sketch:

#include "DRV8833.h"

Create an instance of the DRV8833 class:

motor::DRV8833 motorDriver(in1, in2, in3, in4, sleep);

void setup() {
    motorDriver.begin();
}

Control a motor:

// 25% speed, forward
motorDriver.getBridgeA().setSpeed(0.25f, motor::Direction::Forward);

motorDriver.getBridgeA().start();

// 13% speed, backwards
motorDriver.getBridgeA().setSpeed(0.13f, motor::Direction::Backward);

Put the DRV8833 to sleep:

motorDriver.sleep();

Wake the DRV8833 from sleep:

motorDriver.wake();

Decay Modes

The decay mode affects the performance of the motor. Fast decay mode causes a rapid reduction in inductive current and allows the motor to coast toward zero velocity. Slow decay mode leads to a slower reduction in inductive current but produces rapid deceleration.

This Adafruit article has some nice info on performance and DC motors which explains the topic in depth.

It is also recommended to mess with lowering the PWM frequency of the board to improve performance:

constexpr auto PWM_FREQ = 100; // hz
analogWriteFreq(PWM_FREQ);

Installation

Platformio

Add the library to your lib_deps in platformio.ini

lib_deps = 
    # ... other libraries...

    # DRV8833 motor controller
    https://github.com/madskjeldgaard/arduino-drv8833

Arduino

Download the library and add it to your Arduino libraries folder.

You also need to manually download and install the PCA9685_RT library.

Contributing

All contributions are welcome. Please open an issue or a pull request if you have ideas to change this library for the better :)

License

This library is released under the MIT license.

About

Arduino/Platformio library for the DRV8833 motor driver. Supports i2c via PCA9685.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages