Raspberry Pi, Bi-Color LEDs and the 74HC595 Serial Shift Register

Posted by Vytas Sinkevicius on

Every project I ever worked on required some form or LED indicators, usually status indicators where OK = Green, Warning = Amber and Critical = Red. Here is a circuit I use all the time, a 74HC595 serial shift register and the LTL-14CHG Red/Green Bi-Color LED.

The LTL-14CHJ Red/Green LED has only 2 leads, there are 3 lead types available which are easier to use. I used the 2 leaded one for this example to show how to get the Amber color. If current is passed in one direction of the LED, the color will be RED, if passed in the reverse direction, the color will be GREEN. By alternating the current direction at greater than 30 Hz, the human eye will integrate the RED and GREEN together and will perceive the color as AMBER.

The interface uses only 2 lines of the SPI interface and one Chip Select Line:

  • SCLK
  • MOSI
  • CS0

Here is the schematic for the circuit shown above:

I used the Pi-SPi-PROTO board to make up the demo using the above schematic. The LEDs as shown in the picture from top to bottom are:

  • LED 1 - GREEN - bits 0 and1
  • LED 2 - AMBER - bits 2 and 3
  • LED 3 - RED - bits 4 and 5
  • LED 4 - GREEN - bits 6 and 7

To achieve the colors as sown above, the program sends serial data to the 74HC595 where each bit is either ON or OFF to control the direction of current flow through the LEDs.

Program Loop in "C"

while(1) {      

        LED_Status = 0b10010110;                                
        Update_Leds(LED_Status);                
        delay(2);             
                
        LED_Status = 0b10011010;                                
        Update_Leds(LED_Status);                
        delay(2);             
}

To get the AMBER color, the bits 2 and 3 of the LED_Status are alternating.

Using this technique and the 74HC595, large multi LED tri-clour displays can be built using the SPI interface and and very few GPIO pins - 1 GPIO for every 4 b-color LEDs.

 

SaveSaveSave

Share this post



← Older Post Newer Post →


Leave a comment

Please note, comments must be approved before they are published.