Electronic – arduino – 74HC595 8x16led matrix arduino

arduinoledled-matrixmultiplexer

I'm currently trying to learn how multi shifting is working and have therefore started a project where I wanna drive 2X 8×8 LED matrix with an Arduino. I have found it that I should work with the 74HC595 chip.

This is the schematic I'm using to try out how the chip works.

Scematic over 8x8

But when I use this with the following code, it doesn't light every LED up and some of them are less bright than the rest.

#define DATA 10
#define CLOCK 11
#define LATCH 12

void latch();
uint8_t pic[] = {250,250,250,250,250,250,250,250};

void setup() {
  pinMode(DATA, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(LATCH, OUTPUT);
}

void loop() {
  for (int i=0; i<8; i++) {
    shiftOut(DATA, CLOCK, LSBFIRST, ~pic[i]);
    shiftOut(DATA, CLOCK, LSBFIRST, 128 >> i);
    latch();
    //delay(100);
  }

}

void latch() {
  digitalWrite(LATCH, HIGH);
  delayMicroseconds(10);
  digitalWrite(LATCH, LOW);
  delayMicroseconds(10);
}

8x8 LED matrix Error Light

What can cause that? Do I have bad wiring? or bad code?

UPDATE

I have tested my LED matrix with the code from @vicatcu. First I found a lot of bad connections they are now fixed, I hope..

Now I have found 2 full columns, 1 full row and a couple of other LED's that don't light up, the middle row where there are 3 LED's that don't light up is light up when I set everything to 0 instead of 250.

LED matrix 2.0

If I remove the "~" from the code then I get this:

LED'matrix removed ~

Update 2

I tried @James idea and moved the resistors from the columns to the rows, but that didn't fixe the problem rather it just moved some of the on light pixels
Scematic over 8x8 2.0

8x8 LED matrix Error Light 2.0

Best Answer

Lets analyze what's going on here. The code is implementing a multiplexing scheme, which is to say at any given moment, only one row of LEDs is being "addressed" (i.e. 128 >> i, the row addressed by the i-th bit). I'd advise you to rename the variable called SHIFT to CLOCK as that is what most people will expect it to be called. Usually the variable you call STORE is called LATCH. You should declare int pic[] as uint8_t pic[] instead so it's the right size (8-bits instead of 16-bits) for what you are trying to express as well.

All of that said, I don't think any of it explains the outcome in the picture. I think it's more likely a wiring error of some kind or an power issue. Can the 74HC595 source / sink 100mA? Because that is what you are asking of it with 8 LEDs, a 5V power source, and 220 Ohm resistor.

I would start with a much more simple sketch that allows you to stimulate each pixel of the matrix individually, and in a way that is under your control through the serial terminal, for example. Something like this:

#include <stdint.h>

#define DATA 10
#define SHIFT 11
#define STORE 12

uint8_t row = 0, col = 0;

void store();

void setup() {
  Serial.begin(9600);
  Serial.println("Test One LED at a time");
  pinMode(DATA, OUTPUT);
  pinMode(SHIFT, OUTPUT);
  pinMode(STORE, OUTPUT);

  // initialize the shift registers
  shiftOut(DATA, SHIFT, LSBFIRST, 0);
  shiftOut(DATA, SHIFT, LSBFIRST, 0);   
  store();

}

void loop() {
  if (Serial.available()) {
    Serial.read();
    Serial.print("Lighting row "); Serial.print(row);
    Serial.print(" and column "); Serial.println(col);

    uint8_t rowval = (1 << row);
    uint8_t colval  = ~(1 << col);
    shiftOut(DATA, SHIFT, LSBFIRST, colval);
    shiftOut(DATA, SHIFT, LSBFIRST, rowval);   
    store();

    col++;
    if (col > 7) {
      col = 0;
      row++;
      if (row > 7) {
        row = 0;
      }
    }
  }
}

void store() {
  digitalWrite(STORE, HIGH);
  delayMicroseconds(10);
  digitalWrite(STORE, LOW);
  delayMicroseconds(10);
}

And just see if you can get each LED to light up one at a time. Make sure you configure the Serial Monitor to have "no line ending" and for every character you send, the LED will advance by one position in row major order. At startup, no LEDs should be illuminated.