Minimus usb and 64 LEDs

May 22, 2012 at 7:47 pm (computers) (, , )

This is the last post on this for a bit (it will probably be a while before I get my next chance to tinker).  Once I’d got my minimus wired up I wanted to flash some LEDs!  After all, that’s the whole point right?

I got hold of a 8×8 LED matrix.  Some some initial confusion about common-anode matrix vs common-cathode matrix then realising that for a single colour matrix, actually it doesn’t really matter, I got hold of one of these – a Kingbright – 8×8 LED Matrix (TC15-11EWA) (around £5 from Spiratronics on ebay)

Then I had to work out how to drive it!  Well finding the data sheet was a start, and then I found some application notes for arduinos to drive an 8×8 matrix:

Neither really explained what I wanted to know – the nuts and bolts of wiring one up to a minimus …

Then the following data sheet on oomlout give me more clues:

This described the scanning approach to getting a picture on the display.  So, to connect the matrix to my minimus, I’d use 8 IO pins for the rows and 8 for the columns, then set a value across the columns, then activate that row only.  Doing this quickly for all rows would give me a display.

The pinouts for the LED matrix are quite peculiar – no logical order, so I had a choice – wire it up in a more complex way to bring them out in a logical order or wire them simply and use software to map IO pins to LEDs.  I really couldn’t entertain having anything other than a simple port to LED mapping,  and I wanted my IED ribbon cable nicely soldered to the edge of my stripboard, so I put together a simple circuit to map the LED pins to tracks on the stripboard.

I also needed some current limiting resistors, so as I get all my electronics knowledge either from first principles physics or wikipedia – in this case I just followed the formula for LEDs on the wikipedia page and decided I needed ~120 Ohm resistors.  Well, I had 150 in an old electronics box, so that’s what I used.

Now shown on this circuit (I don’t have any real circuit drawing tools) – I added the resistors as bridges/links prior to the R (rows) connectors then connected it up to my IDE cable so that:

  • R1-R8 -> PB0-7
  • C1-C4 -> PC4-7
  • C5-C8 -> PD1-4

I didn’t use PD0-7 because of the aforementioned problem I had with pin PD0.

So to drive the matrix, I used the following code

// row = 0 to 7
// col = 0x00 to 0xff
void led (int row, int col)
  PORTB = 0;   // turn all rows off prior to this scan

  // Cols = must be set low to activate LED matrix,
  //        so will need to inverse logic
  // Bits 0-3 = PORT C4-7
  // Bits 4-7 = PORT D1-4
  int portc = (~(col & 0x0f))<<4;
  int portd = (~(col & 0xf0))>>3;

  PORTC &= ~ (0xf0);
  PORTC |= portc;
  PORTD &= ~ (0x1e);
  PORTD |= portd;

  // PORTB = bit per row
  // must be active to set the row
  PORTB = (1<<row);

Notice how I bit-shift and split the col value across ports C (4-7) and D (1-4). I just set a single bit to activate the row.  Also notice how for an LED to light up the row (port B) must be high and the col must be low (ports C and D).

To turn all rows off, I just send a 0 to PORTB.

Also, I need to initialise the ports appropriately for outputs:

PORTB = 0b00000000;
DDRB  = 0b11111111;   // all outputs
PORTB = 0b00000000;   // start low

PORTC = 0b00000000;
DDRC  = 0b11110000;   // 4-7 outputs
PORTC = 0b11110000;   // start high

PORTD = 0b00000000;
DDRD  = 0b01111110;   // 1-4 outputs for matrix, 5,6 for onboard LEDs
PORTD = 0b01111110;   // start high

At this point I can start playing.  By repeating the following in a loop, it will output the display in the picture below!

led (7, 0b00000000);
led (6, 0b00000000);
led (5, 0b01100110);
led (4, 0b01100110);
led (3, 0b00000000);
led (2, 0b10000001);
led (1, 0b01111110);
led (0, 0b00000000);

Its not perfect – for some reason the LEDs are brighter at the edges than in the centre.  And I’m sure what I thought was going to be a row has turned out to be column!  But its a pretty good start.

At the end of the day – I have 64 LEDs and a smiley face.  Could I want for more?

And with that, I think my minimus tinkering will take a short pause.



1 Comment

  1. Josh Siefer said,

    “And with that, I think my minimus tinkering will take a short pause.”

    Hahahah…. Too funny. I hope it’s not TOO tricky making stuff though, as I just purchased 3x Minimus units today on a whim. I’m hoping to try out a keyboard encoder project I found at:

    Do you have sample code/projects that you are able to pull from when making the stuff you’re working on, or what resources do you use in creating your projects? It seems like a great little device, but a little daunting as well, you know? Just glad to see there are other people out there using it more for PS3 Hacks.

    Anyway, great post! Great site! Glad I found it!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: