Has anyone tried to use the A4988 carrier board through a shift register (595)? I have three steppers, each with two limit switches to control through a Arduino Min Pro so I need to reduced the number of required pens. So far, my attempts have not even been close. I’ve included my code, although I think it is probably laughable.
int dirpin = 2;
int steppin = 3;
int vPin = 6; // button for full step
int vPinslow=7; // button for quarter step
int dir = 0; // 0=down,left, 1=up,right
int SER_Pin = 8; //pin 14 on the 75HC595
int RCLK_Pin = 9; //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595
int sr_disablePin = 32;
int sr_DirPin = 16;
int sr_StepPin = 8;
int sr_M3Pin = 4;
int sr_M2Pin = 2;
int sr_M1Pin = 1;
int fullStep=0;
int halfStep=sr_M1Pin;
int quarterStep=sr_M2Pin;
int eightStep = sr_M1Pin + sr_M2Pin;
int SixteenthStep = sr_M1Pin + sr_M2Pin + sr_M3Pin;
byte registerData=0;
int b;
int bslow;
void setup()
{
Serial.begin(9600);
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
pinMode(vPin, INPUT);
pinMode(vPinslow,INPUT);
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
//reset all register pins
clearRegisters();
writeRegisters();
}
void loop()
{
b=digitalRead(vPin);
bslow=digitalRead(vPinslow);
if (b == 1) // button produce a full step
{
Serial.println(b);
setMotor(sr_DirPin + sr_StepPin,0);
}
if (bslow == 1) // button to produce a quarter step
{
Serial.println(bslow);
setMotor(quarterStep+sr_DirPin + sr_StepPin,0);
}
}
void setMotor(byte m1,byte m2) // m2 will be use when I can get m1 to work
{
clearRegisters();
writeRegisters();
int i;
if (m2 > 0)
for (i=0;i<=7;i++)
bitWrite(registerData,i,bitRead(m2,i));
for (i=0;i<=7;i++)
bitWrite(registerData,i,bitRead(m1,i));
writeRegisters();
delayMicroseconds(1000);
}
void clearRegisters()
{
Serial.println("clearRegister");
registerData = 0;
//for(int i = numOfRegisterPins - 1; i >= 0; i--){
// registers[i] = LOW;
}
void writeRegisters(){
Serial.println("writeRegister");
digitalWrite(RCLK_Pin, LOW);
// only using the first five bits from the s/r
for(int i = 4; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = bitRead(registerData,i);
Serial.println(val);
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}