This week's assignment is to write an application that interacts with a user with input and/or output devices on one of the boards that have been created.
Group assignment:
For this task we will use one of the boards created in week 13 where an XIAO ESP32 is used.
Figure N°1
Python + Tk
We are going to create a graphic interface that reads the value of a potentiometer and based on the value obtained has an image that changes, since our final project is the automatic cat feeder, the image we will use will be an empty bowl to a full one.
The language that we will use to program our interface will be Python together with the Tkinter library, we will use chatgpt to give us a basic script that we will modify.
The prompt that was used was the following: "I want to make a graphical interface in python in which I have an image that changes depending on the value read by pyserial"
Figure N°2
The result obtained was the following:
From this we will make a small change, we will increase one more option in the conditional so that there are 4 images depending on the value obtained.
Additionally, the image refresh time was also changed to be 10 milliseconds and the image size was changed to (960,540).
Then another request was made for an arduino script that works with the interface, the prompt used was the following: "what would be the arduino code to send the signal through the serial port"
Figure N°3
The result obtained was the following:
Here the result was quite simple, we make changes in the conditional since when using this module we have a 12-bit ADC, that is, the values go from 0 to 4095.
To design the images of the interface, Blender was used, starting from a basic figure called a torus using the edition mode, a bowl for pets was created.
Figure N°4
Basic figures representing the small cookies were also created and they filled the bowl to create these images.
Figure N°5
We uploaded the arduino code to our XIAO ESP32 and the python script was executed from the Geany IDE.
Figure N°6
We see a demonstration of the integrated elements.
Video N°1
Individual assignment:
The goal now is to write an application that interfaces a user with input and/or output device(s) on a board that we made. We will use the PCB created in week 13 with the XIAO-ESP32 and a servo motor.
Processing
This language is used in conjunction with arduino to create interactive graphical interfaces. The IDE is quite similar to the Arduino IDE.
Figure N°7
For this task we will use the Control P5 library, to install it we must go to Sketch --> Library Import and place the term in the search engine and install.
Figure N°8
In this language we have two main functions like arduino but instead of void loop() we have void draw().
In the Setup part we define the size of the window, we establish the communication port according to the PC port assigning it to a Control P5 instance, then we create a button defining its position and size.
Finally, a function is created for the button with which we will transmit the letter 't' via serial.
This is how the interface with the button would look.
Figure N°9
From the arduino side, since we are using an XIAO-ESP32 module, we cannot use the usual servo library, but we must use the library called "ESP32Servo.h"
Within Setup we assign the microcontroller timers and assign the servo to a pin defining the rise and fall time in milliseconds.
Then, based on the value read by the serial port, we will place the servomotor in one position (0°) or another (180°).
We see a demonstration of the integrated elements.
Video N°2
Final thoughts:
Chatgpt is a very useful help tool for basic examples, here for example the scripts are used as starting points to later focus them on the desired objective, it is necessary to verify that the syntax obtained does not have errors.
Tkinter is a library for creating graphical interfaces in a simple way, the main limitation is that it can only run on PC or systems where python runs, being a disadvantage compared to other multiplatform interfaces.
If we want to integrate animations into our Blender interfaces, it helps us to create them in a simple way.
The files created or used this week can be downloaded here: