LED Segment Display on a Raspberry Pi

During my leisure time I made a LED segment display work using a Raspberry Pi. I have used a 74HC595 shift register and a LED segment display. This would be the circuit diagram.

Actually all of this was done from the scratch. The SegCodes were found from Wikipedia http://en.wikipedia.org/wiki/Seven-segment_display

This is the program ๐Ÿ™‚

#include <wiringPi.h>
#include <stdio.h>


#define   SDI   0
#define   RCLK  1
#define   SRCLK 2

unsigned char SegCode[17] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80};

void init(void){
        pinMode(SDI, OUTPUT);
        pinMode(RCLK, OUTPUT);
        pinMode(SRCLK, OUTPUT);

        digitalWrite(SDI, 0);
        digitalWrite(RCLK, 0);
        digitalWrite(SRCLK, 0);

void shift(unsigned char dat){
        int i;

                digitalWrite(SDI, 0x80 & (dat << i));
                digitalWrite(SRCLK, 1);
                digitalWrite(SRCLK, 0);
        }       digitalWrite(RCLK, 1);
                digitalWrite(RCLK, 0);

int main(void){
        int i;

        if(!wiringPiSetup()) printf("Error Occured");
        while(1) for(i=0;i<17;i++){

        return 0;


Feels amazing when you write programs and control hardware ๐Ÿ™‚ You can also use Python with the GPIO library to the above or any language as long as it supports GPIO capabilities. However being familiar with C programming I love to do most of the things in C.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.