Connecting a 16-pin 64-LED matrix to Arduino via a shift register

I'm trying to string together a few components I have into something. The first step is to control a 64-LED matrix I have from a kit. It have 16 pins, 8 for the columns and 8 for the rows. I've attached a photo of the back of the LED matrix showing the two rows of 8 pins each. I've also attached a Fritzing image that shows my wiring configuration. In the Fritzing image I have the two rows of 8 pins each going out into space as there is no similar LED matrix in the library (there is only a 10-pin version).

I wired it following the ShiftOut tutorial (http://arduino.cc/en/tutorial/ShiftOut), except that in that tutorial the shift register is connected to 8 LEDs via resistors. In my case, it's an LED matrix, so each register matches up to a column or row.

So a few questions:

  1. Just curious, why does the shift register link to power and ground twice?

  2. In the example, each LED is connected via a 220R resistor. That's obviously impossible in a matrix, unless the matrix itself has the resistors. I have no documentation on the matrix, so I don't know. Is it common for LED matrixes to have resistors inside? I think I saw an article somewhere that showed a
    similar 16-pin matrix hooked up directly to an Arduino, but I couldn't find it now.

  3. If I need to add resistors, would I add to each column and row? I did find the following instructable (http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/step8/Current-Limiting-Resistors/) which shows adding resistors to just the cathodes. Considering I have no specs on the LEDs, is there a way to figure out the needed resistance using a multimeter or some such tool?

  4. If you look at my diagram I'm actually connecting two rows and two columns to each register. That's because it's an 8x8 matrix and later on I'm going to be connecting it to a 4x4 keypad and want one button press on the keypad to light up the LEDs that match up to the location of the button on the keypad, which would be 4 LEDs. I'm not sure if this will work, but I am guessing I can send a signal to the right registers and light up 4 LEDs instead of 1, as long as I get the resistance calculated correctly - which is a bit more complicated with two LEDs, so any help here would be appreciated.

  5. Once I get the hardware configured correctly, how do I program the Arduino to properly address the matrix? Is there a library for using a shift register to control an LED matrix such as this, or do I just use ShiftOut or the SPI libraries to address the hardware directly? Does anyone know of write-ups of similar setups online?

Thank you.

trauring:

  1. Just curious, why does the shift register link to power and ground twice?

Two are the actual power pins of the chip. The other two are control inputs and it just so happens that to get the shift register to work in the required way, one needs to be connected to ground and the other needs to be connected to 5V. But the chip draws no (significant) power from those other connections.

trauring:
2) In the example, each LED is connected via a 220R resistor. That's obviously impossible in a matrix, unless the matrix itself has the resistors. I have no documentation on the matrix, so I don't know. Is it common for LED matrixes to have resistors inside? I think I saw an article somewhere that showed a
similar 16-pin matrix hooked up directly to an Arduino, but I couldn't find it now.

No, the matrix will not have any internal resistors. You still need to add the external ones, or the Arduino and/or the matrix could be damaged. There are indeed many articles where matrices and other leds are shown connected directly to Arduino outputs without series resistors. They are all wrong. The authors may have got away with it, or they might have damaged or at least reduced the life of their components.

trauring:
3) If I need to add resistors, would I add to each column and row? I did find the following instructable (http://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/step8/Current-Limiting-Resistors/) which shows adding resistors to just the cathodes. Considering I have no specs on the LEDs, is there a way to figure out the needed resistance using a multimeter or some such tool?

Yes. Start with a safe resistor to use, eg 1K. Connect one column to 0V with wire and one row to 5V using the resistor. One led should light, not very bright. If it does not, try the column to 5V with wire and the row to 0V with the resistor. Once an led lights, you can measure the voltage drop across the matrix with your multimeter (between the row pin and the column pin you connected). It will probably be around 1.8 to 2.4V depending on the colour of the leds. This is known as the "forward voltage" of the leds. Lets say it is 2V.

The maximum continuous current the leds can cope with is probably 20mA. Some can take 30mA, but without a data sheet, the only way to know is to test to destruction, and I'm sure you don't want to do that.

So for example if your led's forward voltage is 2V and your power supply is 5V, your series resistor is needed to "drop" the other 3V. Unlike leds, resistors follow Ohm's Law, which says I = V / R or R = V / I (where R is the resistor value in Ohms, I is the current in Amps and V is the voltage in Volts). We want 20mA = 0.02A current to flow, and we have 3V across the resistor, so the resistor value should be 3 / 0.02 = 150 Ohms.

Paul

trauring:
I have no specs on the LEDs

Usually there is a code printed on the white plastic side of the matrix. Try Googling for that.

trauring:
there is no similar LED matrix in the library (there is only a 10-pin version)

There is a 8x8 matrix in the Fritzing library that only has 10 pins? A single-digit 7-seg display would probably have 10 pins, but every 8x8 matrix I ever saw needs 16 pins.

trauring:
4) If you look at my diagram I'm actually connecting two rows and two columns to each register.

