High Power Stepper Motor Driver and Due

Is the High-Power Stepper Motor Driver 36v4 compatible with the Arduino Due? Following the wiring and Basic Stepping example code in the Pololu library the stepper motor is unresponsive. I have tried the same wiring setup and code on a mega 2560 and it works fine, but no luck on the Due. I’ve changed the code to reflect the DUE advanced SPI call (SPI.begin vs SPI.begin(4)) and have accounted for different voltages in the board setup. Using same power supply, stepper motor and motor driver with both tests. Same connections to SPI bus and cs, step and direction pins on both boards. Confirmed correct voltage is found on motor driver. Any suggestions?

Hello.

We have not tried using the High-Power Stepper Motor Driver 36v4 with an Arduino Due, but I do not see a reason why they would not work together. Can you post your modified code that you’re trying to run on your Arduino? Also, can you post a wiring diagram or pictures showing how everything is connected in your system, especially pictures showing the connections between the stepper motor driver and the Arduino?

- Amanda

Amanda-

Here’s the Due setup that doesn’t work:

Here’s the wiring:

Here’s a detail of diver board connections:

Here’s the same driver board used on a mega:

And here’s the code (minor addition of using internal led).

Code was taken from github samples. (Basic test)

#include <SPI.h>
#include <HighPowerStepperDriver.h>

const uint8_t DirPin = 2;
const uint8_t StepPin = 3;
const uint8_t CSPin = 4;

bool lightOn = 0;

HighPowerStepperDriver sd;

void setup()
{
Serial.begin(9600);

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

SPI.begin(); // THIS IS FOR MEGA
// SPI.begin(CSPin); // THIS IS FOR DUE
sd.setChipSelectPin(CSPin);

pinMode(StepPin, OUTPUT);
digitalWrite(StepPin, LOW);
pinMode(DirPin, OUTPUT);
digitalWrite(DirPin, LOW);

delay(10);

sd.resetSettings();
sd.clearStatus();
sd.setDecayMode(HPSDDecayMode::AutoMixed);
sd.setCurrentMilliamps36v4(2000);
sd.setStepMode(HPSDStepMode::MicroStep32);
sd.enableDriver();
}

void loop()
{
if (lightOn == 0)
{
digitalWrite(LED_BUILTIN, HIGH);
lightOn = 1;
} else
{
digitalWrite(LED_BUILTIN, LOW);
lightOn = 0;
}

setDirection(0);
for(unsigned int x = 0; x < 1000; x++)
{
step();
delayMicroseconds(StepPeriodUs);
}

delay(300);

setDirection(1);
for(unsigned int x = 0; x < 1000; x++)
{
step();
delayMicroseconds(StepPeriodUs);
}

delay(300);
}

void step()
{
digitalWrite(StepPin, HIGH);
delayMicroseconds(3);
digitalWrite(StepPin, LOW);
delayMicroseconds(3);
}

void setDirection(bool dir)
{
delayMicroseconds(1);
digitalWrite(DirPin, dir);
delayMicroseconds(1);
}

Thanks for your help!

I added code tags to your code so that it looks clean and easy to read.

It looks like you swapped your MISO and SCK connections on your Arduino Due. (Also, your MISO connection in your Arduino Mega setup looks wrong.) Other than the SPI connections being incorrect, the rest of your connections and code look fine. Can you fix those connections and try running your code again to see if that fixes the issue?

- Amanda

Yes, my mistake, the SPI connections were wrong on both. I fixed and retested with same results- Mega OK, Due nothing. I’m looking at the driver code and wondering if the SPI.beginTransaction() code on line 105 may need to be changed for the Due extended SPI code as it uses a chip select in the call- beginTransaction(pin, SPISettings settings).

From our understanding, specifying the CS in SPI.beginTransaction() is optional and the function should work without doing that for the Arduino Due. Can you try using SPI.begin(), not SPI.begin(CSPin), for the Arduino Due and see if that changes anything?

- Amanda

Yes, that solved the problem. The stepper is now working. Interestingly, the amount of rotation on the shaft is much less than the mega. 40 degrees on the Due vs 4 full rotations on the Mega.

Great! The SPI.begin(CSPin) probably was interfering with the library’s software control of CS when assigning control of the CS pin to the Due’s SPI peripheral.

It’s not clear why you’re getting different rotations between the Arduino Mega and Arduino Due setups. I noticed StepPeriodUs is not defined in your code. What did you set StepPeriodUs to?

- Amanda