parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:47 am

Hi everyone,

I am a beginner with the Raspberry Pi and with this forum, so if I'm doing anything wrong please let me know ;). I bought a single-colour LED matrix display (https://www.adafruit.com/products/860) and I know how to light up an individual light by wiring up the columns to positive and the rows to negative and I also know how multiplexing works. But, I have a very limited knowledge of the GPIO and I only know how to light up a single or multiple LED's in a parallel circuit by connecting the cathode on the LED to the ground GPIO pin. This means that I can only control where the positive input goes in (on the columns) but I have no way of controlling the negative output (in the rows). I was wondering if anyone could explain it to me or point me in the right direction of a tutorial.

- Thanks, Parker

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 8:41 am

Not sure how much help I can be but what will do the multiplexing did you get a chip or are you wanting the Pi to do it all I am not sure if the Pi can all by itself but do think it is possible. There are 17 pins for the Pi to use 8 General purpose and the rest can have other purposes.


First place I think to start is with the library python, C, Java is there one you prefer over the other?
You could start with https://projects.drogon.net/raspberry-pi/wiringpi/ their is something for every language. Probably just start out with controlling one row of lights then more depending on your skill.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 2:28 pm

Thanks for the response,

I am already familiar with the Python GPIO library and I can make LED's turn on when wired directly to the GPIO pins and I am advanced with Python so I would rather write my own library, for the fun of it. The problem I'm having is that I have a limited knowledge of electronics and I only know how to make the positive current flow from a general purpose pin to the ground pin. With an LED matrix I will need to be able to "specify" where the ground output is going too, because if I wire all rows to the same ground pin, a whole column will light up even if I'm trying to light up just one light.

- Thanks, Parker

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 2:52 pm

I have a few matrix boards and when I thought I understood it I realized I only knew enough to get in trouble. I think for myself at least once I do get it I will realize how easy it is. It's just that it's so easily overcomplicated through explanation. I did find this and I think it might help at least I hope it does http://www.create.ucsb.edu/200C/2008_St ... tabile.pdf

Weak example but the leds across are pins 1 to 8 and the leds down are pins 1 to 8 can be how some are setup. So 1,1 turns on one led 8,1 would turn on the entire row all pins across the top are hot but only one pin down the side is set. I think different layouts give different results.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:22 pm

Thanks again,

I now understand how the LED matrix works (positive current through a column, ground current through a row, to light up the intersecting LED) but what I don't understand is how I can change a GPIO pin from positive to negative. My explanation isn't so great so how about a diagram:
Capture.PNG
Capture.PNG (29.48 KiB) Viewed 18263 times
As you can see, pins 1 - 5 are negative wires and are connected to the rows of the LED matrix and pins 6 - 10 are positive wires and are connected to the columns of the LED matrix. I know how to sent positive current out of a GPIO pin, but I don't know how to accept negative current from the pin I would like. Hope this helps you understand my problem.

- Thanks, Parker

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:44 pm

I think that's the problem you don't use negative pins. Don't quote me on this I am no expert but a shield from what I got out of that uses a.... sorry I work graves getting to end of shift.

They use a transistor? so a switch that compensates for two positives passing through. That is why for a 16 pin shield you need 16 pins not 8 pins and 8 tied to negative. That setup works but as your experiencing it only controls a row not a single led.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:50 pm

I'm not very good with using resistors and other components to wire things together, but I think I somewhat understand. Do you think you could find me a tutorial or some explanations on how to find the right resistors and wire them up?

- Thanks, Parker

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:51 pm

The other thing to consider is:
in each row and column, it is not possible to
control each individual LED at the same
time. Instead, the matrix is controlled by
cycling through each row very quickly while
triggering the correct column pins to light
the desired LED’s for that particular row. If
the switching is done at a quick enough
rate, there will be no visible flicker and the
LED matrix display will appear to have each
LED turned on at the same time. This works
because of the principle known as
Persistence of Vision, which is the theory
that the retina of the human eye retains an
image for about a tenth of a second. Thus
an LED matrix must be very precisely
controlled, with the Rows being scanned
through sequentially at a rate greater than
about 40Hz (to be safe) while sending out
the column data at the exact same rate.
This kind of control is most easily
accomplished with the aid of a
microcontroller,
This is where I get lost as it seems so easy yet gets complicated so quickly for me
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 3:52 pm

I have collected these posts on the matrix board I own

http://www.raspians.com/pi-matrix-demo/

http://www.raspians.com/pi-matrix-8x8-led/
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Sun Mar 24, 2013 4:01 pm

Thanks for your help, I understand it a little better I'll just have to do a bit more researching, I'll post again if I have any other questions. This is what I found on the topic: http://www.appelsiini.net/2011/how-does-led-matrix-work

- Thanks, Parker

