Hello ! I am having trouble with the SPI communication between my Arduino Uno and two L6470 Drivers (i have this version of it Getting Started with the AutoDriver - SparkFun Learn which is not the newest v13 version !)
I will post my code and setup below, and I think that the problem is probably with the code and the way i send data to the two drivers.
Basically, my 2 drivers are wired to the arduino which is programmed to make them go back and forth 1 time when receiving a trigger from a esp32 board.
I have a version of the code that only defines one driver which works fine, and when i upload this code everything behaves normally : the motor moves when the trigger from the esp32 is sent.
However, when i try to define a second driver in my code, nothing works anymore. For now the 2nd driver is not even being powered so i don't think it could be a power issue as well.
If anyone has any experience with these drivers or in SPI communication, it would be a great help. Thank you
Wiring :
MOSI (Master Out Slave In) for both drivers : pin11 Arduino
MISO (Master In Slave Out) for both drivers : pin12 Arduino
SCK (Serial Clock) for both drivers : pin 13 Arduino
CS (Chip Select) for driver 1: pin 10 Arduino
CS (Chip Select) for driver 2: pin 9 Arduino
RESET for driver 1: pin 8 Arduino
gpio13 on esp32 : pin 7 Arduino
RESET for driver 1: pin 6 Arduino
and of course 5v to 5v and ground to ground.
Here is the code that works and makes the motor move when triggered from the esp32 :
#include <SparkFunAutoDriver.h>
#include <SPI.h>
// Define constants for the motor rotation
#define MOTOR_STEPS 25600 // Steps per revolution for your motor
#define MAX_SPEED 2000 // Maximum speed
#define ACCEL 1000 // Acceleration
#define DECEL 1000 // Deceleration
const int triggerPin = 7; // Input from ESP32 to start the motor movement
AutoDriver boardA(0, 10, 8);
void setup()
{
Serial.begin(9600);
Serial.println("Hello world");
pinMode(8, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
digitalWrite(8, LOW);
digitalWrite(8, HIGH);
pinMode(triggerPin, INPUT);
SPI.begin();
SPI.setDataMode(SPI_MODE3);
boardA.resetDev();
boardA.setParam(MAX_SPEED, MAX_SPEED);
boardA.setParam(ACC, ACCEL); // Set acceleration
boardA.setParam(DECEL, DECEL); // Set deceleration
}
void loop()
{
int state = digitalRead(triggerPin);
Serial.print("State of trigger pin: "); // Add this line
Serial.println(state); // Prints the state of the triggerPin
if (state == HIGH) { // If trigger is received from ESP32
// 180 degree rotation
boardA.move(FWD, MOTOR_STEPS / 2);
while (boardA.getStatus() & 0x0002); // Wait for motor to stop
delay(500); // Wait for 1 second
// 180 degree rotation in opposite direction
boardA.move(REV, MOTOR_STEPS / 2); // Half the steps per revolution in opposite direction
while (boardA.getStatus() & 0x0002); // Wait for motor to stop
delay(500); // Wait for 1 second
}
}
And here is when i try to define the 2nd driver, and nothing works anymore :
#include <SparkFunAutoDriver.h>
#include <SPI.h>
// Define constants for the motor rotation
#define MOTOR_STEPS 25600 // Steps per revolution for your motor
#define MAX_SPEED 2000 // Maximum speed
#define ACCEL 1000 // Acceleration
#define DECEL 1000 // Deceleration
const int triggerPin = 7; // Input from ESP32 to start the motor movement
AutoDriver boardA(0, 10, 8);
AutoDriver boardB(1, 9, 6); // Added second motor driver with CS=9, RESET=6
void setup()
{
Serial.begin(9600);
Serial.println("Hello world");
pinMode(8, OUTPUT);
pinMode(6, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(6, LOW);
digitalWrite(8, HIGH);
digitalWrite(6, HIGH);
pinMode(triggerPin, INPUT);
SPI.begin();
SPI.setDataMode(SPI_MODE3);
boardA.resetDev();
boardA.setParam(MAX_SPEED, MAX_SPEED);
boardA.setParam(ACC, ACCEL); // Set acceleration
boardA.setParam(DECEL, DECEL); // Set deceleration
boardB.resetDev(); // Reset board B
boardB.setParam(MAX_SPEED, MAX_SPEED); // Set max speed for board B
boardB.setParam(ACC, ACCEL); // Set acceleration for board B
boardB.setParam(DECEL, DECEL); // Set deceleration for board B
}
void loop()
{
byte responseA = boardA.getParam(CONFIG);
Serial.print("Board A CONFIG Register: ");
Serial.println(responseA, HEX);
byte responseB = boardB.getParam(CONFIG);
Serial.print("Board B CONFIG Register: ");
Serial.println(responseB, HEX);
delay(1000);
int state = digitalRead(triggerPin);
Serial.print("State of trigger pin: ");
Serial.println(state); // Prints the state of the triggerPin
#
if (state == HIGH) { // If trigger is received from ESP32
// 180 degree rotation
boardA.move(FWD, MOTOR_STEPS / 2);
boardB.move(FWD, MOTOR_STEPS / 2); // Move board B in same way as board A
while (boardA.getStatus() & 0x0002 || boardB.getStatus() & 0x0002); // Wait for both motors to stop
delay(500); // Wait for 1 second
// 180 degree rotation in opposite direction
boardA.move(REV, MOTOR_STEPS / 2); // Half the steps per revolution in opposite direction
boardB.move(REV, MOTOR_STEPS / 2); // Move board B in same way as board A
while (boardA.getStatus() & 0x0002 || boardB.getStatus() & 0x0002); // Wait for both motors to stop
delay(500); // Wait for 1 second
}
}
Thank you in advance, any help is greatly appreciated !