URG Controlling a led matrix with picture 1 changing to pic 2 then back to pic 1

hI GUYS I AM HAVING PROBLEMS WITH MY CODE AS SOMETHING IS WRONG BUT I DONT KNOW WHAT.Arduino sketch debugging say no problems.However it is supposed to display two messages by displaying message 1 wait 5 secs display message 2 wait 5 secs display message on an 8x8 led matrix.However it is displaying randoms leds. not the two pics in sequence.The code for inspection is below

// Project 23 - Displaying an Image on an LED Matrix
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595
#define CLOCK 10 // connect to pin 11 on the 74HC595
byte hfd[] = {
  B00000101,B00000111, B00000101, B0000000,
  B00110111, B01010001, B01010111,B00110001 };
  
  byte dadx[] = {
  B00100011, B00000101, B1110101, B10001011, B1010011,
  B00100101, B01010101, B10001011};

int binary[] = {
  1, 2, 4, 8, 16, 32, 64, 128};
void setup()
{
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
}
void loop()
{
  int i;
  for ( i = 0 ; i < 16 ; i++ )
  {
    digitalWrite(LATCH, LOW);
    shiftOut(DATA, CLOCK, MSBFIRST, ~hfd[i]); // columns
       digitalWrite(LATCH, LOW);
       delay(5000);
        digitalWrite(LATCH, HIGH);
       shiftOut(DATA, CLOCK, LSBFIRST, binary[i]); // rows
         shiftOut(DATA, CLOCK, MSBFIRST, ~dadx[i]); // columns
    shiftOut(DATA, CLOCK, LSBFIRST, binary[i]); // rows
    digitalWrite(LATCH, HIGH);
    delay(5000);
   
  }
}

Any questions feel free to ask.
Daniel.
Its for my dad for fathers day.

Hi, this is for Father's Day 2015, right? I'm afraid your sketch reveals you have quite a lot of learning to do to understand multiplexing.

Post a schematic of your circuit, we should probably check that for mistakes first, before any components are damaged. Hand drawn will be fine as long as it is neat enough. Don't forget things like resistor values.

Paul

The circuit diagram is in the attachment. It works fine with single images and scrolling images but with two images joined together.
Thanks Daniel

Hi Daniel, that circuit looks, well... not great. I'm not sure how long it will last. But if you say it works, then ok I suppose. What do the first 2 pictures show, your connections to the matrix? Also I asked you not to miss off the values of resistors, so what are those?

You say you have it working for other patterns? Did those sketches come from the book/internet, written by someone else? Can you post one please (the shortest one), it will help us figure out the correct way to control the shift registers.

The first two pictures show what pin on the serial register is attached to what pin on the led matrix.The value on all the resistors are 680ohms.I mean i have got the two pics working indivualy so they are on their own.The code for one of the pics is below

// Project 23 - Displaying an Image on an LED Matrix
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595
#define CLOCK 10 // connect to pin 11 on the 74HC595
byte dadx[] = {
  B00100011, B00000101, B1110101, B10001011, B1010011,
  B00100101, B01010101, B10001011};
int binary[] = {
  1, 2, 4, 8, 16, 32, 64, 128};
void setup()
{
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
}
void loop()
{
  int i;
  for ( i = 0 ; i < 8 ; i++ )
  {
    digitalWrite(LATCH, LOW);
    shiftOut(DATA, CLOCK, MSBFIRST, ~dadx[i]); // columns
    shiftOut(DATA, CLOCK, LSBFIRST, binary[i]); // rows
    digitalWrite(LATCH, HIGH);
    delay(1);
  }
}

Thanks
Daniel

In the interests of getting this thing working before Father’s day is over, I have had a go at fixing your sketch. Normally I would not do this because if someone does something like this for you, you don’t really learn very much.

Give this a go.

// Project 23 - Displaying an Image on an LED Matrix

#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595
#define CLOCK 10 // connect to pin 11 on the 74HC595

