Sunday, November 29, 2009

Scrolling message display board

To make an led ON/OFF we usually use one I/O pin of the microcontroller
this will work fine with 5 to 8 leds but when u have drive a display board
which may contain LEDs between 70 to 100 depending on the matrix size , using each microcontroller I/O to control each LED is impossible and !!!!!!!!

so there are ways in which we can control many leds using few i/o pins
1)using charlieplexing if we have n i/o pins we can control
n*(n-1) leds using this method and all the pattern's may not be possible in this case
more about charlieplexing can be found at charlieplexing

charlieplexing with 3 i/o pins



2)using Dot Matrix
leds a connected like this


two types common anode n common cathode type.....
u can buy this modules , they cost around Rs70(5*7 matrix)


here we send data row wise , that is activating one row at a time and through column we need to send the data which we want to see
this image might give a better idea


i have shown for two row's this repeat's in a loop for all the row ..

3) using decoder's this is the ultimate way and flickering can be seen if the microcontroller is working at slow speed's , we can control 1024 leds with 11 i/o pins two 5*32 decoder for row n column
we are not interested with this method , as modules are not available we need solder the whole LED network

Program which i have implemented
ATmega32 chip running @4mhz
compiler WINAVR

#include
#define F_CPU 4000000UL
#include
typedef unsigned char u8;
typedef unsigned int u16;

int main(void)
{
u16 data2[5]={1,2,4,8,16},y[5];
u16 i,j,k,p,t,l[5][6]={{0x7f,0x41,0x41,0x41,0x3e,0x00},{0x3e,0x41,0x41,0x41,0x3e,0x00},{0x7f,0x40,0x40,0x40,0x40,0x00},{0x7f,0x40,0x40,0x40,0x40,0x00},{0x01,0x02,0x7c,0x02,0x01,0x00}};//data to be displayed
DDRD=0X00; //control i/p for Lb and Rb
PORTD=0XFF; //internal pull ups
DDRA=0xff;//data O/p to dot matrix
DDRC=0xff; //control o/p to dot matrix
for(i=0;i<5;i++)
{
y[i]=0;
}

while(1)
{
for(i=0;i<5;i++)
{
for(p=0;p<6;p++)
{
// display data
for(j=0;j<50;j++)
{
for(k=0;k<5;k++)
{
PORTC=data2[4-k];
PORTA=y[k];

_delay_ms(1);

}
}
// next loop data
for(t=0;t<4;t++)
{
y[4-t]=y[3-t];
}

y[0]=l[i][p];//new data

}// end of p for

}// end of i for
}// end while

}

here's the vedio moving message vedio

PING PONG game on DOT matrix

Wednesday, November 25, 2009

charecter segmentation matlab


we will use the above image for processing

1.add the image to matlab work space

ch=imread('char.jpg');

2.convert the RGB image to gray scale using rgb2gray function
Gch=rgb2gray(ch);

3.convert this gray scale image to BW comparing with some threshold
bw= im2bw(Gch,graythresh(Gch));

now u will get a binary image containing 1 r 0 's which will be easy to process

4. find the edge's in that binary image
Ibw= edge(uint8(bw));
imshow(Ibw);

5.using Morphological process to enhance the image
se = strel('disk',4);
bw2 = imdilate(Ibw, se);
imshow(bw2);



6. filling the holes in the dilated image
fill= imfill(bw2,'holes');
imshow(fill)
7. labeling the parts of the image and marking their position
[lab n] = bwlabel(fill);
props = regionprops(lab);
Z = [props.BoundingBox];
Z= reshape(Z,[4 n]);


8. display the results
imshow(I);
hold on;
for i = 1:n
rectangle('position',z(:,i),'edgecolor','r');
end


this can be used with a neural network to recognize patterns
we will see how to do this in next blog