# Building an I2C controllable stepper driver board with DRV8825 breakout boards and ATMega328p

23 May 2019 - tsp

The following is the description of a small breakout board for two DRV8825 stepper driver breakout boards (they are commonly used in 3D printers, hobby CNC mills, etc.) which can control bipolar stepper motors. The driver operats with a motor voltage between $8.2\text{V}$ and $45\text{V}$ and can deliver up to $1.5\text{A}$ per phase without a heat sink or active cooling as well as up to $2.2\text{A}$ with heatsink.

Since the driver requires a complex 4 layer PCB it’s easy for the hobbyist to use an existing breakout board like the Pololu DRV8825 stepper motor driver. Note while assembling that heatsinks should not be attached to the top of the chip which as an exposed thermal pad on the lower side. This thermal pad is connected via a bunch of thermal vias to the backside of the PCB to an large thermal pad - which is the location where one should attach a heatsink. So the heatsink goes on the opposite side of the PCB than the chip! These breakout boards are readily available (for example - note this is an affilate link and this pages author profits from orders - Amazon).

The main task of the driver board is to implement the previously presented linear stepper control algorithm with some additional commands (like accelerating form the current speed to a target speed, running at constant speed, etc.). The derivation for these equations is similar to the previously presented ones but with $v_0 \neq 0$.

## Schematic and design decisions

The board has been designed to include mostly DIP components for more complex elements - since the DRV8825 carriers are already DIP and an SOIC package is way harder to solder for beginners who don’t use an reflow oven. Some components like Tantal capacitors have been choosen to be SMD though to get a more compact board and since they are easy to solder (nothing smaller than 0805 has been used) that shouldn’t pose a problem.

It’s a basic minimalistic AVR circuit that get’s powered by it’s own MIC5205 regulator at 5V (3.3V would also have been possible - one just has to replace the regulator with the 3.3V version - the logic level is sufficient for the DRV8825 but the board looses the compatibility for 5V I2C - using an 5V AVR the board can be used with 3.3V and 5V I2C masters. This is possible because it doesn’t include any pullup’s itself - the AVR only pulls the logic level down during conversations).

Since the maximum power dissipation is $455\text{mW}$ and the AVR is run under absolute maximum conditions with an voltage of $5\text{V}$ and a maximum current of $200\text{mA}$ the input voltage should (because of thermal reasons) not exceed $7.185\text{V}$. Since the AVR is not used under that conditions but the maximum current can be assumed to be approximately the active core current ($12\text{mA}$) but nearly no current on the I/O pins since they are all CMOS inputs with nanoampere leakage currents the one can assume that the current supplied by the regulator stays well below $15\text{mA}$ which leads to a maximum input voltage (thermally) of $30.28\text{V}$. Since the MIC5205 can operate at up to $20\text{V}$ one should be able to use the full voltage range from about $5.5\text{V}$ up to $20\text{V}$ for the logic supply. If steppers are operated also below $20\text{V}$ one can use the jumper JP2 to supply logic power via the motor voltage and not via a separate power supply.

The usage of the LED D2 is of course optional as well as the usage of the ICSP connector J5 (one can program the AVR externally or use pogo pins on the pads).

All permanent connections (except the jumper) are assumed to be realized with standard screw terminals that fit into an $2.54\text{mm}$ grid. If one doesn’t expect any vibrations one can of course substitute them with standard pin headers.

The I2C conenctor has been decided to supply the standard SDA (Pin 1) and SCL (Pin 2) pins as well as Ground (Pin 3) and a reset pin (Pin 4) that can be used to reset the device by pulling the pin low. Internally the reset pin contains a $10\text{k}\Omega$ pullup. The Reset pin can be used to reset all stepper drivers on the I2C bus which can be useful when using an I2C bootloader that allows firmware upgrade via the I2C bus.

The configuration pins (M0-M2 for microstepping selection, Enable, Reset and Sleep) are shared between the two DRV8825 boards - so both have to be active at the same time and both have to use the same microstepping settings. Step and Direction are of course not shared as well as the Fault outputs that signal overcurrent or thermal shutdown of the drivers.

Both DRV8825 have an additional external $100\mu\text{F}$ capacitor as required by the driver chip itself to provide the required damping of high requency response of the motor coil system.

### Pin Mapping

Direction (Channel 1) 2 PD2 Out
Step (Channel 1) 3 PD3 Out
Fault (Channel 1) 16 PC2 In PCINT10 (PCI1)
Direction (Channel 2) 14 PC0 Out
Step (Channel 2) 15 PC1 Out
Fault (Channel 2) 17 PC3 In PCINT11 (PCI1)
Sleep 4 PD4 Out
Reset 5 PD5 Out
Mode 2 6 PD6 Out
Mode 1 7 PD7 Out
Mode 0 8 PB0 Out
Enable 9 PB1 Out
I2C SDA 27 PC4/SDA I/O
I2C SCL 28 PC5/SCL In

## Board layout

The (Version 1) board layout can be seen below. The bottom side has been filled by copper fill as usual.

All board layout files can be found on GitHub.

## Software

The motion control algorithm is implemented inside the AVR. It can be found on GitHub as well. For the other side of the control system the author has used an RaspberryPi (note: Amazon affilate link - the author profits from purchases) running FreeBSD. The software used can also be seen on GitHub inside the controller subdirectory. Some examples can be seen inside the tests directory.

A description of the I2C communication between AVR and the Raspberry Pi has been done in a previous blog post

## Photos and testing of the basic functionality (Update (2019-07-10))

First the design has been tested (because components had been available) using a breadboard, some wire, two DRV8825 boards and an Arduino ProMini. This setup can be seen in the following images.

Logic power supply and 12V power supply for stepper drivers had been provided via different power supplies, the AVR has been programmed via the Arduino bootloader over the serial port using avrdude using the same (non-Arduino) firmware as with the final version.

The final board has been designed as described above with plenty of space to allow easy hand soldering of all components. Manufacturing has been done by PCBWay with which I’ve been really satisfied (delivery totally in the projected time range, the price nearly unbeatable for small hobby boards without any fancy features, high quality and they’ve had no problems using the Gerber files created with KiCad)

On the final board initial programming is done using the 6 pin ICSP connector on the top left of the board. Note that this board uses 5V logic when choosing your adapter.

This board has two different power supply options that can be choosen with the jumper that can be seen besides the two DRV8825 boards. If the jumper is in place logic and stepper drivers are powered via the common (up to 20V) power supply via the 10 pin screw connector. If the jumper is not in place the logic supply can be done via the additional two pin 3.54mm pin header on the lower left. In both cases the power supply is connected to the MIC5205 which limits the supply voltage to a absolute maximum of 20V.

A last thing one should be aware of: One can use 3.3V I2C masters to control these boards even though they are using 5V logic supply internally - because pullups for the I2C bus have to be done on the master side and are not done on this board - and I2C is driven via open collector outputs. If one wants to use the I2C bootloader to upload new firmware though one has to use the fourth pin available on the I2C screw terminal - the RST pin. This pin has to be pulled to low to perform a reset of the microcontroller. Since the reset pin is active low it’s pulled to Vcc (i.e. 5V) during normal operation. The output that drives this pin low has to be 5V tolerant.