Hello, Ben and Dave.
In case it helps, I wrote an Arduino sketch that uses our library for the 36v4 to control two drivers. Unfortunately though, I am not able to verify it works myself because I am working from home due to the COVID-19 outbreak, and I do not have the required equipment with me. With that in mind, be cautious testing this example for the first time (e.g. use a low supply voltage, monitor motor temps carefully and be ready to disconnect power, etc.), and please let me know if you come across any problems with it.
Also, always check the current limits in the sketch. My code and the examples in our library set the current limit to 1A to avoid burning up the driver, but that could still potentially damage smaller stepper motors.
By the way, before trying to control two drivers, I recommend using our example in the library to confirm that each of your drivers and motors works individually if possible.
// This example shows basic use of two Pololu High Power Stepper Motor Drivers
// using the Arduino library for the Pololu High-Power Stepper Motor Driver.
//
// It shows how to initialize the drivers, configure various settings, and enable
// the drivers. It shows how to send pulses to the STEP pins to step the motors
// and how to switch directions using the DIR pins.
//
// Before using this example, be sure to change the setCurrentMilliamps36v4 lines
// to have an appropriate current limit for your system. Also, see this
// library's documentation for information about how to connect the driver:
// http://pololu.github.io/high-power-stepper-driver
#include <SPI.h>
#include <HighPowerStepperDriver.h>
// Driver 1 pins
const uint8_t sd1DirPin = 2;
const uint8_t sd1StepPin = 3;
const uint8_t sd1CSPin = 4;
// Driver 2 pins
const uint8_t sd2DirPin = 5;
const uint8_t sd2StepPin = 6;
const uint8_t sd2CSPin = 7;
// This period is the length of the delay between steps, which controls the
// stepper motor's speed. You can increase the delay to make the stepper motor
// go slower. If you decrease the delay, the stepper motor will go faster, but
// there is a limit to how fast it can go before it starts missing steps.
const uint16_t StepPeriodUs = 2000;
// Driver 1 object
HighPowerStepperDriver sd1;
// Driver 2 object
HighPowerStepperDriver sd2;
void setup()
{
SPI.begin();
sd1.setChipSelectPin(sd1CSPin);
sd2.setChipSelectPin(sd2CSPin);
// Drive the STEP and DIR pins low initially.
pinMode(sd1StepPin, OUTPUT);
digitalWrite(sd1StepPin, LOW);
pinMode(sd1DirPin, OUTPUT);
digitalWrite(sd1DirPin, LOW);
pinMode(sd2StepPin, OUTPUT);
digitalWrite(sd2StepPin, LOW);
pinMode(sd2DirPin, OUTPUT);
digitalWrite(sd2DirPin, LOW);
// Give the drivers some time to power up.
delay(1);
// Reset the drivers to their default settings and clear latched
// status conditions.
sd1.resetSettings();
sd1.clearStatus();
sd2.resetSettings();
sd2.clearStatus();
// Select auto mixed decay. TI's DRV8711 documentation recommends this mode
// for most applications, and we find that it usually works well.
sd1.setDecayMode(HPSDDecayMode::AutoMixed);
sd2.setDecayMode(HPSDDecayMode::AutoMixed);
// Set the current limit. You should change the number here to an appropriate
// value for your particular system.
sd1.setCurrentMilliamps36v4(1000);
sd2.setCurrentMilliamps36v4(1000);
// Set the number of microsteps that correspond to one full step.
sd1.setStepMode(HPSDStepMode::MicroStep32);
sd2.setStepMode(HPSDStepMode::MicroStep32);
// Enable the motor outputs.
sd1.enableDriver();
sd2.enableDriver();
}
void loop()
{
// Step motor 1 in the default direction 1000 times.
sd1SetDirection(0);
for(unsigned int x = 0; x < 1000; x++)
{
sd1Step();
delayMicroseconds(StepPeriodUs);
}
// Wait for 300 ms.
delay(300);
// Step motor 1 in the other direction 1000 times.
sd1SetDirection(1);
for(unsigned int x = 0; x < 1000; x++)
{
sd1Step();
delayMicroseconds(StepPeriodUs);
}
// Wait for 300 ms.
delay(300);
// Step motor 2 in the default direction 1000 times.
sd2SetDirection(0);
for(unsigned int x = 0; x < 1000; x++)
{
sd2Step();
delayMicroseconds(StepPeriodUs);
}
// Wait for 300 ms.
delay(300);
// Step motor 2 in the other direction 1000 times.
sd2SetDirection(1);
for(unsigned int x = 0; x < 1000; x++)
{
sd2Step();
delayMicroseconds(StepPeriodUs);
}
// Wait for 300 ms.
delay(300);
}
// Sends a pulse on the driver 1 STEP pin to tell the driver to take one
// step.
void sd1Step()
{
// The STEP minimum high pulse width is 1.9 microseconds.
digitalWrite(sd1StepPin, HIGH);
delayMicroseconds(3);
digitalWrite(sd1StepPin, LOW);
delayMicroseconds(3);
}
// Writes a high or low value to the driver 1 direction pin to specify what
// direction to turn motor 1.
void sd1SetDirection(bool dir)
{
// The STEP pin must not change for at least 200 nanoseconds before and after
// changing the DIR pin.
delayMicroseconds(1);
digitalWrite(sd1DirPin, dir);
delayMicroseconds(1);
}
// Sends a pulse on the driver 2 STEP pin to tell the driver to take one
// step.
void sd2Step()
{
// The STEP minimum high pulse width is 1.9 microseconds.
digitalWrite(sd2StepPin, HIGH);
delayMicroseconds(3);
digitalWrite(sd2StepPin, LOW);
delayMicroseconds(3);
}
// Writes a high or low value to the driver 2 direction pin to specify what
// direction to turn motor 2.
void sd2SetDirection(bool dir)
{
// The STEP pin must not change for at least 200 nanoseconds before and after
// changing the DIR pin.
delayMicroseconds(1);
digitalWrite(sd2DirPin, dir);
delayMicroseconds(1);
}
BasicSteppingWith2Motors.ino (4.8 KB)
Update: I was able to confirm this program works in a setup with an Arduino Uno wired according to the table in Dave_c’s second post.
- Patrick