0

so I'm playing around with an 8x8 RGB matrix using a 74HC595 shift register for each of the colors. I've done this before with single color matrices and everything worked fine, but here I'm getting some weir behavior that I can't really understand.

All 3 74HC595's are wired identically: MR - 5v, OE - Ground, VCC - 5v, GND - Ground

Latch and clock are shared between the registers.

The result:

enter image description here

This is not how it should look, do I have a timing issue somewhere? Thanks in advance!

The code:

int clock_pin = 3; // SH_CP
int latch_pin = 4; // ST_CP

int r_data_pin = 2;  // DS
int g_data_pin = A0;
int b_data_pin = A1;

int row1 = 5;
int row2 = 6;
int row3 = 7;
int row4 = 8;
int row5 = 9;
int row6 = 10;
int row7 = 11;
int row8 = 12;

const int row_count = 8;
const int col_count = 8;

void setup() {
  Serial.begin(9600);

  pinMode(row1, OUTPUT);
  pinMode(row2, OUTPUT);
  pinMode(row3, OUTPUT);
  pinMode(row4, OUTPUT);
  pinMode(row5, OUTPUT);
  pinMode(row6, OUTPUT);
  pinMode(row7, OUTPUT);
  pinMode(row8, OUTPUT);

  pinMode(clock_pin, OUTPUT);
  pinMode(latch_pin, OUTPUT);

  pinMode(r_data_pin, OUTPUT);
  pinMode(g_data_pin, OUTPUT);
  pinMode(b_data_pin, OUTPUT);

  digitalWrite(latch_pin, HIGH);
  digitalWrite(clock_pin, HIGH);

  digitalWrite(r_data_pin, HIGH);
  digitalWrite(g_data_pin, HIGH);
  digitalWrite(b_data_pin, HIGH);
}

namespace RGB {

typedef struct pixel {
  byte r;
  byte g;
  byte b;
};

}

int r_data[8][8] = {
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0}
};

int g_data[8][8] = {
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0}
};

int b_data[8][8] = {
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {0, 1, 1, 0, 0, 1, 1, 0},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1, 1},
  {0, 1, 1, 0, 0, 1, 1, 0}
};

void loop() {
  for (int row = 0; row < 8; row++) {
    digitalWrite(latch_pin, LOW);

    if (row == 0) digitalWrite(row1, HIGH);
    if (row == 1) digitalWrite(row2, HIGH);
    if (row == 2) digitalWrite(row3, HIGH);
    if (row == 3) digitalWrite(row4, HIGH);
    if (row == 4) digitalWrite(row5, HIGH);
    if (row == 5) digitalWrite(row6, HIGH);
    if (row == 6) digitalWrite(row7, HIGH);
    if (row == 7) digitalWrite(row8, HIGH);


    for (int i = 0; i < 8; i++) {
      digitalWrite(clock_pin, LOW);

      digitalWrite(r_data_pin, r_data[row][i]);
      digitalWrite(g_data_pin, g_data[row][i]);
      digitalWrite(b_data_pin, b_data[row][i]);

      digitalWrite(clock_pin, HIGH);
    }
    delay(1);
    if (row == 0) digitalWrite(row1, LOW);
    if (row == 1) digitalWrite(row2, LOW);
    if (row == 2) digitalWrite(row3, LOW);
    if (row == 3) digitalWrite(row4, LOW);
    if (row == 4) digitalWrite(row5, LOW);
    if (row == 5) digitalWrite(row6, LOW);
    if (row == 6) digitalWrite(row7, LOW);
    if (row == 7) digitalWrite(row8, LOW);
    digitalWrite(latch_pin, HIGH);
  }
}
5
  • 1
    Same hardware & software as before when it worked? Just different display using 3 times the number of LEDs (Red, Green & Blue) to make white colored light? I would first check the power supply to see if it can handle the new load with out dropping the voltage and causing all kinds of problems with the processor and peripheral logic. – st2000 May 27 '17 at 13:15
  • @st2000 The arduino is powering everything, how can I use a separate power supply? – MustSeeMelons May 27 '17 at 16:08
  • 1
    You should be able to power the Arduino separately from the 74HC595 (which are assumed to be driving the LEDs) if you connect the grounds of the two power sources together and the two power sources are of the same voltage. However, it would be simpler to use a single power source with about twice the current capacity that you would expect to draw. Other considerations: If you are using the Arduino's on board 5 volt regulator you need to stay under the upper current capacity of that regulator. Again, this is assuming the problems you are having are related to a weak power source. – st2000 May 27 '17 at 16:45
  • 1
    With out changing any hardware, consider changing the software to only light 1 or 2 LEDs to see if the Arduino acts as expected when using a smaller amount of current to light less LEDs. – st2000 May 27 '17 at 16:48
  • @st2000 Figured out how to use an external power supply, sadly it's only 3.3V, tried to use it but I still get an incorrect "image". I have not added no resistors for the LED's, maybe I should? I get some minor flicker in LED's which should not light up. – MustSeeMelons May 27 '17 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.