Step 5: Programming the User Interface

Picture of Programming the User Interface
blank matrix.JPG
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.
ben_k (author) 2 years ago
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:
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...???
ssukhi2 years ago
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.