Reading values off of 74hc595

I'm creating a library that lets me control 2 steppers using a shift register (using 74hc595). I have everything working except one issue. When I switch between stepper motors, the register values controlling the other stepper are getting overwritten.
I created a bit of code that I'd like to read the current register values from the register and write them to the register variable before starting the step function so that I don't lose the holding power on the motor I'm not stepping. Below is the code I have - which compiles, but doesn't appear to be initializing the registers boolean array as expected.
I've found plenty of example code on how to write to the registers - but can't seem to find code on the way to read the current register values off the chip, and would appreciate some pointers. My current understanding is that I want to set the RCLK pin high, as I'm not trying to change values on the register, then I want to cycle through the byte setting the clock low, read the serial pin, then set the clock high to advance to the next character?

void StepperH::readRegisters(){
//Sets registers variable to current value on register

  digitalWrite(this->RCLK_Pin, HIGH);
  for(int i = this->numOfRegisterPins - 1; i >=  0; i--){
	digitalWrite(this->SRCLK_Pin, LOW);
	digitalWrite(this->SRCLK_Pin, HIGH);

Why read it back in? You know what you wrote out, yes?

Just keep track of the outputs in two variables.

I use SPI.transfer() to send data to shift registers:

digitalWrite (latchPin, LOW);
SPI.transfer (shifter1);
SPI.transfer (shifter2);
digitalWrite (latchPin, HiGH); // both devices update their outputs on this rising edge

If you want to change one shift registrer and not the other, just send the same data to it again. The outputs will not change if you send it the same data.

You know that arduino pretty much directly supports shift registers with library functions named shiftIn() and shiftOut()?

Oh incidentally, you don’t need this->foo to access class variables inside class methods. foo by itself does the job.

I think I’ve come to the conclusion that you can’t read the current pin values on the register of a 74hc595 chip - as far as I can tell it’s an output register only. I’ve tried using shiftIn() to read the register values and it seems to set all of the pins to either all 1s or all 0s.
I did have a legit reason for not knowing the values of the registers. In my library I had it setup so you would call the arduino pins, and then specify the 4 pins on the register to control the stepper. So I’d have 2 stepper objects, e.g.

StepperH myStepper(200, 8, 9, 10, 0, 1, 2, 3); //200 steps per rev, pins 8,9,10 for Arduino to H Bridge, HBridge pins 0,1,2,3


StepperH myStepper2(2048, 8, 9, 10, 4, 5, 6, 7); //2048 steps per rev, pins 8,9,10 for Arduino to H Bridge, HBridge pins 4,5,6,7

Library initialization:

StepperH::StepperH(int number_of_steps, int SER_Pin, int RCLK_Pin, int SRCLK_Pin, int motor_pin_1, int motor_pin_2,
                                      int motor_pin_3, int motor_pin_4)

Since the registers boolean array that controls the state of the HBridge pins 0 through 7 exist in separate class objects I was looking for a means of reading the current pin values off the HBridge prior to initiating steps as the registers array is initialized differently for the two different stepper objects ‘myStepper’ and ‘myStepper2’.

If anyone knows for sure if it is or isn’t possible to read the current pin values on the 74HC595 chip, I’d be interested in learning how - but I haven’t been able to turn up any examples and believe that the chip is intended for output only and that trying to read the pin values results in resetting all the pins states.

Edit: I found my problem - reading the datasheet more closely - my problem was I was trying to read from SER_Pin - which was my output pin. Once I hooked up an additional arduino pin and set it as the input pin I was up an running. Here’s my semi-final code (I just forced my arduino pin 7 to the input pin - for troubleshooting, still need to clean up the code for initializing input pin). There’s almost certainly a cleaner way to load my registers array as well.

void StepperH::readRegisters(){
  byte tempReg;
  tempReg = shiftIn(7, SRCLK_Pin,MSBFIRST);
  for(int i=0;i<8;i++) {
    if(bitRead(tempReg,i) ==1)

Attached is my poorly documented library code should someone be foolhardy enough to use it to control a couple of steppers using an HBridge. Next time going with a true stepper motor driver rather than an L298N.

StepperH.h (4.04 KB)

StepperH.cpp (7.1 KB)