This week was the simplest week. We had to develop some sort of Interface to connect to our microcontrollers. I decided to do a button that would toggle an LED.
From a few weeks back I remember that I had a board that had an FTDI connection through which you could send a message and recieve the echo of this message. I decided to do a simple application that would present the user with a button that when pressed, would turn on or off (toggle) an LED in the board with the FTDI. To accomplish this, I first created a firmware that would receive the character 'o' through the FTDI connection and would toggle the LED accordingly. Once I had this set up, I looked at how the simple term.py that was the sample on the FTDI week worked. This would simply initialize a serial connection and would send a character over it whenever the keyboard was pressed. I decided to incorporate this into a very simple Flask script. Flask is a simple HTTP server for Python. This server receives HTTP requests and does any sort of processing or activity upon the receipt. I took the lines that initialized the serial connection and used them to initialize the serial connection before the Flask server was set up. Then, I made a simple request that would listen to whenever a user accessed '/toggle' within the server's address. After that, I put in to send the character 'o' whenever the request was sent. Once the server was up and running, I needed simply to make an html page that would show the user the button, and perform a request to the Flask server. This webpage utilized JQuery to perform AJAX/HTTP Calls into the Flask server. Once I had this up and running, the entire pipeline worked and the Button sent a request to the flask server which then sent 'o' down the serial into the microcontroller and would toggle the LED. Lastly I made the Flask server serve the HTML page and the page would load Google's JQuery library.
Here are the files that I used.