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.
Can I use a 3x3 matrix instead of this??? I'm not good at soldering <br>
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 <br> <br>Also just download the win32.exe version of Pyserial: <br>http://sourceforge.net/projects/pyserial/files/pyserial/2.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 <br> <br>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...???
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.
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!
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!<br>http://en.wikipedia.org/wiki/Charlieplexing<br><br>https://www.instructables.com/id/CharliePlexed-LED-string-for-the-Arduino/
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.
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.
Thanks for the correction. That's a really clever way of expanding an LED array.
Traceback (most recent call last): <br> File &quot;C:/Python26/sgfasfasfas&quot;, line 39, in <br> arduino = Arduino(2) #This sets the arduino to serial port 2. On PC's this will probably be COM3 <br> File &quot;C:/Python26/sgfasfasfas&quot;, line 26, in __init__ <br> self.connection = serial.Serial(path, 9600) <br> File &quot;C:/Python26\serial\serialwin32.py&quot;, line 31, in __init__ <br> SerialBase.__init__(self, *args, **kwargs) <br> File &quot;C:/Python26\serial\serialutil.py&quot;, line 261, in __init__ <br> self.open() <br> File &quot;C:/Python26\serial\serialwin32.py&quot;, line 59, in open <br> raise SerialException(&quot;could not open port %s: %s&quot; % (self.portstr, ctypes.WinError())) <br>SerialException: could not open port COM3: [Error 2] The system cannot find the file specified. <br>&quot;?&quot;
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. <br> <br>I recommend following this tutorial to make sure your 'duino is ready to go. http://www.ladyada.net/learn/arduino/lesson1.html

About This Instructable




More by ben_k:Electric Tricycle All-Terrain Electric Scooter Retro Rechargeable USB Booster 
Add instructable to: