Week 12: Interface & Application Programming


The objective for this week was to write and application that interfaces with an input &/or output device. I used Python to write a very simple application that would allow me to control the output some LED's.

Choosing the Output

A few weeks ago during the input devices week I had accidentally connected my input device to digital pins rather than analog ones so I was unable to use it for that week. Luckily, I had already attached two LED's to the board that worked great, so to save time I decided to use that board as an output device for this week's assignment.

Programming the Board Application Board

I used Arduino to upload a program to the board. Throughout this enitre project I found

Richard Li's page

to be extremely helpful.

Here is the Arduino code I used to get the board to listen for instructions on the serial port:

Download Arduino Code

I basically took Rich's Arduino code and tweaked it to include two LED's.

The code initializes the serial port using the "SoftwareSerial" function. Then it sets the two LED's as output pins and begins listening to the serial port. Then it activates and deactivates the LED's depending on the input from the computer.

Creating the GUI with Python

Once again I found Rich's page to be extremely well documented and helpful so I used it to understand how to program the interface with Python. Here is the python code I used to create the GUI shown to the right.

Download Python Code

Im totally new to Python so this part took me a while but I found the following websites to be really helpful:

Basics of Python

Intro to pyserial in Python

Using Tkinter for GUI programming

Control an LED with Arduino and Python

Using python to create the interface was the hardest part for me this week mostly because I was having a hard time finding the board through serial communication. After figuring out how to use pyserial from the link above I was finally able to get the GUI to work.

For all of the Python code, I used Python 2.7 and edited the code in the IDLE interface.

Mistakes I Made

The biggest issue I had was that I missed the lecture this week since I was in Texas for Thanksgiving so I had a really hard time even understanding the basics of what we had needed to do. It really helped looking at other people's pages but it still took me a quite a long time to learn everything. As a result, my interface isn't the most sophisticated GUI but I'm just happy I was actually able to get it to work!