Wednesday, December 21, 2011

§5X7 Scrolling Message Display

Hello Friends,
     LED Matrix displays are very popular for displaying messages you can see them in everywhere in your daily routine. For example at railway station - it is used to display train details, in buses, at restaurants etc. In this post we will make a simple 5x7 LED matrix display and display some messages.

5x7 LED display needs 35 LEDs to make it. We have to connect all of 35 LEDs with a single microcontroller; here I am using AVR atmega8 which has 28 pins. If one LED takes one I/O pin of MCU then 35 LEDs required 35 I/O pins but atmega8 have only 22 I/O pins. Then how we do this??

Answer is MULTIPLEXING. This technique requires fewer I/O pins of MCU. We need only 12 I/O pins of MCU to interface this display. To understand that techniques see the figure below.


 
 
You can see in the figure that there are 5 column and 7 rows. All the cathodes are shorted horizontally and all the anodes are shorted vertically. All the anodes are controlled by columns and all the anodes are controlled by rows. This structure makes a matrix of 7x5 hence the name ‘LED Matrix display’ and controlling all the LEDs using this technique called multiplexing.

For example: If we want to ON led located at (0, 0) then we have to connect first column to VCC and first Row to Ground. We will discuss more about this in this post.

Ok! First we have to make this matrix; this requires patience and lots of time to soldering. See the pics below.

 
This is my 13x5 LED matrix.

 
Be careful to make this; the directions of all the anodes and cathodes should be in correct way otherwise some LEDs will not glow. You can see in the figure that there is a bridge shape structure which is complex and many chances to shorting; If you hesitate to make this then don’t worry there is readily available 5x7 LED display available in the market.See pic below :

 
This is a 5x7 LED Matrix module common anode type. Let’s see its pin sequence.


 

Circuit Diagram :
 
 We can't connect LEDs directly to supply hence we have to connect resistance within its path, 470 ohm is sufficient with 5volt supply. Here I am using MCU as current sinking so for current sourcing I placed 4 NPN transistors at columns. Base of transistors are connected to MCU. When base goes high Emitter to Collector gets shorted and vcc comes at columns.

Readily available 5x7 LED modules have no regular sequence of row and columns so we have to spend some time with PCB and soldering iron. 

Take a small piece of zero PCB and make a Header Board for this LED module. Also place transistors and registers on it. See images –

 
Connect a 12 pin female burg strip for Row and Column Connection.


Now we can directly connect this with our microcontroller. The purpose of making this is to make it portable so that we can connect it on the breadboard also. Always try to make things portable so that we don’t have to make them again if repeated.

Make two ribbon cables. One is 7 pin male-to-male and second is 5 pin male-to-male. See pics :

 
Connect the cables to 5x7 module and to Microcontroller with the help of circuit diagram.



 


Hardware part is completed. Let’s move towards software part.


To display a character break it in five 8-bit binary (or hex) sequences. See the image below-
 

                                              1 -- LED ON      0 -- LED Off
(Note : We configure MCU as current sinking so we have to send invert sequence ~seq[] )

Store the sequences in an array.We have to switch column one by one rapidly. Binary sequence comes from micro-controller strikes at row pins (R1-R7) and that time if any column line is active (High) then this sequence will show on that column. We have to send seq1 to col-1, seq2 to col-2 and so on. If you don't understand clearly then see the image blow, which is self explanatory.
Columns are switched one by one with some delay and at the same time binary data comes at row will display on that column line.

**What will happen if we decrease column switching delay (or increase switching speed)?  Yes, you are thinking right we will see a still image. This phenomenon is known as “Persistence of Vision”, it gives the illusion that all the LEDs lit at the same time. This is the basic concept of this display. See the image below –

See the image below - POV effect
 
Program: To display a single character
MCU : Atmega8 @ 16MHz  Compiler – WinAVR

Code :
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>

unsigned char seq[]={
0b01111111,
0b00001001,
0b00001001,
0b00001001,
0b00000110,  
};
                    
int main()
{   
   DDRC=0xFF;
   DDRD=0xFF;
   PORTC=0;
   PORTD=0; 
   int i=0;
    while(1)
       {   
          for(i=0;i<5;i++)
           {  
           PORTC=(1<<i);       
           PORTD=~seq[i];
           _delay_ms(3);           
        }
  }
 return 0;
}

Program -2: Scrolling Message

The 5x7 hex sequence of all the characters are stored previously in a header file “font5x7.h” just include it in your main program and enjoy it. All the characters are stored at its ascii location. So first convert characters in its ascii value to fetch up sequence from correct location.

To display moving message we have to maintain a buffer and store binary sequences of all the characters of our message in it. A window of sequence 5 will slide continuously at specified time which will show moving effect.(see ISR section of the code)

Software delay is not accurate so I configure AVR internal Hardware Timer which is CPU independent. I am using 16-bit Timer1 in compare mode means I can decide it’s counting boundary according to my requirement. If you are not familiar with timer go through AVR datasheet or Google it.

Let’s do some calculation:
A good POV frequency is 400Hz (Flicker Free). Our CPU frequency is 16000000Hz and timer frequency is F_CPU/Prescaler=(16000000/1024)=15625Hz.
So compare value to generate 400Hz is ---
Compare Value = (15625/400)=39.0625
1/400=2.5ms delay means at every 2.5 ms timer interrupt will strike ISR. 



