Attempting to use a4988 carrier with shift register

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);
}

Hello,

I do not know of anyone using the A4988 with a shift register, and I am not sure controlling the steps of your motors with a shift register will be practical. I suggest you try to simplify this first. For example, can you get one stepper motor and stepper motor driver working without the shift register? Can you get the shift register to do what you expect by itself (i.e. no stepper motor driver in the system)?

-Brandon

Probably a hair brain idea. I am currently backing up and trying to make sure I get what I want from the shift register and the a4988 by themselves. I’m doing ok with the shift register right now (only one so far until I know what i’m doing) controlling five pins for step, direction and the three m pins. Not sure I have a good handle on the stepper driver yet though. I can get the sample code to work fine, but if I deviate from that (adding buttons to control step and direction) things get flakey. Just need to stay with it until I know what i’m missing.

Another thought I had was to pair the 3988 with an ATTiny for each stepper and communicate via i2c. I have done some of that on earlier projects, just not with a stepper controller. The Attiny85 has three useable lines after you take away Vcc, gnd and the two control lines (I haven’t tried repurposing the reset yet). That might work as well.

I will keep plugging and post here.

Charlie

As I stated in my previous post, it might be impractical to control the step pins with a shift register since you potentially want high-frequency pulse trains on those pins. It might be alright to control the direction and microstep selection pins with your shift registers.

If you run into trouble, please post the simplest complete program that demonstrates the issue, and I would be happy to take a look and see if I can help.

-Brandon