Interface and application programming


On Prof. Gershenfeld's suggestion, I decided to learn Python for this week's application development assignment. In addition to its high level and cross-platform compatibility, it sounds like its scripting abilities and integration with C make it a very powerful tool in my continuing quest to learn how to use computers in more powerful ways.

The first challenge I encountered was the question of whether to learn Python 2.7 or 3.5. Python claims that 3.5 is "the future of Python", and that most new learners learn it, but according to another member of the class, most new library development is in 2.7. For myself, I'm tempted to learn 3.5 because I trust that if the developers of Python think that the changes to the language (changes in the standard libraries, strict Unicode/byte separation) are beneficial, then they probably are.

I ended up deciding on Python 3.5. It was mostly a moral decision: given that I have no need of any modules that aren't in Python 3, there's no reason for me to continue using an outdated version of the language. It's not as if I'm using a large existing codebase or anything.

First steps with python/tkinter

Getting started, I decided that it would make the most sense to try to begin learning python and tkinter by attempting to recreate one of Prof. Gershenfeld's example programs in the input devices week. I went with the MEMS microphone readout program, as that's the one I was trying to use last week with the I S microphone that still hasn't come in yet. This time, I wanted to give it made-up data and try to get a handle on the syntax of python (and maybe learn a thing or two about Tkinter as well).

Success! I did, in fact, manage to make a sample program that just graphs made-up data. I went with importing the math library to make a sum of sinusoidal functions for the data, then plugged it into the part where data goes in the script. At first, it was refreshing way too quickly. I adjusted what looked like a wait parameter in the bottom line of the script, but it turns out that it was only a wait for the first idle. In order to incorporate waiting a little while into the main idle loop, I had to grab the time functions and check manually before looping.Image of one of the random graphs

Random graphs: I ended up running Python 3.5 directly from Windows PowerShell.

Code can be found here.

Interacting with a microcontroller

For this part, I did the bare minimum of what I wanted to be able to do for control between a microcontroller and an application/interface: I made my hello-world board turn on its LED only when both its button and the button on the computer were "on". Alas, although I got this working I forgot to take a video or screencap of that part. However, the code for that can be found here.

What I have for you instead is a nice little video of what I got together for the demo before that: Just a program that would send ones and zeroes over the serial connection, so that the LED would flash if I pressed the button on the microcontroller board. This code can be foundhere.

The LED controller: Python just sent a series of ones and zeroes over serial and printed them in the terminal, the microcontroller checked serial and its button.