Need some help on led matrix 8x8

Hi everyone!

Here is my problem: I tried to do the following assembly on my arduino Uno

... with the following code

iint DataPin = 11; //data
int LatchPin = 8;  //STCP
int ClockPin = 12;  //SHCP
int clock = 9;  //CD4017 Pin14
int Reset = 10;  //CD4017 Pin15
//x,y for the loop
int x;
int y;
// here the definion of all the letter(big ans small) and numbers
#define A     {B00000000,B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B00000000}
#define B     {B00000000,B01111100,B01000010,B01000010,B01111100,B01000010,B01000010,B01000010,B01111100,B00000000}
#define C     {B00000000,B00111110,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B00111110,B00000000}
#define D     {B00000000,B01111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111100,B00000000}
#define E     {B00000000,B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01111110,B00000000}
#define F     {B00000000,B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01000000,B00000000}
//etc.
#define num_0 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000}
#define num_1 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000}
#define num_2 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000}
#define num_3 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000}
#define num_4 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000}
#define num_5 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000}
#define num_6 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_7 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000}
#define num_8 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_9 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000}
#define times {B00000000,B00000000,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B00000000,B00000000}

const int numPatterns = 17;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space,M,A,D,E,space,B,Y,space,V,A,D,I,M,space};// the patterns order
void setup(){
  pinMode(DataPin,OUTPUT);
  pinMode(ClockPin,OUTPUT);
  pinMode(LatchPin,OUTPUT);
  //simple stuff here
 pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  //reseting the 4017 IC, you have to do this
 digitalWrite(Reset,HIGH);
  delayMicroseconds(5);
  digitalWrite(Reset,LOW);
}

void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it
{ 
  for(x=0;x<numPatterns-1;x++){ // loop over the patterns
   for (int z=0;z<8;z++){ //scrolls one bite at a time 
    for(int t=0;t<loops;t++){// the delay we get with loops
     for(y=0;y<10;y++){// loops over the array of bytes
     byte temp = patterns[x][y]; 
     byte temp_2=patterns[x+1][y];
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,((temp<<z)+(temp_2>>7-z)));//writes digital outputs, Z is for how much bites it need to scroll
          digitalWrite(LatchPin, 1);
      delayMicroseconds(800);
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
      digitalWrite(LatchPin, 1);
     digitalWrite(clock,HIGH);
     digitalWrite(clock,LOW);
   }
  }
 }
}
}

void loop(){
 display_pattern(7);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrrol slower).

}

I tried with just the matrix 1 and the text is scrolling but with one pixel gap. The upper line is useless and the last line do not appears (maybe an assembling error I don't know).

I tried with the matrix 1 and 2. The matrix 2 displays the same as the matrix 1 but with one more pixel gap and the LED are less bright.

I think about using 74hc595 instead of cd4017 but I don't know how to wire i up.

One last thing: I wired the mass to GND plugg near the 5V on my arduino, is it good?

Thank you a lot guys!

PS: as you understood, I'm not english (I'm french) so I do apologise for ALL my mistakes.

Hi, do you have a name?

Did you miss something from your schematic? I can’t see how the lower 4 led matrix are driven.

Can you edit your post and make sure the code is indented please, it is difficult to understand without indentation.

I can’t understand exactly what you mean by “one pixel gap”. Can you post a video?

When you try to scan 2 led matrices, you say the leds are less bright. I can think of 2 possible reasons. First, your power supply - is it providing enough current? If you are using the UNO as the power supply, what is the maximum current allowed? Secondly, is your code multiplexing one matrix and then the other, instead of both at the same time? If so, that would make it look less bright, as each led would only be lit for 1/16 of the time instead of 1/8 of the time.

As for using 595 instead of 4017, you would wire it up in just the same way as the others. You will still need the 2803 because it must sink the current from 8 leds at once, which the 595 cannot do. In you code, you must ensure only one of the 8 outputs on the new 595 is high at any time.

You could add 2 more 595’s and another 2803 to drive the lower 4 matrices. You may need to use lower series resistors to maintain the brightness, but take care to not exceed the max current of the 595’s (for each output pin, and each IC as a whole). Check the data sheets page with the title “Limiting values”.

I hope I have answered as many questions as I have asked!

Paul

Hi Paul!
Yeah sure I have a name. My name is Tony.

Yes, I know that the lower matrix are not driven according to the schematic. I didn't know how to drive them so I leave it blank.

Here is the video 1pxl gap - YouTube (1hour ago this issue fixed itself, so I've restarded the arduino and it came back) the upper row is useless so the lower one is cut).

I originaly took the schematic here Lab 15: Scrolling text message on an LED dot-matrix display | Embedded Lab. I took the code but it wasn't build for arduino so I have 6 things I don't know what to do with

void main() {
 CMCON = 0x07;   // Disable comparators
 ADCON0 = 0x00; // Select ADC channel AN0
 ADCON1 = 0b00001110;  // RA0 as analog input
 TRISC = 0x00;
 TRISB = 0xFF;
 TRISA = 0x01;

The brightness isn't my principal issue, I'll fix it later. I prefer focus on the scroling for now.

Thank you a lot for your help you gived me (and you will)!

Here is the full code wich is supposed to be working (different than the one that actualy working)

int DataPin = 11;
int ClockPin = 12;
int LatchPin = 8;
int clock = 9;
int Reset = 10;


void send_data(unsigned int temp){
 unsigned int Mask = 0x0001, t, Flag;
  for (t=0; t<16; t++){
   Flag = temp & Mask;
   if(Flag==0) DataPin = 0;
   else DataPin = 1;
   ClockPin = 1;
   ClockPin = 0;
   Mask = Mask << 1;
  }
  // Apply clock on ST_Clk
  LatchPin = 1;
  LatchPin = 0;

}

/* CharData is a two dimensional constant array that holds the 8-bit column values of
   individual rows for ASCII characters that are to be displayed on a 8x8 matrix format.
*/
const unsigned short CharData[][8] ={
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000100},
{0b00001010, 0b00001010, 0b00001010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010, 0b00011111, 0b00001010},
{0b00000111, 0b00001100, 0b00010100, 0b00001100, 0b00000110, 0b00000101, 0b00000110, 0b00011100},
{0b00011001, 0b00011010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001011, 0b00010011},
{0b00000110, 0b00001010, 0b00010010, 0b00010100, 0b00001001, 0b00010110, 0b00010110, 0b00001001},
{0b00000100, 0b00000100, 0b00000100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000},
{0b00000010, 0b00000100, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000100, 0b00000010},
{0b00001000, 0b00000100, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000100, 0b00001000},
{0b00010101, 0b00001110, 0b00011111, 0b00001110, 0b00010101, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000100, 0b00000100, 0b00011111, 0b00000100, 0b00000100, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00000000, 0b00000000},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000100},
{0b00000001, 0b00000010, 0b00000010, 0b00000100, 0b00000100, 0b00001000, 0b00001000, 0b00010000},
//etc.

{0b00000010, 0b00000100, 0b00000100, 0b00000100, 0b00001000, 0b00000100, 0b00000100, 0b00000010},
{0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100},
{0b00001000, 0b00000100, 0b00000100, 0b00000100, 0b00000010, 0b00000100, 0b00000100, 0b00001000},
{0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00011110, 0b00010100, 0b00000000, 0b00000000}
};

unsigned int DisplayBuffer[]={0,0,0,0,0,0,0,0};
unsigned int speed;
short i, l, k, ShiftAmount, scroll, temp, shift_step=1, StringLength;
char message[]="SCROLLING MESSAGE ON LED DOT-MATRIX DISPLAY FROM WWW.EMBEDDED-LAB.COM ";
char index;
void main() {
 CMCON = 0x07;   // Disable comparators
 ADCON0 = 0x00; // Select ADC channel AN0
 ADCON1 = 0b00001110;  // RA0 as analog input
 TRISC = 0x00;
 TRISB = 0xFF;
 TRISA = 0x01;
 StringLength = strlen(message) ;
 do {
 for (k=0; k<StringLength; k++){
  for (scroll=0; scroll<(8/shift_step); scroll++) {
   for (ShiftAmount=0; ShiftAmount<8; ShiftAmount++){
    index = message[k];
    temp = CharData[index-32][ShiftAmount];
    DisplayBuffer[ShiftAmount] = (DisplayBuffer[ShiftAmount] << shift_step)| (temp >> ((8-shift_step)-scroll*shift_step));
   }

  speed = 10+ADC_Read(0)/10;
  for(l=0; l<speed;l++){

   for (i=0; i<8; i++) {

    send_data(DisplayBuffer[i]);
    clock = 1;
    clock = 0;
    Delay_ms(1);
   }  // i
  Reset = 1;
  Reset = 0;
  } // l
  } // scroll
 } // k

 } while(1);

}

(I cut some code not to exceed the characters limit)

Hi Tony,

I don't think you should worry about those commands you could not translate. I think they are either not be needed on Arduino or are replaced by pinMode ().

The send_data () function can easilly be replaced by the standard Arduino shiftOut () function, I suspect.