m0rgo
Posts: 6
Joined: Wed Mar 20, 2013 10:00 pm

Re: Raspberry Pi LED Matrix with GPIO

Tue Apr 02, 2013 7:25 pm

I have just made up a circuit to drive a 8x8 matrix, with a 'Slice of PI/O' board.
This gives me 16 outputs from the board, plus another 8 standard GPIO outputs if I want them.

I have a 330 Ohm resistor current limiting resistor in series with the positive side to the LED (supply = 3.3 V DC) - this should limit the LED current to 10 mA, which I have always found adequate for an LED, even though 20 - 20 mA may be spec'd.

Currently, the negative side is switched via 2N3904 transistors with a 10k resistor in the base, to limit the base - emitter current. I could use a smaller resistor but I don't want to overdrive the transistor - and I have the resistors available anyway.

The positive side is directly driven by the 8, MCP23017 bank A outputs, with the bank B outputs going to a transistor, via the resistor, to switch the 'ground' to complete the circuit.

I have limited the 'on' LEDs to one or two, as I don't want to draw too much current via the IC and fry it.
Depending on who you believe, there may be less than 200 mA spare from the Pi.

If I switch on all the 64 LEDs, I would need to supply 640mA - which is more than is going to be available from the RPi.

My next move is to drive the positive side via transistors and have a separate DC supply to the matrix circuit. This is so I can switch on as many LEDs as I want without risking damaging the Pi or 'Slice of Pi/O' board.

It is a little unfortunate that the 8x8 matrix unit is not configured with the pins positive one side and negative the other, but 4 +ve and 4 -ve each side with the relationship crossed over. Not a great problem, just makes the wiring twisted. I'm sure there is a good reason for doing it, just haven't figured it out yet.

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Tue Apr 02, 2013 8:02 pm

Thanks for the reply!

This is what I was wondering about, I understood how to control which positive (column) pins on the matrix received power, by turning on or off the GPIO pins. But I didn't understand how I could control which negative (row) pins could drain power to ground. If I have understood correctly, you are using 8 transistors (one for each row) to control flow from the negative pins?

- Parker

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Sun Apr 07, 2013 2:52 am

Ok, I've got a status update for everyone, and an issue.

I've got everything wired up in a way where I have 16 positive "control" pins, and one ground pin (visible on the left of the photo) to control the matrix. When I apply positive power to the first control pin, it inputs positive current into the first column of the matrix, and, when I apply positive power to the ninth control pin, it sends power to the base of a transistor which allows current to flow from the negative ground control pin to the first row of the LED matrix, this should light up the top-left LED.

But, this doesn't work, this is what I think is happening - when my 3V power supply is applied to the base of the transistor, the positive current begins to fight the negative current flowing through the transistor, this lowers the overall output to something less than 0.5V which is not sufficient to power the matrix. In the second photo I have attached, I place an LED between the first control pin and the base of the transistor, this lowers the amperage of the current fighting the negative current through the transistor, and the LED matrix turns on.

Is there any better way I can make this work? I realize I could use resistors to lower the base current going into the transistors, but finding the right Ohm resistors can be quit the hassle.

Thanks for the help!
http://www.mediafire.com/view/?nzvo9jpzbv4z3nc
http://www.mediafire.com/view/?tdi23ly547u8ar1
Last edited by parkerhoyes on Thu Apr 11, 2013 1:53 pm, edited 2 times in total.

User avatar
Burngate
Posts: 6437
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Raspberry Pi LED Matrix with GPIO

Mon Apr 08, 2013 10:55 am

parkerhoyes wrote:... what I think is happening - when my 3V power supply is applied to the base of the transistor, the positive current begins to fight the negative current flowing through the transistor, this lowers the overall output to something less than 0.5V which is not sufficient to power the matrix. In the second photo I have attached, I place an LED between the first control pin and the base of the transistor, this lowers the amperage of the current fighting the negative current through the transistor, and the LED matrix turns on.
I'm not sure I understand what you mean here, but I get the feeling you don't fully understand how transistors work.

Would it be possible to give us a circuit diagram of how you have things connected up?

pixiecherub1950
Posts: 2
Joined: Tue Jan 22, 2013 3:03 am
Location: London, U.K.

Re: Raspberry Pi LED Matrix with GPIO

Thu Apr 11, 2013 4:47 am

[quote="parkerhoyes"]Ok, I've got a status update for everyone, and an issue.

I've got everything wired up in a way where I have 16 positive "control" pins, and one ground pin (visible on the left of the photo) to control the matrix. When I apply positive power to the first control pin, it inputs positive current into the first column of the matrix, and, when I apply positive power to the ninth control pin, it sends power to the base of a transistor which allows current to flow from the negative ground control pin to the first row of the LED matrix, this should light up the top-left LED.

