Pages: [1]   Go Down
Author Topic: Help with Multiplexing DISPLAY PROBLEM  (Read 1543 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, i'm connecting according to http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267391793/7 , instead i use 595shift register for both rows and column.  see my video below for the problem

http://www.youtube.com/watch?v=lR1SGd_6Uc4&feature=youtu.be

My matrix are 5x7. i connected rows to 3 shift register and the column into one shift register.
this are my code. Can anyone teach me how to display properly and with some text?

Code:
//-- Columns (Negative Cathodes) --
int latchPin1 = 2; //Arduino pin connected to Green 10 RCK of TPIC6C595
int clockPin1 = 3; //Arduino pin connected to Yellow 15 SRCK of TPIC6C595
int dataPin1 = 4;  //Arduino pin connected to Blue 2 SER IN of TPIC6C595

//-- Rows (Positive Anodes) --
int latchPin2 = 5; //Arduino pinn connected to Green Latch 12 ST_CP / RCK of 74HC595
int clockPin2 = 6; //Arduino pin connected to Yellow Clock 11 SH_CP / SCK of 74HC595
int dataPin2 = 7;  //Arduino pin connected to Blue Data 14 DS / SI of 74HC595

//=== B I T M A P ===
//Bits in this array represents one LED of the matrix
// 8 is # of rows, 7 is # of LED matrix we have
byte bitmap[8][4]; // Change the 7 to however many matrices you want to use.
int numZones = sizeof(bitmap) / 8; // I will refer to each group of 8 columns (represented by one matrix) as a Zone.
int maxZoneIndex = numZones-1;
int numCols = numZones * 8;

//=== F O N T ===
// Font courtesy of aspro648
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203747843/22
// First char is @, next is A, B, etc.  Only lower case, no symbols.  
// The @ will display as space character.
byte alphabets[][5] = {
  {0,0,0,0,0}, //space
  {31, 36, 68, 36, 31}, //a
  {127, 73, 73, 73, 54}, //b
  {62, 65, 65, 65, 34}, //c
  {127, 65, 65, 34, 28}, //d
  {127, 73, 73, 65, 65},        //e
  {127, 72, 72, 72, 64}, //f
  {62, 65, 65, 69, 38}, //g
  {127, 8, 8, 8, 127}, //h
  {0, 65, 127, 65, 0}, //i
  {2, 1, 1, 1, 126}, //j
  {127, 8, 20, 34, 65}, //k
  {127, 1, 1, 1, 1}, //l
  {127, 32, 16, 32, 127}, //m
  {127, 32, 16, 8, 127}, //n
  {62, 65, 65, 65, 62}, //o
  {127, 72, 72, 72, 48}, //p
  {62, 65, 69, 66, 61}, //q
  {127, 72, 76, 74, 49}, //r
  {50, 73, 73, 73, 38}, //s
  {64, 64, 127, 64, 64}, //t
  {126, 1, 1, 1, 126}, //u
  {124, 2, 1, 2, 124}, //v
  {126, 1, 6, 1, 126}, //q
  {99, 20, 8, 20, 99}, //x
  {96, 16, 15, 16, 96}, //y
  {67, 69, 73, 81, 97}, //z
  {62, 69, 73, 81, 62},         //0 - zero
  {0, 33, 127, 1, 0},           //1
  {49, 67, 69, 73, 49},         //2
  {34, 65, 73, 73, 54},         //3
  {24, 104, 8, 127, 8},         //4
  {114, 73, 73, 73, 70},        //5
  {62, 73, 73, 73, 38},         //6
  {64, 64, 71, 72, 112},        //7
  {54, 73, 73, 73, 54},         //8
  {50, 73, 73, 73, 62},         //9  
};

//=== S E T U P ===

void setup() {
  pinMode(latchPin1, OUTPUT);
  pinMode(clockPin1, OUTPUT);
  pinMode(dataPin1, OUTPUT);

  pinMode(latchPin2, OUTPUT);
  pinMode(clockPin2, OUTPUT);
  pinMode(dataPin2, OUTPUT);
  
  //-- Clear bitmap --
  for (int row = 0; row < 8; row++) {
    for (int zone = 0; zone <= maxZoneIndex; zone++) {
      bitmap[row][zone] = 0;
    }
  }
}

//=== F U N C T I O N S ===

// This routine takes whatever we've setup in the bitmap array and display it on the matrix
void RefreshDisplay()
{
  for (int row = 0; row < 8; row++) {
    int rowbit = 1 << row;
    digitalWrite(latchPin2, LOW);  //Hold latchPin LOW for as long as we're transmitting data
    shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit);   //Transmit data

    //-- Start sending column bytes --
    digitalWrite(latchPin1, LOW);  //Hold latchPin LOW for as long as we're transmitting data

    //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
    for (int zone = maxZoneIndex; zone >= 0; zone--) {
      shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
    }

    //-- Done sending Column bytes, flip both latches at once to eliminate flicker
    digitalWrite(latchPin1, HIGH);  //Return the latch pin high to signal chip that it no longer needs to listen for information
    digitalWrite(latchPin2, HIGH);  //Return the latch pin high to signal chip that it no longer needs to listen for information

    //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
    delayMicroseconds(500);
  }
}

// Converts row and colum to actual bitmap bit and turn it off/on
void Plot(int col, int row, bool isOn)
{
  int zone = col / 8;
  int colBitIndex = col % 8;
  byte colBit = 1 << colBitIndex;
  if (isOn)
    bitmap[row][zone] =  bitmap[row][zone] | colBit;
  else
    bitmap[row][zone] =  bitmap[row][zone] & (~colBit);
}

