Announce: Stepper library for DRV8834 / A4988 etc

I wrote a library for the stepper driver boards from Pololu. Using these boards is so easy it almost doesn’t warrant a library for it, but in the end the code is cleaner with one, as one doesn’t have to do timing calculations and setup as you can see below. I only tested it with DRV8834 which I have, but I added A4988 and DRV8825 from on their datasheets so it should work with those as well.

Main page: github.com/laurb9/StepperDriver
Download library: github.com/laurb9/StepperDriver … master.zip

Using it is very simple. This example moves the stepper like the seconds hand of a watch forever. It keeps the motor engaged so it’s only for demo.

#include <Arduino.h>
#include "DRV8834.h"

#define MOTOR_STEPS 200
#define DIR 8
#define STEP 9
#define M0 10
#define M1 11
DRV8834 stepper(MOTOR_STEPS, DIR, STEP, M0, M1);

/*
 * The easy way, albeit not best, is just tell the motor to rotate 360 degrees at 1rpm
 */

void setup() {
    stepper.setRPM(1); 
    stepper.setMicrostep(1); // make sure we are in full speed mode
}

void loop() {
    stepper.rotate(360);
}

Please feel free to move to appropriate forum if not this one.

Hello.

Thank you for sharing! The driver interfaces are very simple, but we do hear from people asking for a library or sample code for them. We will consider adding your library as a resource on our stepper motor driver product pages.

-Jon

Hello, laurb9.

When reviewing your library, I noticed you are recommending adding a pull-down resistor to the DRV8834’s M0 pin. Why is that? It seems like adding the resistor would make it so you cannot get into the 1/4 and 1/32 microstep modes, which require M0 to be high impedance, but are you saying adding the resistor actually makes those microstepping modes possible?

Ryan

Hmm. The Arduino Uno clone I developed on needed that weak 470K pull-down to make it work. On the Pro Mini I am now on it worked with or without it. I suspected there’s a weak divider in the driver to set a “high-impedance” state voltage, and that voltage is sometimes thrown off by the input impedance of the pin.

[quote=“ryantm”]Hello, laurb9.

When reviewing your library, I noticed you are recommending adding a pull-down resistor to the DRV8834’s M0 pin. Why is that? It seems like adding the resistor would make it so you cannot get into the 1/4 and 1/32 microstep modes, which require M0 to be high impedance, but are you saying adding the resistor actually makes those microstepping modes possible?

Ryan[/quote]

What clone were you using? If you use the 470K pull-down on M0 with the Pro Mini, are you able to get into the 1/4 or 1/32 microstepping modes?

Ryan

I was using the UNO R3 clone in the left pic at the bottom: github.com/laurb9/tiny_scope/bl … /README.md

The Pro Mini works fine with the pull-down, or without it (I just moved all the wiring to it at some point and did not check to see if it still needed it).

[quote=“ryantm”]What clone were you using? If you use the 470K pull-down on M0 with the Pro Mini, are you able to get into the 1/4 or 1/32 microstepping modes?

Ryan[/quote]

I think I have another theory. Setting the pin to INPUT is not sufficient to go high impedance if the previous state was HIGH, because of some pull-up that was left enabled. If this is true, I can fix it in the code without needing an external resistor. I’ll play a bit more later.

[quote=“ryantm”]What clone were you using? If you use the 470K pull-down on M0 with the Pro Mini, are you able to get into the 1/4 or 1/32 microstepping modes?

Ryan[/quote]

Hi laurb9,

Thanks for sharing, this is a very useful library. Is there a way of setting the stepper rpm as a fraction? I have it set to 1.2 in my code and it seems to round down the rpm to 1.
Thanks
Sley

The rpm is indeed defined as an integer so any value you give will be converted to that. Making it a float might work but would increase code size and make it slower on common 8-bit Arduinos.

I am curious, what use case needs this precision control at such low speeds ?

I am building a low cost arduino based syringe pump for our chemistry lab at college. It requires 0.1 rpm increments inorder to achieve the precision needed to match commecial units…