Hi there,
the connections are working properly I checked them multiple times and each driver works on its own when it’s the only one connected. With the code below, no driver moves at all and both motors don’t even have power. I use the slave select only for the SPI commands provided with the example, the DIR pin should be independent of the slave select right?
-Noa
#include <SPI.h>
#include <AMIS30543.h>
const uint8_t motor1step = 49; const uint8_t motor1dir = 48; const uint8_t motor1 = 47; int Lichtschranke1 = 46; const uint8_t motor2step = 45; const uint8_t motor2dir = 44; const uint8_t motor2 = 43; int Lichtschranke2 = 42; int ssPin;
AMIS30543 stepper;
void setup() { SPI.begin(); SPI.setDataMode(SPI_MODE0);
// stepper.init pinMode(motor1, OUTPUT); digitalWrite(motor1, HIGH);
pinMode(motor2, OUTPUT); digitalWrite(motor2, HIGH);
// Drive the NXT/STEP and DIR pins low initially.
digitalWrite(motor1step, LOW); pinMode(motor1step, OUTPUT); digitalWrite(motor1dir, LOW); pinMode(motor1dir, OUTPUT);
digitalWrite(motor2step, LOW); pinMode(motor2step, OUTPUT); digitalWrite(motor2dir, LOW); pinMode(motor2dir, OUTPUT);
pinMode(Lichtschranke1, INPUT); pinMode(Lichtschranke2, INPUT);
// Give the driver some time to power up. delay(1);
select(motor1); // Reset the driver to its default settings. stepper.resetSettings();
// Set the current limit. You should change the number here to // an appropriate value for your particular system. stepper.setCurrentMilliamps(500);
// Set the number of microsteps that correspond to one full step. stepper.setStepMode(16);
// Enable the motor outputs. stepper.enableDriver(); deselect(motor1);
select(motor2); stepper.resetSettings(); stepper.setCurrentMilliamps(500); stepper.setStepMode(16); stepper.enableDriver(); deselect(motor2);
Serial.begin(9600); setDirection2(0); setDirection1(0); }
void loop() { if (digitalRead(Lichtschranke2)==LOW){ step2(100); }
if (digitalRead(Lichtschranke1)==LOW){ step1(500); } }
void step1(int velocity) { digitalWrite(motor1step, HIGH); delayMicroseconds(3); digitalWrite(motor1step, LOW); delayMicroseconds(3); delayMicroseconds(velocity); }
void step2(int velocity) { digitalWrite(motor2step, HIGH); delayMicroseconds(3); digitalWrite(motor2step, LOW); delayMicroseconds(3); delayMicroseconds(velocity); }
void setDirection1(bool dir) { delayMicroseconds(1); digitalWrite(motor1dir, dir); delayMicroseconds(1); }
void setDirection2(bool dir) { delayMicroseconds(1); digitalWrite(motor2dir, dir); delayMicroseconds(1); }
void select(int motorselect) { ssPin=motorselect; digitalWrite(motorselect, LOW); }
void deselect(int motorselect) { digitalWrite(motorselect, HIGH); delayMicroseconds(3); }