GUI Controlled LED Matrix
32,675
58
11
Introduction: GUI Controlled LED Matrix
I recently got an Arduino Uno, and it quickly became my favorite toy. After learning the basics of how the platform operates, I became interested in interfacing the Arduino with personal computers. After seeing a large number of LED matrix projects on Instructables and the rest of the web, the LED matrix seemed like a perfect project to attempt to interface with a computer.
I chose to build a 3 x 3 matrix, because I thought it would be best to start small (and I did not have enough LED's for a larger one). Also, 3 x 3 is about the largest size it is safe to power directly from the Arduino, without using an external power supply. However, the design for the matrix and the software in this Instructable should be fairly easy to scale up to 8 x 8 or so, by using an external 5V power supply and some transistors.
.
Step 1: Tools, Materials and Resources
To build the matrix, you will need:
- Arduino microcontroller: I used an Arduino Uno, but pretty much any will work.
- 9 LED's: Any sort should work. I had some left over from my bicycle's spoke lights
- 3 resistors: These are to prevent the pins/LED's from burning out. I used the 330 Ohm variety, but anything around there should work
- A breadboard
- 1 Foot of thin gauge electrical wire: To connect the negative ends of the matrix to the breadboard
- 6 breadboard jumpers
- Soldering materials
- A Mac or PC with the Arduino IDE and Python 2.6/2.7. Unfortunately, I could not get Python 3 to talk to the Arduino, so you'll have to use python 2.
Step 2: Building the Matrix
The matrix itself is fairly simple to build, and if you are building one as small as 3 x 3, it can be built without any sort of jig to align the LED's or circuitboard to hold the components.
To start out, bend the anodes (the longer leads) of all 9 LED's to a 90 degree angles, perpendicular to the plane the leads are on. Then bend the cathodes (the shorter leads) to 90 degree angles parallel to the plane of the leads. Make sure the leads extend farther out of the LED before bending on the cathodes than the anodes.
Next, divide the LED's into groups of three. Solder the cathodes of all three LED's together, so that the LED's form a chain. The anodes of the chain should all stick out in the same direction. Once you have done this three times, you will have three chains of three LED's. Then you can solder the anodes of each chain to the anodes of the next chain. If all your bends are 90 degrees, and you secure the LED's while you solder them, the LEDs' leads should form a nice grid.
Once all the LED's are soldered together, solder a resistor to the three anode leads that are not connected to other LED's. Finally, solder a short length of wire to each of the three cathode leads protruding from the matrix.
Step 3: Attaching the Matrix
I attached the leads to the Arduino in the following order:
- Left anode: Pin 2
- Center anode: Pin 3
- Right anode: Pin 4
- Top cathode: Pin 5
- Middle cathode: Pin 6
- Bottom cathode: Pin 7
Step 4: Programming the Arduino
Now, I do not know if there is a standard for how LED displays cycle through the rows/columns, but I wrote my POV controlling program from scratch. If you go down to the basics, it works like this:
The Arduino's code contains a set of arrays (one could also use a single 2D array), one for each row, that indicates which LEDs in the row are activated. The program scans through these arrays one at a time, and the Arduino lights only the LED's which are indicated in the one row. It lights the LED's in the row by setting the pin for the row to "LOW" and the pins for the lit LED's to "HIGH." Every cycle, the program also runs a function which gathers input over a serial connection. Inputs are in the form of integers, which correspond to an LED on the matrix. The matrix is arranged as such:
[0, 1, 2]
[3, 4, 5]
[6, 7, 8]
If the code receives the number "6" over serial, the state of the bottom left LED in the array is switched.
Due to its length, I will not paste the code into this text, but you can download a commented version of it just below:
Step 5: Programming the User Interface
I programmed the program and GUI that control the LED matrix in Python, using the built-in Tkinter graphics module. The design of the GUI is very simple. It contains nine buttons, each representing one LED. When the buttons are clicked, they turn orange, and when they are clicked again they turn white. As the buttons are clicked, they update the LED matrix in real-time.
In order for Python to communicate with the Arduino, it needs the Pyserial module. Once this is installed, you can read and write to the Arduino over the serial connection.
In my program, whenever a button is clicked, the button calls a function which writes the number of the button to the Arduino. Using that number, the Arduino figures out which LED the number corresponds to, and switches the state of that LED.
The Python file for the UI is attached below. When running it, there are a few things to note:
If you run the file in Windows, it is advisable to simply double click the file instead of opening it in IDLE (the python IDE) and running it from there. Also, you will have to set the serial port to use within the code. By default, it is set to 2, which corresponds to COM3 on Windows.
Mac users: I have not tested the program on a mac. Please let me know if there are any problems with it, so I can try to fix them. Python sometimes behaves differently on Macs, especially when dealing with graphics stuff.
Attachments
Step 6: Using the Matrix, Conclusion
To test the matrix, plug it in to your computer, and download the program to it from the Arduino IDE. Then run the Serial Monitor. You can use the number keys, 0-8, to test each LED and make sure the program is running correctly. Then you can run the Python GUI program. Before you do so, make sure you have closed the Serial Monitor in the Arduino IDE, or the Python will not be able to connect over Serial, since the port is already in use. When you quit the GUI, you can go ahead and connect to it in the Arduino IDE again, because the GUI closes its connection when it quits.
Have fun playing with your GUI controlled LED matrix! I have found that it is almost infinitely entertaining to small children. If you build your matrix with different color LED's, you can easily change the color of the buttons in the GUI to match your LED's, using hexadecimal color codes. The section of the code that must be changed is clearly commented.
I would like to create a much larger 8x8 version of this matrix. 8x8 is the largest size you can build on an Arduino Uno without using shift registers, charlieplexing, or controlling circuitry other than some transistors for the power. If you build one of these, please post pictures, and I will post them in this last step. The construction of the matrix actually very little work. Programming it took far longer, and I have already done that part for you.

Participated in the
Microcontroller Contest

Participated in the
LED Contest
11 Comments
8 years ago on Step 2
Can I use a 3x3 matrix instead of this??? I'm not good at soldering
8 years ago on Step 5
I just checked and the code in step 4 downloads just fine. For some reason it downloaded as a .tmp, but you can either just open it in notepad and paste it to the arduino ide, or just change the extension to .pde
Also just download the win32.exe version of Pyserial:
http://sourceforge.net/projects/pyserial/files/pyserial/2.5/
8 years ago on Step 5
your arduino code attachment is not found. I think its lost. I got ur py file. Can u send me your arduino program on my email id...?? If u can, this is my id : dixitad88@gmail.com
Also the PySerial is i found in tar.gz format which works on linux. I am using windows, so what can i do..?? Isn't there windows version available of pyserial...???
9 years ago on Step 5
Hello, I'm working on this project, and I'm kinda stuck. Just to let you know, I have absolutely no experience with python, so I little clue of what I'm doing (this is a class project). I got a window with the buttons to pop up, but only it doesn't have any buttons. Also when I click on 'run module' the [buttonless] window with buttons comes up along with python shell and it has all this red text in it.
9 years ago on Introduction
Hi! I am a first time Arduino user and absolutely love your GUI project! I'm wondering how you install the Pyserial serial module in Python. Thanks!
10 years ago on Step 6
Hi, just thought i would tell you that you could control more than 64 LEDs on a Uno if you use some fancy charlieplexing. although a control circuit would probably be easier!
http://en.wikipedia.org/wiki/Charlieplexing
https://www.instructables.com/id/CharliePlexed-LED-string-for-the-Arduino/
Reply 10 years ago on Introduction
Jchant Hello, I am layman in the field of electronics and I'm trying to mount a curtain of RGB LEDs, the project is much larger q this, will have 30 rows by 48 columns with tri-color RGB LEDs. I would like your help to put the project into practice stating what I'll need for this, the components and how to connect them. I'll have the help of an electronics technician to assist me in the project. I thank your attention.
Reply 9 years ago on Introduction
That is going to be extremely complex for a beginner. I strongly suggest you start with this instructable and then search for more that use shift registers. The bigger the LED matrix the better as the coding and setup gets much more complicated when you have to start daisy chaining them together. using RGB LEDs also adds an incredible layer of complexity. I will say when you finish it, please post it if you can as I would love to see something on that scale.
Reply 10 years ago on Introduction
Thanks for the correction. That's a really clever way of expanding an LED array.
9 years ago on Introduction
Traceback (most recent call last):
File "C:/Python26/sgfasfasfas", line 39, in
arduino = Arduino(2) #This sets the arduino to serial port 2. On PC's this will probably be COM3
File "C:/Python26/sgfasfasfas", line 26, in __init__
self.connection = serial.Serial(path, 9600)
File "C:/Python26\serial\serialwin32.py", line 31, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:/Python26\serial\serialutil.py", line 261, in __init__
self.open()
File "C:/Python26\serial\serialwin32.py", line 59, in open
raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError()))
SerialException: could not open port COM3: [Error 2] The system cannot find the file specified.
"?"
Reply 9 years ago on Introduction
That error is common, means the port is incorrect. Windows uses whatever COM port is next when connecting devices. An easy way is to check using the Arduino software by uploading a test sketch (like the blinker). Make note of which COM port works and use that in the script. Depending on how I connect to my PC mine usually picks up a COM port between 3-7.
I recommend following this tutorial to make sure your 'duino is ready to go. http://www.ladyada.net/learn/arduino/lesson1.html