74HC595 Pins or SPI?

As I want to build a qlocktwo ( http://qlocktwo.com/ ) I try to use a 74HC595,
chain a lot of them, and solder my leds to them.

What approach in development would you prefer?
Using pins or using SPI ?

Which would you prefer and why?

I personally prefer the pin solution as I dont know anything about SPI :slight_smile:
I browsed through some older posts discussing the 74HC595 some where using Pins others SPI.
What is the common and best solution for this?

Thanks!

Picture of my breadboard attached :wink:

Hi,
I have used X socket (3 wire needed) and no spi at all. I’ve done my own driver for 74HC595, although SPI can be used.


    public class Driver74HC595
    {
        DigitalOutput pin_CK;
        DigitalOutput pin_SI;
        DigitalOutput pin_RK;
        GT.Socket socket;

        public Driver74HC595(int numsocket)
        {
            socket = GT.Socket.GetSocket(numsocket, false, null, null);
            
            pin_CK = new DigitalOutput(socket, GT.Socket.Pin.Five, false, null);
            pin_SI = new DigitalOutput(socket, GT.Socket.Pin.Four, false, null);
            pin_RK = new DigitalOutput(socket, GT.Socket.Pin.Three, false, null);
        }


        public Driver74HC595(Cpu.Pin _pin_CK, Cpu.Pin _pin_SI, Cpu.Pin _pin_RK)
        {
            //pin_CK = _pin_CK;
            //pin_SI = _pin_SI;
            //pin_RK = _pin_RK;
        }


        public void SendData(byte b)
        {
            byte btemp = b;
            int i = 0;
            pin_RK.Write(false);
            for (i = 0; i < 8; i++)
            {
                pin_CK.Write(false);
                //btemp &= 0x01;
                if ((btemp & 0x01) == 1)
                {
                    pin_SI.Write(true);
                }
                else
                {
                    pin_SI.Write(false);
                }
                Thread.Sleep(1);
                pin_CK.Write(true);
                Thread.Sleep(1);
                btemp >>= 1;
            }
            pin_RK.Write(true);
        }
    }
}


do you think this approach is better than using SPI ?

I have not an absolute answer. For my needs I choose software driver and not to reserve a SPI hadware port.

SPI is more optimised. That’s it’s plus. For a 74HC595 it’s not deemed an SPI device though, even though it’s timing is exactly SPI-compatible. Bit-banging this device is easy, and as you say its more flexible since you don’t need to tie up SPI unnecessarily (but that’s not really a big issue unless you want to use those pins for other things).

after two days of very frustrating work with my breadboard everything is wired up and seems to be running

with my arduino.

with the spider its not working.

maybe i mixed up the pins…
I think i tried every combination of my pins 3,4 and 5 with the latch clock and data in the code snippet from dobova.
but its totally frustrating me…
can anyone tell me which pin in the provided code is what?

SI should be data
CK should be latch
and RK is the clock

please tell me if im wrong

thanks :slight_smile:

@ Weiti - If I rember correctly RK is latch and CK is clock.

CK = Clock, always…

The 74HC(T)595 has 2 stages, look into the datasheet : http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf
You need DataIn, Clock, Load and a value level at Reset…

In the code above, pin 3 (PIN_RK) is LATCH, pin 4 (PIN_SI) is DATA and pin 5 (PIN_CK) is CLOCK, and the whole thing assumes your extender module is in socket 6, despite asking for ‘numsocket’ on initialising. The pseudocode for the shift register would be:


Set the latch off at the start, ready to program in the next set of bits
for each one of the eight data bits to set, do this:
  set the clock off
  set the data pin on or off depending on data 1 or 0
  set the clock on again - this is the point the shift register notices the value of the data bit
end loop
set the latch on - this is the point at which the shift register sends all eight bits of data out to its output pins.

Here’s an Arduino tutorial that includes how to use more shift registers cascaded: http://www.arduino.cc/en/Tutorial/ShiftOut

If you’ve got a breadboard working with Arduino, the only difference needed to get it working with Gadgeteer too would be get an extender module with breadboard headers soldered on connected to socket 6 on the mainboard and plugged into the breadboard, then get GND, 5V and pins 3, 4 and 5 hooked up.

The code above is working fine in a an application driving relays since one month.
Pay attention, because some brend of 595 are different in the latch sequence needed.

Yay!
Great success :slight_smile:

Finally got some leds lit up, but after that I think I “measured” my 74HC595 to death…
No blue smoke, but they are not responding anymore…

Maybe its cause I wasnt using any resistors, but with em I wasnt getting any lit up leds…

Im gonna buy me tomorrow a bunch of them and try it again.

Thank you Guys!

No resistors, no party

with resistors there was no party!
maybe i use some strange german leds…

I’had similar setup, but leds are attached to 595 pins through resistor of 100 ohm. Leds have common catode to gnd

100 ?

i used 220…
Maybe thats my problem…

Choosing the right resistor for a led is not something you do by trail-and-error. You can calculate them :slight_smile:

Something like R = (Vdrive - Vled) / Iled

Right but you need to know vled and iled. This may vary a bit.

I bet those leds on the breadboard are 3V leds and I would drive them with 5, max 10mA. Anyway even with 2 or 3mA they should light up.