Shift Register question

Hi,

Is there a way to daisy chain Shift registers so that data can be sent to each one individually? I need to shift 4 individual lots of 8 bit data into 4 shift registers whilst minimizing the number of digital pins used as I need to use four rotary encoders. Sorry if this is a dumb question but Im pretty new to this.

Sorry, I don't have anything to upload yet as I'm still at the planning stage and this has got me a bit stumped :blush:

Help appreciated.

Thanks

Which do you want - daisy chained, or written to individually?
74HC595 example: You can connect shift clock and serial data to all devices in parallel, and give each one its own register clock. Then each gets data clocked in, but only the device getting a register clock will have its output updated.
Or you can daisy chain the serial data, and send out all data when the data for one register changes. I do this from an array using the built in SPI. Say you had 4 registers that were daisy chained:

#include <SPI.h> // connect MOSI (D11) to Serial Data in, SCK (D13) to SRCLK
// OE to GND, MRCLR to +5

byte dataArray[] = {0,1,2,3,};
byte ssPin = 10; // connect to RCLK
byte x; // used with for loop

void setup(){
pinMode (ssPin, OUTPUT);
digitalWrite (ssPIN, HIGH);
SPI.begin();
}

void setup(){
:
stuff happens
:
// data is updated, time to send it out
digitalWrite (ssPIN, LOW);
for (x=0; x<4; x=x+1){ // 0,1,2,3
SPI.transfer (dataArray[x]);
}
digitalWrite (ssPIN, HIGH); // outputs change on this rising edge of different data was shifted in, otherwise outputs stay the same.
:
do other stuff
: 
}

The Transfer just takes 40-50uS to complete, and can be made faster with direct port manipulation and increasing the SPI transfer speed (default is 4 MHz clock). Make sure each shift register has a 0.1uF cap from it s Vcc pin to Gnd.

I need to shift 4 individual lots of 8 bit data into 4 shift registers

You are not understanding how to use shift registers. You have a variable, or set of variables in an array, and you output them all to the shift register chain.

If you only want to change one byte or bit and leave the others unchanged you just change the bits or bytes in the variable and move the whole lot into the shift registers. Only the bits you changed actually change. There is no need to output to individual shift registers at all. Use the bit write function or the grown up logic operators of AND (&) OR (|) and XOR (^) to manipulate bits in a variable.

Thanks for the replies!

I’ve used SR’s beforehand but never daisy chained them . I think what I’m trying to do is fairly basic for most… but when your a newbie…geez! All I need to do at this stage is get the binary value from the four encoders into each shift register. Any further advise on best practice …

Thanks

All I need to do at this stage is get the binary value from the four encoders into each shift register.

Are these parallel in serial out or serial in parallel out shift registers?

I seems to be not a good idea to transfer information from a rotary shaft encoder through a shift register. Can you post a link to this encoder?

Grumpy_Mike: I seems to be not a good idea to transfer information from a rotary shaft encoder through a shift register. Can you post a link to this encoder?

OK, sorry, I didn't explain myself very well ..... What I'm trying to do is have the arduino read each of the encoders and then send out a binary value to the SRs. In a nutshell, 4 binary counters controlled by encoders. I've not specced the encoders yet but I guess they don't need to be anything special. Maybe a push switch....not sure yet.

I got my head around the daisy chaining by the way and I now understand how to address as many individual SRs as I like. Thanks ;) I'm making progress with understanding the encoder coding but I have a question regarding this..... Is it possible to increase the number of interrupt pins ? Do I need two for each encoder...?

You can use the pin change interrupt facility which turns any pin into an interrupted pin. You only need one interrupt per pair of encoders if you don't mind half the resoloution.

The problem with encoders is that they produce a lot of interrupts and depending on the application you can get swamped if there are too many or your interrupt service routine is too slow, that is you try and do too much in them.

OK I think I'll scrap the encoders for now and just go for regular pots with inc/dec buttons. A 74HC165 will give me the inputs I need.

Another question though.... Do I need to use specific pins on the UNO for my 2 SRs. All the wiring I've seen so far seems to use pins D8, D11 and D12 for both the 595 AND the 165 ?

Nevermind... I think I have ze answer. A 4051 ;)