0

I want to make an 8*8 led matrix. I found this code on the web:

i

    int latchPin = 12;  //Pin connected to ST_CP of 1st 74595
    int clockPin = 13;  //Pin connected to SH_CP of 1st 74595
    int dataPin = 11;   //Pin connected to DS of 1st 74595
    
    int latchPin2 = 6;  //Pin connected to ST_CP of 2nd 74595
    int clockPin2 = 7;  //Pin connected to SH_CP of 2nd 74595
    int dataPin2 = 5;   //Pin connected to DS of 2nd 74595
    
    void setup() {
      //set pins to output so you can control the shift register
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
      
      pinMode(latchPin2, OUTPUT);
      pinMode(clockPin2, OUTPUT);
      pinMode(dataPin2, OUTPUT);
    }
    
    void loop() {
      /************** Send HIGH to first Anode pin (16th pin) and LOW to all
      other anode pins (15, 11, 3, 10, 5, 6, 13) of LED matrix *************/    
      
      // take the latchPin low so the LEDs don't change while you're sending in bits:  
      digitalWrite(latchPin, LOW);
      //Send 0 0 0 0 0 0 0 1 (1) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
      shiftOut(dataPin, clockPin, MSBFIRST, 1);
      // shift out the bits:    
      digitalWrite(latchPin, HIGH);
    
      /**************** Send LOW to the first cathode pin (4th pin) and HIGH to all 
        other cathode pins (7, 2, 8, 12, 1, 14 and 9) of LED matrix *****************/    
        
      // take the latchPin low so the LEDs don't change while you're sending in bits:    
      digitalWrite(latchPin2, LOW);
      // Send 1 1 1 1 1 1 1 0 (254) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
      shiftOut(dataPin2, clockPin2, MSBFIRST, 254);
      // shift out the bits:  
      digitalWrite(latchPin2, HIGH);
    }

I expected this code to turn on the first LED, but when I uploaded this code nothing lights up. I checked my rows and colum connections.

Also, I want to ask if a 74hc595 can output sink current?

4
  • what's a first LED? ... what is it connected to?
    – jsotola
    Jan 31, 2021 at 6:23
  • In reverse order, yes about 20ma or so sink and source. If you look on the data sheet it will give you the answer. As far as the first part simple connect this to that and that should fix it. That is about as helpful as the schematic, not a frizzy drawing, you included. You have both hardware and software and knowledge of both is normally required to solve the problem. Show all power and ground connections on the schematic.
    – Gil
    Jan 31, 2021 at 6:52
  • 1
    Have you connected the 5V from the schematic to an external power supply? If yes, did you connect the GND of the power supply to the GND shown in the schematic too? Jan 31, 2021 at 8:20
  • Did saprate power supply needed for this... Jan 31, 2021 at 15:27

1 Answer 1

2

I can't add comment to your question so I post as an answer even though this is not much an answer. This is just a hint to solve your problem.

8x8 led matrix and 595s are pretty low-level stuff, so I assume you have some knowledge about electronics and programming in general.

I think your wiring is OK but I also think you misunderstand how 595 works.

Here is the flow taken from a library (ESP32) for 64x64 RBG LED panel using bunch of 595s:

uint8_t data[8]; // data for one row

digitalWrite(OE_PIN, HIGH); // disable output, 595 outputs go into high impedance state

for (int i=0; i<8; i++) 
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, data[i]);  // dump data out

digitalWrite(LATCH_PIN, LOW);  // pulse 1 clock
delayMicroseconds(1); // note 2*
digitalWrite(LATCH_PIN, HIGH); // latch is active high 

digitalWrite(OE_PIN, LOW); // Enable output 

I think now you know how to fix your code.

Note 1: I find those names SER, SRCLK, RCLK (on TI's datasheet) are confusing. I prefer the names SERIAL DATA INPUT, SHIFT CLOCK, LATCH CLOCK (on ONSEMI MC74HC595 datasheet) or better DATA, CLK, LATCH, OE, RESET.

Note 2: Check 74HC595 datasheet to see clock pulse width limit and speed limit. And if you are using UNO or MEGA (@16MHz), you are good without stretching the clock (data clock and latch clock). If you use higher speed MCU, e.g: ESP32@240MHz or STM32@72MHz, you have to consider clock stretching there and also inside shiftOut() function.

To improve your circuit, you should wire both OE of 595s to a Digital pin. You can also connect both latch pin into one digital pin. Every time you latch, botch 595 latch, and every time you enable output, both enable output.

So with your configuration, just shiftOut data normally for the 595 on the left and invert data for the 595 on the right, like this

#define DATA_COL_PIN 11
#define DATA_ROW_PIN 5
#define CLOCK_COL_PIN 13
#define CLOCK_ROW_PIN 7

#define OE_PIN 4 //use digital pin 4 to enable output on both 595s
#define LATCH_PIN 6 // or 12, but you must connect both latch inputs of both 595s together

uint8_t col = 0b00000001; // for the left 595
uint8_t row = 0b00000001; // for the right 595

digitalWrite(OE_PIN, HIGH);
shiftOut(DATA_COL_PIN, CLOCK_COL_PIN, MSBFIRST, col);
shiftOut(DATA_ROW_PIN, CLOCK_ROW_PIN, MSBFIRST, ~row); // ~row = 0b11111110 = invert_bits(row)
digitalWrite(LATCH_PIN, LOW);
digitalWrite(LATCH_PIN, HIGH);
digitalWrite(OE_PIN, LOW);

The code above is just for you to understand how it works. Normally, they would work on a buffer such as

uint8_t row[8]; // each byte is one row

And they do row scanning, turn one row ON at a time and just flip each column ON and OFF following the byte data of that row.

I stop here as this is going off-topic. You just ask what is wrong with your code right?

BTW, 595 can sink/source 35mA on each pin (70mA in total). So if you want to light up one row at a time with your setup, you should choose each current limiter carefully so that not to exceed 70mA in total.

70mA / 8xLED = 8.75mA for each LED (assume red LED)

(5v - 1v7) / 8.75mA = 377R

It's likely the resistors should be at least 377 ohm or 470 ohm for safety.

2
  • Sry i didn't get it... Are u trying to say instead of putting 8bit value in decimal... I have to make array for it... Feb 1, 2021 at 8:19
  • I'm probably ahead of myself on how people do write a graphic driver for these LED panel by answering like that. It's doesn't matter if a number is written in binary or decimal or hexadecimal. I just use binary because it's straight forward reflecting each bit as a single LED on the matrix. The array of eight 8-bit number has 8x 8-bit = 64-bit, which represents all 64 LEDs on your 8x8 led panel. So you have 2 functions, one to read this array and spit out data to 595s, the other function to modify this array so you have visual effect or animation or changing a static image after some time.
    – SimonVu14
    Feb 1, 2021 at 9:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.