week 11

interface and application programming.

Note: this work was done starting August 2022.

This week, I wanted to create an interface that communicated/read data from the output device I had made in Week 9. If you recall, I made a board with a servo motor on it, so I wanted to create an interface where pressing a button would turn the servo. However, I had no idea how to do so, as I had never written an interface before. To make things worse, Anthony told me that this was not really in his domain of knowledge, so I was kind of on my own. Looking through Neil's list of suggested interfaces, I chose Tkinter, only because it seemed the easiest as I have already worked with Python before (Tkinter is based on Python).

Then started the extensive Googling in order to learn how Tkinter worked. It seemed fairly understandable, but there were a lot of moving parts, especially as Arduino and Python were interacting, so I kept getting confused. The main thing I learnt though was that I needed to import three main things in Python in order to get Tkinter to work: serial, time, and tkinter. Serial and time need to be imported in order to communicate with Arduino properly. Obviously tkinter needs to be imported in order to be used. Also it is important to note that serial does not come pre-installed with Python, so I had to run 'pip3 install pyserial' in order to install it. I was able to write some very simple Programs using tkinter with my basic knowledge, but I was still feeling pretty stuck on figuring out how to put everything together. Then I found this Medium post.

This Medium post was the first place I found that clearly explained the connection between Tkinter and Arduino, so that was really helpful to finally understand. The pieces felt like they were fitting together, finally. Then looking at the sample code there, I was able to write my own code! I wrote Python code (using Tkinter) and also separate Arduino code. Surprisingly, it all worked correctly the first time. Here is what my interface looks like:

Here is a video of the functionality:

Finally, here is the code: Tkinter Code Arduino Code