But, this doesn't work, this is what I think is happening - when my 3V power supply is applied to the base of the transistor, the positive current begins to fight the negative current flowing through the transistor, this lowers the overall output to something less than 0.5V which is not sufficient to power the matrix. In the second photo I have attached, I place an LED between the first control pin and the base of the transistor, this lowers the amperage of the current fighting the negative current through the transistor, and the LED matrix turns on.

Is there any better way I can make this work? I realize I could use resistors to lower the base current going into the transistors, but finding the right Ohm resistors can be quit the hassle.

Thanks for the help!

Hi there,

Just a few words to get you started on the right track, but we really do need a few more details such as:
1) A circuit diagram, and the part number/s of the transistors that you have used.
2) Details of the Power Supply that you are using to drive the LED matrix at the moment!

a) Is it coming directly from the 3Volt battery pack that we can see at the top, and do you have a current limiting resistor in series with the column that you are trying to light up, or (as I suspect),
b) It is coming directly from the battery pack, and there is NO limiting resistor.

3) Try replacing the link in the the Column connected to the top left matrix LED with a 75 Ohm resistor. This is calculated as RLim = Supply Voltage(3V) - (LED Voltage (2.1V) + VCEsat (~0.15V))=0.75V therefore RLim = V/I = 0.75V/0.01A(10mA) =75 Ohms

4) As far as originally connecting 3V directly to the Base of the Row transistor was concerned, you again need a resistor to limit the current into the base otherwise the forward biased B-E junction tries to maintain a constant 0.6V or so across itself, and drags too much current out of the batteries, which (luckily in this case) they cannot supply!

When you replace the jumper with the red LED you are are ,fortunately, adding the forward voltage of the red LED (about 1.6V)to the forward voltage of B-E junction of the transistor (about 0.6V). This luckily gives around 2.1-2.2V, which is just about enough, given that the yellow LED in the 8x8 matrix needs about that voltage to light up! Given that your batteries are probably getting fairly used up by now, you are fortunate that you didn't destroy anything. Just don't be tempted to replace them with new ones without adding both the resistor in the column line anything from 68 to 82 Ohms should give you about 10mA through the Yellow LED at 3V supply.

Replace the Red LED with a resistor calculated as for column resistor above, but using a rule of thumb that to fully turn on the transistor the base current should be about 1/10th to 1/50th the collector current, depending on the current gain of the transistor.
Using relevant parameters Voltage VBE (approx 0.6V) and Supply Voltage (3V) Resistor Base = Supply Voltage(3V) - VBE(0.6V) = 2.4V therefore RBase = 2.4V/0.001A (1mA) =2,400 (2k4) Ohms. But anything around 1k to 10k should work for now!

This should get you started, at least.

Finally, I must congratulate you on the very neat job that you have made on your breadboard layout.
pixiecherub1950

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Thu Apr 11, 2013 1:48 pm

Thanks for the reply!

Ok, you've cleared up a lot of my questions. I am not using any resistors in this circuit what so ever. I'll start working on adding in some resistors as you've mentioned. But one issue remains, GPIO pins #3 and #5 remain powered regardless of how I program them using python, does this have anything to do with the fact that they are labeled "IC2 Bus"?. I've also done the best I could making a circuit diagram (see attached), although it's fairly crude it should clear some things up.
Matrix Circuit Diagram.png
Matrix Circuit Diagram.png (35.68 KiB) Viewed 17412 times
PS - I have a pack of about 100 resistors, but I only have a few that are in the range of what I need for this project. Do you know of any easier way of getting 16 of the resistors that I need instead of buying 1000 resistors and testing them all? Thanks.

parkerhoyes
Posts: 13
Joined: Sun Mar 24, 2013 3:34 am

Re: Raspberry Pi LED Matrix with GPIO

Wed Apr 17, 2013 12:43 pm

Hi everyone,

I've played around with Python and the RPi.GPIO module and I was able to fix my issue with a few pins not acting properly. But the (hopefully) final issue remains, does anyone know where I can buy 16 of the resistors that I need without needing to buy huge packs of them and testing them all?

Hope someone can help. Thanks!

PaulCheffus
Posts: 381
Joined: Tue May 29, 2012 2:51 pm
Location: Lincolnshire UK

Re: Raspberry Pi LED Matrix with GPIO

Wed Apr 17, 2013 3:03 pm

parkerhoyes wrote:Hi everyone,

I've played around with Python and the RPi.GPIO module and I was able to fix my issue with a few pins not acting properly. But the (hopefully) final issue remains, does anyone know where I can buy 16 of the resistors that I need without needing to buy huge packs of them and testing them all?

Hope someone can help. Thanks!
Hi

http://www.ebay.co.uk/itm/100x-0-25W-5- ... 1407wt_993

Just select the value you require.

Cheers

Paul
Procrastination - The Thief of Time.

Return to “Other projects”