Code :
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "font5x7.h"

#define LED5x7_DDR DDRD
#define LED5x7_PORT PORTD

#define LED5x7CONTROL_DDR DDRC
#define LED5x7CONTROL_PORT PORTC 

unsigned char buffer[];
unsigned int buffer_loc=0;
volatile int count=0,scroll=0,col=0;

//----------------------------------------------------------------
void Scroll_MSG(char *msg)
{
 int i,j=0;
 while(*msg!='\0')
 {
    j=(*msg-32)*5;
      for(i=j;i<(j+5);i++)
       {  
          buffer[buffer_loc]=font5x7[i];
          buffer_loc++;
        }
       buffer[buffer_loc]=0;
      buffer_loc++;
      msg++;
 }
}
//----------------------------------------------------------------
void Timer_Init()
{
    TCNT1=0;
    TIMSK|=(1<<OCIE1A);
    OCR1A=39;
    TCCR1B|=(1<<CS12)|(1<<CS10)|(1<<WGM12);//F_CPU/1024,CTC
    sei();
}
//----------------------------------------------------------------
int main()
{
Timer_Init();

LED5x7_DDR = 0xFF;
LED5x7CONTROL_DDR = 0xFF;

Scroll_MSG(" 5x7LED DISPLAY");
Scroll_MSG(" By-PRATYUSH ");

while(1);
return 0;
}
//----------------------------------------------------------------
ISR(TIMER1_COMPA_vect)
{
 count++;
 if(count==50){ //to increase scrolling speed decrease counting
   count=0;scroll++;
    if(scroll>buffer_loc-5)
     {scroll=0;}
  }

 LED5x7CONTROL_PORT = (1<<col);
 LED5x7_PORT = ~buffer[scroll+col];

 if(col++==4)
      {col=0;}
}
//----------------------------------------------------------------

My Pocket Electronic Message card: :)

 
Downloads:  circuit diagram 
                      hex file and code for display single character
                      hex file and code for scroll string/message

Video: 
                                                                                                                             ~Pratyush Gehlot

29 comments:

  1. ur project fine but i want sms controled scrolling led display can u give me that on my mail if u help me i will help u i am project macker my email devdatta_mhaiskar@in.com

    ReplyDelete
  2. it was really helpfull

    ReplyDelete
  3. Hi, your project is nice cool! I'm loving this. Now I haven't led 8x8 cathode row, then I have led 8x8 anode row. I need your help about the 74HC595 shift registers with connecting the 16 columns and the 4017 decade counter with UDN2981 rows. Also sending the string message on USART RX/TX. Help me.

    ReplyDelete
  4. These display is microprocessor based Moving Message Display made up of light emitting diode (LEDs) arranged in an array. The Moving Message or data can be fed & set with the help of keypad on chorded remote provided with this unit.For more information visit: http://www.ledtechshop.com

    ReplyDelete
  5. can u plz help me to make this to a 15*7 display?

    ReplyDelete
  6. This is a very nice project, it has really help me a lot. the only challenge i have with it now it how to add LED extension to be able to accommodate more LEDs for display.
    Pls kindly help me out on this, as per what to do.

    Thank You very much.

    ReplyDelete
  7. please give me the circuit diagram and components used for shifting the characters from one matrix to another matrix and simple programming also

    warm regards

    saket

    ReplyDelete
  8. It is nice blog. In Proteus, your string program is not working. Please send me a correct string program. My email is 131061@gmail.com.

    ReplyDelete
  9. This is the blog, that i was searching from like a very long... GRT WORK BRO!!

    ReplyDelete
  10. A very well mentioned project on a good projects. Currently i am doing different Led Display projects. These are very tough to do & execute.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. i cant able to view the .hex file

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. ur project fine arrow design up/down help me my project code file

    ReplyDelete
  18. incredible boss.....ur d best in making things simple......
    i have been exploring many blogs from long time,no one made it as simple as u did...
    y dont u help us making a led cube(atleast 3x3 )....

    ReplyDelete
  19. Hi buddy, your blog's design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!


    Moving Display Board

    ReplyDelete
  20. Nice and very helpful information i have got from your post.

    led video light

    ReplyDelete
  21. Thank you for posting the great content…I was looking for something like this…I found it quiet interesting, hopefully you will keep posting such blogs….Keep sharing

    led display

    ReplyDelete
  22. There are certainly a lot of details like that to take into consideration.
    led display

    ReplyDelete
  23. I just came across to reading your blog it serve very useful information about the interiors thank u
    Tv wall

    ReplyDelete
  24. Post is very informative,It helped me with great information so I really believe you will do much better in the future.
    Digital Signage Kiosk

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Sir plz explain how the function to scroll is working and why u have done j=(*msg-32)*5. I didn't got this logic.

    ReplyDelete

PID Controlled Self balancing Robot using ESP8266 and MPU6050

This ROBOT is made using ESP8266 Node MCU and MPU6050 accelerometer. Motor used here is normal gear motor of 150 rpm with TB6612FNG motor dr...