I don't understand and I can't see that on your diagram.

To run the matrix, you will need two 74xx595 shift registers, or one register and 8 Arduino outputs. The 8 matrix rows can then go to one register and the 8 columns to the second register or the Arduino pins, or vice versa.

That can work, but there is a danger of overloading and damaging the Arduino or the shift register. To prevent that, you must use much higher value series resistors than the ones we calculated above. This is because the 74xx595 register has a maximum total current of 70mA for the whole chip, so that's less than 10mA for each row/column. The Arduino's maximum is around 200mA, so it can provide 20mA to each row or column.

Sounds great, but there is another problem! We have not yet discussed the technique called multiplexing, which is needed to drive a matrix like this. To do that, one shift register pin, or one Arduino pin, must provide enough current for up to 8 leds. They can't do that, unless you choose very high series resistors, and then the leds will be very dim indeed.

To overcome that problem, you can use 8 transistors. Or you can use a special version of the shift register called a tpic6c595, which has high-current outputs.

But the easier and better solution is to use a max7219 or max7221 chip. These make the whole thing far easier. Only one resistor to set the maximum led current, no transistors, one chip to drive the 8x8 matrix. But you won't learn as much using that chip!

You need a MAX7219. :grinning:

The best way to do it for experimentation - as I see it - is to get one of these kits from eBay.
![|500x500](http://i.ebayimg.com/00/s/ODAwWDgwMA==/z/RA8AAOxyFiRRzS3N/$(KGrHqFHJF!FG3+JipWNBRzS3My2sg~~60_57.JPG)

I like these kits more than the one above:
http://www.electrodragon.com/product/dot-matrix-chain-display-kit-max7219-v2/

Not only are they cheaper, but the 7219 mounts underneath the matrix and the layout of the PCB allows chaining them together directly using simple header jumpers.

The other design above, which seems to be quite common, kind of sucks when you want to create a chain of them since you have use 4 pin header cables to connect them together, which eats up additional space and adds more cost.

--- bill

bperrybap:
The other design above, which seems to be quite common, kind of sucks when you want to create a chain of them since you have use 4 pin header cables to connect them together, which eats up additional space and adds more cost.

I know. That's why I cautiously specified "for experimentation". The ones you cite are clearly superior though they are in fact more expensive unless you run up a bulk order for five of them and a few other things to cover the postage. I have chased a couple (not quite the same, using the SMD chip version supplied ready-mounted) down on eBay auction, yet to assemble them.

Noted that web page pointed out that the jumpers foul the matrix units so that they do not seat fully. Probably not a big problem but if you do not mind the extra overall depth, you can simply mount the jumper headers (and of course, the end termination) on the other side. And a pity they do not seem to sell the green version (for a reasonable price).


I have a complete LED cube kit yet to assemble. I did have a mind to make a single-colour LED cube using one of the less useful MAX7219 boards.

Thank you all for your help. Sorry for the delay in responding but for some reason I received no notifications of responses (even though I signed up to receive them). In any case, I appreciate the guidance here. I am aware of the MAX7219/MAX7221 chips and have some on order from China, but I was hoping to figure out how to drive the matrix with what I have on hand - mostly as a learning experience.

By the way, that kit from eBay is cheaper from BangGood (MAX7219 Dot Matrix Module DIY Kit SCM Control Module Sale - Banggood USA-arrival notice-arrival notice) where it costs $2.50 and shipping is free (as opposed to $2.95 + $1.98 shipping). The Electrodragon kit does look better designed (especially since you can string them together) but I'm not planning to do that for this experiment.

Good advice on Googling the number on the side, although I only got mentions of it in Chinese.

I'll take a look again and see what I can do (or wait for the MAX7221 chips I have on order to arrive).

trauring:
I was hoping to figure out how to drive the matrix with what I have on hand - mostly as a learning experience.

What else do you have on hand? The parts you mentioned in your first post are not enough. Do you have 8 outputs free on the Arduino? Do you have 8 transistors of some kind? Do you have a ULN2803 chip?