byte hfd[] = {
  B00000101,
  B00000111,
  B00000101,
  B00000000,
  B00110111,
  B01010001,
  B01010111,
  B00110001 };
  
byte dadx[] = {
  B00100011,
  B00000101,
  B01110101,
  B10001011,
  B01010011,
  B00100101,
  B01010101,
  B10001011};

int binary[] = {
  1, 2, 4, 8, 16, 32, 64, 128};
  
void setup() {
  pinMode(LATCH, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
}

void loop() {
  
  unsigned long startTime = millis();
  
  while ( millis() - startTime < 5000 ) {
    for ( int i = 0 ; i < 8 ; i++ ) {
      digitalWrite(LATCH, LOW);
      shiftOut(DATA, CLOCK, MSBFIRST, ~hfd[i]); // columns
      shiftOut(DATA, CLOCK, LSBFIRST, binary[i]); // rows
      digitalWrite(LATCH, HIGH);
      delay(1);
    }
  }
    
  while ( millis() - startTime < 10000 ) {
    for ( int i = 0 ; i < 8 ; i++ ) {
      digitalWrite(LATCH, LOW);
      shiftOut(DATA, CLOCK, MSBFIRST, ~dadx[i]); // columns
      shiftOut(DATA, CLOCK, LSBFIRST, binary[i]); // rows
      digitalWrite(LATCH, HIGH);
      delay(1);
    }
  }
}

It works thanks so much

Great Daniel! We got it working for your dad.

With those 680R resistors, the shift registers are overloaded, so it may not work forever. If you want to re-make it some day, I would suggest using a chip called a max7219. Its ideal for 8x8 matrices.

Paul

My dad loved it.
I have some questions
Why would the SR be overloaded when the resistors are between the matrix and the chip not between the arduino and the matrix?
For future projects involving two colours how would i adapt the code to show one slide green and the other side red.Also it is difficult to add a third or fourth shift register to cater for the additional pins.

Also why do you need mills() in this line

while ( millis() - startTime < 10000 )

Thanks again
Daniel

danield123–:
Why would the SR be overloaded when the resistors are between the matrix and the chip not between the arduino and the matrix?

Because the shift registers have their limits too. If you read the data sheet for the 74hc595 (not easy, it will be some time before they make much sense) it says that each output pin of the chip can source or sink at most 20mA. Overall the chip can source or sink only 70mA. That’s not very much. But this chip wasn’t really designed for driving leds. With 680R resistors, each led will use about 4~5mA. If an entire row or column of leds is on at the same time, any one of the shift register pins might have to either source or sink nearly 45mA. The chip manufacturer will not guarantee that the chip will work with that much current. It might be OK for years or it might last only minutes before it becomes damaged.

danield123–:
For future projects involving two colours how would i adapt the code to show one slide green and the other side red.Also it is difficult to add a third or fourth shift register to cater for the additional pins.

You can easily add more shift registers, daisy-chaining them up as you have done with two at the moment. Changing the code is easy. The hardware is more difficult. With your current design, the shift registers would still be overloaded. Unfortunately my recommendation of the max7219 does not work very easily with a two colour matrix.

Strangely enough, it might be easier to go straight to a full RGB matrix, as long as the leds are the ws2812 kind. These leds each have a built-in driver chip, making them easy to control directly by the Arduino without any other chips.

danield123–:
Also why do you need mills() in this line

while ( millis() - startTime < 10000 )

Well, you wanted the second pattern to be displayed for 5 seconds after the first pattern had been displayed for 5 seconds. The millis() function tells you how many milliseconds have passed since the Arduino was powered up or reset. At the start of loop(), the variable startTime is used to record this “time”. By comparing it to the current value of millis(), the sketch can tell how much time has passed since then. The first while() loop compares this difference to 5000 to detect when 5 seconds has passed. The second while() loop runs until 10 seconds has passed.