// Plot each character of the message one column at a time, updated the display, shift bitmap left.
void AlphabetSoup()
{
  char msg[] = "LED MATRIX 1234 ";

  for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)
  {
    int alphabetIndex = msg[charIndex] - '@';
    if (alphabetIndex < 0) alphabetIndex=0;
    
    //-- Draw one character of the message --
    // Each character is only 5 columns wide, but I loop two more times to create 2 pixel space betwen characters
    for (int col = 0; col < 7; col++)
    {
      for (int row = 0; row < 8; row++)
      {
        // Set the pixel to what the alphabet say for columns 0 thru 4, but always leave columns 5 and 6 blank.
        bool isOn = 0;
        if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;
        Plot( numCols-1, row, isOn); // We ALWAYS draw on the rightmost column, the shift loop below will scroll it leftward.
      }
      
      //-- The more times you repeat this loop, the slower we would scroll --
      for (int refreshCount=0; refreshCount < 10; refreshCount++)
        RefreshDisplay();

      //-- Shift the bitmap one column to left --
      for (int row=0; row<8; row++)
      {
        for (int zone=0; zone < numZones; zone++)
        {
          // This right shift would show as a left scroll on display because leftmost column is represented by least significant bit of the byte.
          bitmap[row][zone] = bitmap[row][zone] >> 1;
          
          // Roll over lowest bit from the next zone as highest bit of this zone.
          if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7, bitRead(bitmap[row][zone+1],0));
        }
      }
    }
  }
}

//=== L O O P ===

void loop() {
  AlphabetSoup();
}

Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
« Last Edit: May 03, 2012, 12:13:34 am by Nick Gammon » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting sound effects.

So what is wrong exactly? What are you expecting to see?

Personally I would use SPI rather than shiftOut.

http://www.gammon.com.au/forum/?id=11518
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How have you wired it up? That will influence how you display stuff. This might help maybe:

http://www.gammon.com.au/forum/?id=11524
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i wired up like this http://g33k.blogspot.com/2010/02/arduino-56x8-scrolling-led-matrix.html but using 595 shift register.
i wan to display character that are visable . but mine dont look like a alphabet.
What is SPI?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.gammon.com.au/spi

The link I posted above shows how you can use SPI to shift stuff out to shift registers.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SPI is so hard.. any more solid code to spi in controling shift register ?
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 625
Posts: 34099
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
SPI is so hard
No it is not.
Look at the examples given in the SPI library, it is almost trivial.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
SPI is so hard
No it is not.
Look at the examples given in the SPI library, it is almost trivial.

eh, alrights. then how do i setup in order to use SPI?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <SPI.h>

...


SPI.begin ();
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i mean as in hardware? so i have five 5x7 dot matrix, i connect all the rows into 4 595 shift register , and column into one 595 shift register? Then to use SPI, i connect the column shift register to the row shift register linking together?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Help please.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 625
Posts: 34099
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Then to use SPI, i connect the column shift register to the row shift register linking together?
No, the SPI output connects directly to the data and clock of one shift register. The others are chained on the end of it. It is just like using shift out only it runs much faster.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello grumpy. Been a week , yet i am still not progressing.. i am using SPI interface. There is five 5x7 dot matrix(common anode on column ) , i connect all the rows into one shift register. and the column (total 25 column) into 4 SR. The 4SR are in serial connected together, then the end of 4th shift register(pin 9 ) went to the row SR(pin 14) , same for the latch and clock. Is that the way? Well, i'm also stuck in programming. How to i send data into my shift register? SPI.TRANSFER(0xff) - will make the 1st shift register all 1? Will it link to other SR. By doing that. How to display Character? Lets say i want to display a A , how do i program? Please help me out. Thanks smiley-cry
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 625
Posts: 34099
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How to i send data into my shift register? SPI.TRANSFER(0xff) - will make the 1st shift register all 1?
Yes,do it again and the contents of the first shift register are transferred to the second and the first has the new data in it. o do it 5 times to fill all 5 shift registers. Then toggle the latch to make what is inside the shift registers appear on the output pins.

Quote
How to display Character? Lets say i want to display a A , how do i program? Please help me out.
Read his:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Note there is only enough current from a pin of a shift register for one LED so you will need some current drivers to get more current output. Again see the above link.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How to i send data into my shift register? SPI.TRANSFER(0xff) - will make the 1st shift register all 1?
Yes,do it again and the contents of the first shift register are transferred to the second and the first has the new data in it. o do it 5 times to fill all 5 shift registers. Then toggle the latch to make what is inside the shift registers appear on the output pins.

However, one thing is that. One of my SR is for row, other 4 are for column . Does it matter? If i SPI.TRANSFER(0xff) to the 4 SR for column . It will light up all right? Then what the row SR for?

Quote
How to display Character? Lets say i want to display a A , how do i program? Please help me out.
Read his:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Note there is only enough current from a pin of a shift register for one LED so you will need some current drivers to get more current output. Again see the above link.

Yes, sorry. i never add in that i got one ULN2803 for the first dot matrix. Must i have 4ULN2803 to have enough current for the 25 columns?
I read it over and over again.  I'm confused. For 5x7 dot matrix, i want display A
It will look like this
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
So i have to activate one column and my desire row one at a time . And make it at a speed that the eye wont see it changing? Is that so ?
Logged

Pages: [1]   Go Up
Jump to: