Controlling multiple stepper with SPI


#1

Hi there,

I am trying to control the stepper motors from Arduino. So far, I have been able to do control 1 stepper at the time with this guide from Roboteurs. But i don’t know how to control stepper motors more than one. I think we can declare more motor on Arduino code, but in SlushEngine how can i know the pin for Motor 1, 2, 3, 4, 5? Do I have to specify it in Arduino code?

Thanks in advance,
Tulga


#2

Hi Tulga,

The Arduino code should look something like this,

#include <SPI.h>
#include <L6470.h>

// Motors
L6470 Motor1(10)
L6470 Motor2(9)
L6470 Motor3(6)
L6470 Motor4(5)

void setup() {
	Serial.begin(9600)
	
	// Initialise 4 stepper motors
	Motor1.init()
	Motor2.init()
	Motor3.init()
	Motor4.init()
	
	// Acceleration for each motors
	Motor1.setAcc(100)
	Motor2.setAcc(200)
	Motor3.setAcc(300)
	Motor4.setAcc(400)
	
	// Etc.
}

I’m not familiar with Arduino, but you have to specify four slaves (SS), see Serial Peripheral Interface (SPI).

Once four slaves (SS) have been setup, you will then need to connect this to the SlushEngine pins, as highlighted in red (STP0_CS, STP1_CS, STP2_CS, STP3_CS)

This should be able to help you out, in defining multiple CS pins. https://www.bluedot.space/tutorials/connect-multiple-bme280-on-spi/