The laborious way to directly drive an 8x8 matrix

I got an arduino cos I wanted a project and an LED cube looked cool. I figured I'd better learn to drive the 8x8 led matrix before i started building the cube but I ran into some issues...
I've tried the direct drive method and using shift registers (both following tutorials) but no dice - possibly cos the code was over complicated for my needs but when I've copied everything exactly it should work... nevermind.
I decided i'd just plug it in and start lighting pins until something happened. It didn't take long, turning pins 1-8 lights up the rows, turning on 9-17 turns off columns. Naturally I couldn't turn off a different column on a different row so i set it to do the rows sequentially with a very brief delay between changes to use POV which works great! Within a short while I had an H on the screen so I decided it needed to say hello world..

The problem I have is that it uses about 30 lines of code for each letter and is very laborious to code.

http://pastebin.com/m64f65f05

Laugh all you like, it works :stuck_out_tongue:
so:
How can I simplify my code? the loop to draw the letters is basically lighting every pin on every row every time, but for a few lights i want off. surely the bulk of the loop can be built into one function somehow and i can tell it just which different pins i want to make high/low for each one?

why does sending the pins connected to the cathode high make the columns turn off?

eerm.. that's about all I can think of.. I'm more accustomed to php code than this but I'm learning

why does sending the pins connected to the cathode high make the columns turn off?

As you understand the anodes are connected to the rows and the cathodes the columns. Electricity flows from higher potential (voltage) to lower potential, so if the potential both sides of the LED is 5V there is no potential difference, so no current and no light.
I'm an engineer, so I like to think of electronics like hydraulics (they're amazingly similar), it makes the rules a lot easier to understand when you can compare it to a physical system, rather than looking at a bunch or wires.

I do hope you're not trying to sink all the current through the arduino, it'll work but it isn't good for them.

cool, thanks for that.

I do hope you're not trying to sink all the current through the arduino, it'll work but it isn't good for them.

what do i need, current limiting resistors on the anodes?

You could add current limiting resistors on the anodes or the cathodes, it would be a good scheme if you're only experimenting.

One way to work it would be run them to ground via resistor (300ohm or whatever) and also attach the arduino pin to the cathode (between the array cathode and the resistor) in output mode so it is high impedance. This means that when the pin is low most of the current will run to ground (as the ground impedance is much lower than the pin impedance), but when the pin is high the LED should be off. Unfortunately current will flow from the output pin to ground when the pin is high, but the resistor should keep this in limits.

Another option is to sink the power through npn transistors, but I think this is overkill for a project like this. There should be something in the playground about this, but I keep getting http 500 errors when I try to look at it.

How can I simplify my code? the loop to draw the letters is basically lighting every pin on every row every time, but for a few lights i want off. surely the bulk of the loop can be built into one function somehow and i can tell it just which different pins i want to make high/low for each one?

the demo is cute.

This sounds like something similar to your project, maybe you can adapt it.
http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix

Hm yeah I've tried that one before, I think there's something wrong with the pin numbering, working on it now....
I'd prefer to use code I understand fully, I guess if I get that code to work I'll have to try understand how it works...

Just wired it up exactly as shown in the tutorial (again) and it does nothing...

on closer inspection, the wiring diagram for my led matrix and the one in the tutorial are subtly different...

http://home.naixsi.co.uk/~kieran/Screenshot.jpg

mine is on the right, tutorial on the left.

all the diodes are the other way round.. so presumably all the pins need switching?

I couldn't see your diagram but maybe it's a matter of rotating the matrix 90 degrees? i.e. a difference of opinion as to which are rows and which are columns?

In any event, all the timing guff in the playground looks a bit hard to understand but maybe just the idea of encoding each letter as a matrix and using a single function to translate the matrix into high/low would do your trick.

sorry, try this:
http://home.naixsi.co.uk/~kieran/Screenshot.jpg

if you rotate your image right 90 degrees I think it's electrically the same as the one in the playground.

Again, his code looks a bit tough but just think about a routine that get's passed an 8x8 matrix and plays it out on the leds repeatedly, a few ms per column.