14. Interface and Application Programming

This week, I worked with my group to explore the use cases and workflows of different programming languages and APIs. We aslo made an interface uing python to send commands to the Arduino. For my individual assignment, I wanted to make an interface that sends commands to multiple microcontrollers.

Group Assignment

Coming soon...

Individual Assignment

Idea

I like creating control panels that can be used to control multiple systems. This is a very basic demonstration of this idea. I used tkinter python library to make a user interface, where the user can send a number to either ESP32C3 or Arduino, and the LED in either microcontroller will blink that many times. I used an Arduino UNO and my development board, which has ane ESP32C3 on it, I had designed in week 8

GUI

tkinter

Tkinter is the de facto way in Python to create Graphical User interfaces (GUIs) and is included in all standard Python Distributions. In fact, it's the only framework built into the Python standard library, so I did not have to install it as I already had Python installed. It has a lot of features that enable developers to create widgets, application layout, and intercative functions, while being fast and lightweight.

Python Code

libraryImport

The basic function of the Python code was to create the GUI and send inputs to the relative port. The first step was to import serial and tkinter libraries. The serial library allows python to communicate with a spcific port. I first set the geometry of the tkinter window to 750*250 pixels. Next step was to define the ports serial library. I am using Macbook Air, so I only have two ports: usbmodem1401 and usbmodem1101.

I had two main functions: Arduino and ESP. They basically send the user input to the relative port using the write() function.

functions
widgets

Finally, I made the actual GUI. I only needed two labels, one entry widget, and two buttons. When a button is pressed, it executes the relative function--that is, it sends the user input to the relative port.

Arduino and ESP32C3 Code

The microcontrollers code is the same for both, except for the LED pin number and baud rate. The loop function starts with a while loop that does nothing till it receives an input to the Serial. Once the input is received, a for loop repeats based on the number received to set the LED state high and low that many times with a delay of half a second between each state.

arduinoCode

Video

Here is a video of the LEDs blinking.

Source File

  • GUI_sendMessageToArduino.py.zip
  • Interface.ino.zip