I'm sorry but I can't see what is causing your gap problem.

Paul

Thank you for your help guys.
After a period of despair, I tried an other code witch actualy works!

#define A     {B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010}
#define B     {B01111100,B01000010,B01000010,B01111100,B01000010,B01000010,B01000010,B01111100}
#define C     {B00111110,B01000000,B01000000,B01000000,B01000000,B01000000,B01000000,B00111110}
#define D     {B01111100,B01000010,B01000010,B01000010,B01000010,B01000010,B01000010,B01111100}
//cut
#define NUM9  {B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100}


int latchPin = 10;
int clockPin = 13;
int dataPin = 11;
int clock = 9;
int Reset = 8;
int latchPinPORTB = latchPin - 8;
int clockPinPORTB = clockPin - 8;
int dataPinPORTB = dataPin - 8;
int i = 0;
long scrolling_word[8];
int array_turn=0;
byte your_text[8][8]={Q,I,SPACE,W,O,R,L,D};//PUT YOU TEXT HERE


void setup(){
  Serial.begin(9600);
  pinMode(dataPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(latchPin,OUTPUT);
  pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  digitalWrite(Reset,HIGH);
  digitalWrite(Reset,LOW);
  setupSPI();
}

void display_word(int loops,byte word_print[][8],int num_patterns,int delay_langth){// this function displays your symbols
  i = 0;// resets the counter fot the 4017
  for(int g=0;g<8;g++)//resets the the long int where your word goes
    scrolling_word[g] = 0;
  for(int x=0;x<num_patterns;x++){//main loop, goes over your symbols
   // you will need to find a better way to make the symbols scroll my way is limited for 24 columns

   for(int r=0;r<8;r++)//puts the buildes the first symbol
      scrolling_word[r] |= word_print[x][r]; 
    for (int z=0;z<8;z++){//the sctolling action
        for(int p=0;p<8;p++)
          scrolling_word[p] = scrolling_word[p] << 1;
// end of the scrolling funcion
      for(int t=0;t<delay_langth;t++){// delay function, it just loops over the same display
        for(int y=0;y<8;y++){// scaning the display
          if(i == 8){// counting up to 8 with the 4017
            digitalWrite(Reset,HIGH);
            digitalWrite(Reset,LOW);
            i = 0;
          }
          latchOff();
          spi_transfer(make_word(0x01000000,y));// sending the data
          spi_transfer(make_word(0x00010000,y));
          spi_transfer(make_word(0x00000100,y));
          latchOn();
          delayMicroseconds(800);//waiting a bit
          latchOff();
          spi_transfer(0);// clearing the data
          spi_transfer(0);
          spi_transfer(0);
          latchOn();
          digitalWrite(clock,HIGH);//counting up with the 4017
          digitalWrite(clock,LOW);
          i++;
        }
      }
    }
  }
  finish_scroll(delay_langth);
}

void finish_scroll(int delay_scroll){// this function is the same as the funcion above, it just finishing scrolling
  for (int n=0;n<24;n++){
        for(int h=0;h<8;h++)
          scrolling_word[h] = scrolling_word[h] << 1;
      for(int w=0;w<delay_scroll;w++){
        for(int k=0;k<8;k++){
          if(i == 8){
            digitalWrite(Reset,HIGH);
            digitalWrite(Reset,LOW);
            i = 0;
          }
          latchOff();
          spi_transfer(make_word(0x01000000,k));
          spi_transfer(make_word(0x00010000,k));
          spi_transfer(make_word(0x00000100,k));
          latchOn();
          delayMicroseconds(800);
          latchOff();
          spi_transfer(0);
          spi_transfer(0);
          spi_transfer(0);
          latchOn();
          digitalWrite(clock,HIGH);
          digitalWrite(clock,LOW);
          i++;
        }
      }
    }
}

byte make_word (long posistion,byte turn){
  byte dummy_word = 0;
  for(int q=0;q<8;q++){
    if(scrolling_word[turn] & (posistion<<q))
      dummy_word |= 0x01<<q;
  }
  return dummy_word;
}   


  void loop() {

        display_word(1,your_text,8,15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrole slower).
   
       }
  
  

void latchOn(){
  bitSet(PORTB,latchPinPORTB);
}

void latchOff(){
  bitClear(PORTB,latchPinPORTB);
}


void setupSPI(){
  byte clr;
  SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
  //SPCR |= ( (1<<SPR1) | (1<<SPR0) ); // set prescaler bits
  SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
  clr=SPSR; // clear SPI status reg
  clr=SPDR; // clear SPI data reg
  SPSR |= (1<<SPI2X); // set prescaler bits
  //SPSR &= ~(1<<SPI2X); // clear prescaler bits

  delay(10);
}
byte spi_transfer(byte data)
{
  SPDR = data;			  // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;			  // return the received byte, we don't need that
}

Now I have to find out how to do to assign differents text to differents buttons.

It musn’t be hard, I think.

Anyone could help me?

UP!

the line

display_word(1,your_text,8,15);

Displays the patterns stored in the array your_text. So make several arrays containing other words.
like:-

byte your_text[8][8]={Q,I,SPACE,W,O,R,L,D};//PUT YOU TEXT HERE
byte your_text2[8][8]={M,O,R,E,SPACE,T,E,X};
byte your_text3[8][8]={Y,E,T,SPACE,M,O,R,E};

Then in the loop just call the display_word function with the appropriate array depending on your buttons.

Thanxx man.

So I tried to add that:

int buttonPin = 3;
int buttonPin2 = 4;
int buttonPin3 = 5;
int buttonState;
int buttonState2;
int buttonState3;
byte your_text[8][8]={H,I,SPACE,W,O,R,L,D};//PUT YOU TEXT HERE
byte your_text2[8][8]={T,E,S,T,SPACE,NUM2,NUM2,NUM2};
byte your_text3[8][8]={T,E,S,T,SPACE,NUM3,NUM3,NUM3};
void setup(){
  pinMode(buttonPin,INPUT);
  pinMode(buttonPin2,INPUT);
  pinMode(buttonPin3,INPUT);
  buttonState = HIGH;
  buttonState2 = HIGH;
  buttonState3 = HIGH;
}
  void loop()
  {
    buttonState = digitalRead(buttonPin);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    if(buttonState == LOW)  
    {
        display_word(1,your_text,8,15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrole slower).    
    }
    else
    {
      if(buttonState2 == LOW)  
      {
        display_word(1,your_text2,8,15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrole slower).    
      }
          else
          {
            if(buttonState3 == LOW)  
            {
                display_word(1,your_text3,8,15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrole slower).    
            }
          }
      }
   }

...and wire the pushbuttons like that (but on pin 3; 4 and 5)

But it don't realy works so well.

ps:I'd like to scroll the text only 2 times after pushing the button, not looping for years... It must be easy but I haven't found how yet.

But it don’t realy works so well.

How do you mean?

You need to enable the internal pull up resistors on those button pins in the setup function. Try that and then say what it does / what you want it to do.

Yeah it's much better.
Now, if I reset, nothing displays.
When I press the first button, the first text scrolls once. That's cool.
But if I try another button, nothing happens.

But if I try another button, nothing happens.

So look at that code and the succession of if elses, do you need the else?

So look at that code and the succession of if elses, do you need the else?

I've done that to avoid any error if two buttons are pressed together.

I just tried to delete the else but it don't change anything.

I've done that to avoid any error if two buttons are pressed together.

There will be no errors as you say, just one line of text will play and then the other.

You need to put some debug print statements in to see what your code is doing at various parts of the loop. Is it seeing the button press?

You haven't posted all your code so it is impossible for anyone else to check it. You can always attach it using the additional options triangle at the bottom left of the reply box if it is too long to post.

So I tried to debug with Visual studio (with no idea of what I’m doing).
Here is what I found: it says something about the 2nd and 3rd if.

line 164
Condition: when ‘millis()>0 || millis()>1’ is true
Hit count: when hit count is a multiple of 250

(It says that with and without the “else”)

It seems to point the error but I have no idea of what it means.

Le_bon_code_test_modif_bouton.ino (8.53 KB)

So I tried to debug with Visual studio

What and why?
If this is an arduino program then why do you think visual studio will know anything about the arduino libraries built into the IDE.

I downloaded that code and compiled it for a Uno without any error messages at all.

You told me to "put some debug print statements in".
I don't know what you mean, so I ask google and I've done what I found.
If you mean click on "verify" in the arduino prog, I've already done that.

It might be a problem on my buttons' wire.
I'll try different things to find out the matter.

You told me to "put some debug print statements in".
I don't know what you mean,

So you should have asked.

so I ask google and I've done what I found.

You found the wrong thing.

A debug print is what you add to your code like

Serial.print("the code has reached this point");

so you know that the code has reached that point. You can also print out variables to see if they contain what you expect them to.

Ok sorry.

I found what was wrong. The second and third buttons weren't connected to the mass and the +5V. (I didn't know my breadboards strips. I already thought about that but I forgot to verify.
Noob mistake ^__^''

Now I can go to the next step of my project.
Thank you again Grumpy_Mike for all your help. <3

See you