SN74HC165N - Using more than 4

http://playground.arduino.cc/Code/ShiftRegSN74HC165N

The above tutorial works great for 4 x SN74HC165N but I would like to use 6.

I have searched through the forums and although there are some alternatives (such as using SPI) there doesn't seem to be a definitive method for using this setup with more than 4.

Any help would be appreciated.

Thanks!

I don't understand. The tutorial is for 2 x SN74HC165N, not 4.

The SN74HC165N is a shift register, so you can use as many as you want. There are some practical limits, but 6 is well within these limits.

The code will have to be appropriately modified to handle 6 chips instead of 2, and the extra bits will make things take longer (from an Arduino viewpoint, not to a button-pushing LED-viewing human).

Man, what a convoluted way to read data.
Try this, with clock connected to SCK, data out connected to MISO, and SS to the Load pin.

// at top of sketch
#include <SPI.h>
byte ssPin = 10;

// in setup
pinMode (ssPIN, OUTPUT);
SPI.begin(); // default settings: 4 MHz clock, MSBFirst

// in loop
digitalWrite (ssPin, LOW);
digitalWrite (ssPin, HIGH); // capture data
byteArray[0] = SPI.transfer(0); // read in a byte
byteArray[1] = SPI.transfer(0); // read in a byte
byteArray[2] = SPI.transfer(0); // read in a byte

byteArray[3] = SPI.transfer(0); // read in a byte

byteArray[4] = SPI.transfer(0); // read in a byte

byteArray[5] = SPI.transfer(0); // read in a byte

Let the internal SPI hardware do its job. Way less code, and it will load data in way faster too.

It's a daisy chain or a cascade (I don't know the right word), you can use 4 or 400. As long as you shift the right amount of bits in the sketch. Pin 10 'SER' is the input and pin 9 'QH' is the output.

I think the 74HC595 is more often used, but I don't know what the difference is.

165 is parallel load, shift out register. For capturing & reading data.
595 is shift in, parallel out. For setting up outputs.

O, right, that was it. Thanks. I have both chips, but had forgotten it.

Thanks for all the prompt responses!

I understand that you can easily daisy chain them but the code requires a little modification.

Yes, the tutorial is for 2 but it easily works well with 4. However, using 6 is a little more complicated.

From the commented code: "Of course you can daisy chain as many as you like while still using only 4 Arduino pins (though you would have to process them 4 at a time into separate unsigned long variables)."

This is the bit I'm having an issue with. Processing them 4 at a time.

I understand that SPI is more efficient but I'd like to get this setup functioning. Even if it is convoluted!

Why not learn from the experience of others, use SPI.

Or not. .

You can use up to 8 shift registers with that example if you change BYTES_VAL_T to unsigned long long (aka uint64_t).

CrossRoads:
Man, what a convoluted way to read data.
Try this, with clock connected to SCK, data out connected to MISO, and SS to the Load pin.

// at top of sketch

#include <SPI.h>
byte ssPin = 10;

// in setup
pinMode (ssPIN, OUTPUT);
SPI.begin(); // default settings: 4 MHz clock, MSBFirst

// in loop
digitalWrite (ssPin, LOW);
digitalWrite (ssPin, HIGH); // capture data
byteArray[0] = SPI.transfer(0); // read in a byte
byteArray[1] = SPI.transfer(0); // read in a byte
byteArray[2] = SPI.transfer(0); // read in a byte

byteArray[3] = SPI.transfer(0); // read in a byte

byteArray[4] = SPI.transfer(0); // read in a byte

byteArray[5] = SPI.transfer(0); // read in a byte



Let the internal SPI hardware do its job. Way less code, and it will load data in way faster too.

Could you give more details, please? I get an error:

exit status 1
‘ssPIN’ was not declared in this scope

You need to show us your code. It would seem that you have omitted this line or placed it incorrectly:

byte ssPin = 10;

CrossRoads:
Man, what a convoluted way to read data.
Try this, with clock connected to SCK, data out connected to MISO, and SS to the Load pin.

// at top of sketch

#include <SPI.h>
byte ssPin = 10;

// in setup
pinMode (ssPIN, OUTPUT);
SPI.begin(); // default settings: 4 MHz clock, MSBFirst

// in loop
digitalWrite (ssPin, LOW);
digitalWrite (ssPin, HIGH); // capture data
byteArray[0] = SPI.transfer(0); // read in a byte
byteArray[1] = SPI.transfer(0); // read in a byte
byteArray[2] = SPI.transfer(0); // read in a byte

byteArray[3] = SPI.transfer(0); // read in a byte

byteArray[4] = SPI.transfer(0); // read in a byte

byteArray[5] = SPI.transfer(0); // read in a byte



Let the internal SPI hardware do its job. Way less code, and it will load data in way faster too.

Can I use 20 74HC165 with this code?

Herodes:
Can I use 20 74HC165 with this code?

Not with that exact code, but the principal will work with any number of SRs

Herodes: Could you give more details, please? I get an error:

exit status 1 'ssPIN' was not declared in this scope

Look closely how each 'sspin' is written. Fix the one that is not like the others.

Capitalization matters.

In order not to duplicate, I'm still in this thread. Please, follow also you.