Week 13: Interface and Application Programming

Creating a virtual serial port

I unfortunately forgot to bring my boards home with my over break so I couldn't actually actually interface directly with my board. My plan was to create virtual serial port on my machine so I could manually create serial messages. My application would read in these messages so when I get back to campus and plug in my device, I would only need to change which serial port I'm reading over to get the same functionality with the same program.

I found pty, a Python library that handles pseudo-terminal utilities. pty.openpty() opens a new pseudo-terminal pair with a master and slave end. The slave end can be used as a serial port and I can interface with this serial port using the serial and OS libraries in Python.

Python application

I decided to write up my application in Python since that is the language that I am the most comfortable in. Although I haven't programmed in tkinter before, I have used graphics libraries that operated with a main window and callback functions so I thought it would be a good way to represent my data graphically. I read through a tutorial and played around with just making a canvas at first. I made a program that would draw a circle at the mouse position.

Responding to serial input

I used this tutorial to change the callback from using the mouse event to a serial input. I'm writing the mouse coordinate to a file and reading the file in as if it was a serial input. I take the mouse position and draw it as a circle on my canvas. This reads the "serial" file very 500 ms. Any board that sends in location data in an x, y format could be plugged into this code to draw the absolute position on the canvas.