Photogate Part 3

(Original post August 10, 2016)

Now that I’ve been able to create a basic working prototype of my DIY photogate, I’ve been focusing on improving different aspects of it in order to make it more useful in the classroom. I’m waiting for the order of parts I need in order to build the final casing for the transmitter and receiver, so in the meantime I’ve been focusing on the code.

Since not all teachers will have literacy in Python, we’re going to need to package our program into an executable. It looks like py2exe provides just what we need, so I’ve been reading up on how to use it. Meanwhile, John pointed out to me that I should improve the program’s data refresh rate in order to get more accurate jump measurements, so I’ve been working on that.

The fact that the Python program refreshes every time it gets a new data point really seems to slow things down, so I’ve now set it to not update the graph as often. The program’s main loop listens for new data, adds it to the dataset, analyzes it, and then checks to see how much time has elapsed since the last time it graphed. If it’s been 150 milliseconds, it goes ahead and updates the graph with all the new data points. So the program’s framerate is still pretty low but the speed at which it actually processes the data, and the calculation accuracy, has improved a lot (now it’s another data point every 10 milliseconds).

Another problem is that the pyserial library needs to know the name of the device it should connect to. Up to this point I’ve just handled that manually, but now I need the program to be able to autodetect the Arduino so that the teachers don’t have to deal with the technical details. Thankfully I was able to find a helpful Stack Overflow thread in which somebody wrote a Python script listing all the computer’s connected COM ports regardless of the operating system. Now all I need to do is integrate this into my program and have it try connecting to each of the ports it finds until it successfully locates an Arduino.