6. Embedded Programming
First of all, in our group webpage (click here), we explain about some architectures, MCUs, commonly used commands [Cheat Sheet] for diferent programing languages as python and c++; as well as UF files for MicroPython and CircuitPython to program in your MCUs like. Here, you can find the IMPORTANT RULES about syntax.
For this assignment, I'm going to use the Seeed XIAO RP2040, because it has the enough architecture and power for these codes.
Arduino
We will use the ARDUINO interface to program our MCU so we will download (click here) it.
Open it and this is the interface.
Then, connect the MCU to your computer and select the port.
Select the XIAO RP2040 and after that click on Show all ports to select the UF2 Board UF2 Devices.
And write your code!
Click on verify to check your code or upload if you want to program your MCU.
Python
Now let's do it in Python! So, download and install Mu software (click here).
To use Mu, we must follow the next steps:
Press the Boot button on the Xiao to load the new bootloader.
Connect it to the computer and wait until the File Explorer opens before releasing the button.
Copy and paste the CircuitPython UF2 file into the RPI-RP2 (E:) unit.
Voila!
Open Mu and this is the interface.
In the upper right corner, select Mode and CircuitPython
And start to program! In the MU Editor, choose "Load" and select the code.py file from your Xiao or "New" to start from zero. Click "Save" to run your code anytime you make changes or want to test it.
CODES
CPP
Every time you press the button the buzzer beeps.
Turning the potentiometer increases the brightness of the LEDs
Turning the potentiometer increases the brightness of the LEDs one by one gradually.
I define functions with the frequencies of the musical notes to program a classical melody. Enjoy!
Python
- import board: Provides access to the pin layout of the microcontroller board.
- import digitalio: Allows manipulation of digital input and output signals.
- import pwmio: Enables control of Pulse Width Modulation (PWM) signals.
- import analogio: Facilitates interaction with analog inputs and outputs.
- import time: Offers functions for time-related operations, like introducing delays.
Every time you press the button the buzzer beeps.
Turning the potentiometer increases the brightness of the LEDs
Turning the potentiometer increases the brightness of the LEDs one by one gradually.
Videos testing the codes
Buzzer and LED
LEDs and Potenciometer (analog)
Gradual turning on LEDs
Mario Bros Theme
C and Python
I had programmed in C for project submissions and assignments for other classes, so clearly, it was easier for me to program in the Arduino interface than in Python. Even though it seemed quite challenging at the beginning, especially since I initially loaded the boot file incorrectly. However, I recognize that programming in Python was simpler; its logic makes it easier to understand how analog elements work, whereas in C, it comes as predefined. I will choose it when I need versatility with the new technologies like AI. Nevertheless, due to my experience and the speed of C language, I prefer to use it for my future submissions, also because I am more familiar with its documentation.