Sunday 26 February 2012

Arduino - How to power LED matrices using shift registers: Part 2

Welcome to part two.

This has all the steps you need to get your creations up and running. But first, the code for my program can be found here: http://dl.dropbox.com/u/16309910/test.ino or search for me on github: j-fray or clone it using https://j-fray@github.com/j-fray/Arduino---Simulating-bead-sort.git


There are also some pictures of the schematics which you can find here:
Imput layer: http://dl.dropbox.com/u/16309910/inputlayer.png
Output layer: http://dl.dropbox.com/u/16309910/outputlayer.png
Power layer: http://dl.dropbox.com/u/16309910/powerlayer.png

I will upload any remaining documents to my github as listed above.

Now obviously this program is meant for 6 matrices, but it should be pretty straight forward to alter it for any number of matrices.

Step 1 - Setup
A good place to start is to get one matrix up and running. You need 3 pins on your Arduino board, one for data, one for clock and one for load pins. With the MAX7219 these correspond to pins 1, 13 and 12 respectively on the shift register. Put the shift register on a breadboard and connect these up.

Then its time to connect the ground and power pins up. The ground pins on the 7219 are 4 and 9, the power pins are 18 and 19 (check the link to the schematic in part 1). Pin 18 needs to be connected to a 40KOhm resistor (or equivalent combinations) and then connected to the power supply.

Arduino boards in general have a 5V output and that's what I used, just make sure the pins are connected in series and not in parallel.

Step 2 - Connecting to matrix
Now to start connecting up the matrix. As mentioned in part 1 the pins mappings of LED matrices vary for each make so check the datasheet of your matrix to see what pins use what. In my case pins 1 - 4 and 20-24 control the rows.13-19 control the red cols and 5-12 control the green cols.

Connect your matrix up appropriately. It is worth uploading the program to the Arduino board first and connecting the pins one at a time so that you can see the matrix working and deduce if there are any problems with a particular row.

The result should be a small sequence on the matrix.

Step 3 - Repeat
Repeat steps 1 and 2 for however many matrices you want, remember to do small bits at a time and test them. The last thing you want is to wire the whole thing and find it doesn't work or you've wired it wrong.

Here are some pictures of my creation:




Schematics
Input layer

Output layer

Power layer




Common problems (I found)
Matrix kept turning off
The most common problem I had was finding the matrix would just randomly turn off and wouldn't turn back on until I reset the Arduino board. I found out this was due to the resistance of the resistor I was using. There is a handy table on selecting the value for this resistor (Rset) in the guide in part 1.

The matrix is displaying my sequence/pattern incorrectly
This is most likely due to connecting the pins up incorrectly. Remember to check the pin mappings for your matrix and whether its common cathode or anode.

My sequence will stop/freeze
This will probably be due to the delays used in the program. If its anything like mine there will be a delay at the start/end of the sequence code. Playing round with that should get it working again.

Any other problems you have you're welcome to ask me about them, but I can't guarantee I'll be able to solve your problem :)

Thanks for reading and I hope this was helpful

Jake

Arduino - How to power LED matrices using shift registers: Part 1

I intend for this to be a comprehensive guide to controlling LED matrices, there are some guides out there (also as blogs) but it all depends on what you're doing.

If you're looking for a quick step by step guide, skip to part 2, if you want to know everything about what you're doing, read this before part 2.

Note - I have only been doing Arduino stuff since July 2011 and so I still consider myself to be a novice at it. While I have completed what I set out to do, there may be some things which I may have done wrong or are bad practice. If you have any questions please feel free to email me or ask in the comments below.

Background
LED matrices can be used for many things, I have chosen to use it to represent the bead sort algorithm (this is for my dissertation, I will probably post about that at some point in the future). This is where beads are sorted using the properties of gravity, and is handy because each LED can represent 1 bead. Here is a gif I found on google images that show you how it works: http://mgs.spatial-computing.org/ImageGallery/EXEMPLES/BeadSort/anim_bead_julien.gif

The equipment
Unfortunately the components for any build like this will be a little expensive, but it depends how you do it.
Here is a list of my equipment:

How the LED matrices work
When I first started using them, it was a bit of an alien world to me so hopefully this part will help. Remember the details for the matrices will be different for each model, check the matrix datasheet for all the necessary information. The matrices I'm using are a common cathode 24 pin matrix. The common cathode part of it means that for a row to be on, it has to be set to LOW (cathode-negative). For this particular matrix pins 1-4 and 21-24 control the rows, pins 5-12 control the columns with green, pins 13-20 control the columns with red. The mappings are below:

How the shift registers work
Shift registers are still a bit of an enigma to me. I don't know exactly how they work but know how to use them. The shift register I'm using (MAX7219) is meant for LED control. It will take serial input (bits, one after another) and give parallel output (all the bits, all at once). It has 24 connections in total. Rather than explain each one in detail, this guide on the Arduino website covers pretty much everything: http://arduino.cc/playground/Main/MAX72XXHardware

The guide above also tells you how to choose the correct resistance value of Rset (in my case 30-40KOhms).

Arduino program
My source code will be as a link on part 2, but I will explain a bit about the program here.

My program uses the LED control library (explained below) so that needs to be imported.

One of the first lines is LedControl lc=LedControl(2,3,4,1); This basically means create a new instance of LED control, using pins 2,3 and 4. The number 1 corresponds to the number of devices (which will always be 1 for my program).

Next I have the step definitions. Each step consists of and array of 48 bytes, as I have 24 steps thats 24 * 48 bytes or 1.125KB which is a heck of a lot to hard code. Luckily I have created a program to do that for me, but that's another subject. It is likely that anyone following this will be using far smaller "steps" and fewer devices.

After the step definitions there is a small bit of code denoting the delay between each step, this is mainly so I can simulate a bit of acceleration by reducing the delay per step.

Following that are the step assignments. In brief these assignments tell the program which parts of the array to assign to which LED control instance.

For my particular case at the end of each set of steps I wipe the LEDs and start again.

IMPORTANT - There must always be a delay at the beginning/end of your step definitions, I'm not sure why but it messes up otherwise.

And that's it :)

Using the LED control library
Firstly make sure you have the Arduino software running and working (version 1.0 was released not too long ago).

I have used the LED control library, details of which can be found here: http://www.arduino.cc/playground/Main/LedControl

You can also download the library as a .zip file from that link, the link to the file is in the section "Sourcecode and download".

Make sure the Library files go to the "Libraries" or "Lib" folders in the Arduino program.

To use the library, go to Tools -> Import Library -> LED control. You may have to close and open the Arduino program again if it was open when you added the library files.

Now you're set to go :D.

I will gladly try to answer any questions so please feel free to comment/email me with any queries.

Now have a look at part 2

Jake



Did you find this post interesting?