For the group assignment this week, we have to compare the performance and development workflow
for different architectures and look into the differente datasheets of the microcontrollers found
at FabLab Puebla.
Architectures are like blueprints for microcontrollers or processors, determining their design
and how they process information. Just as a house's architecture dictates its layout and construction materials,
computing architectures define how chips are built internally, how they compute, and how components interact.
Here are a list of architectures found in the different chips found in FabLab Puebla.
Here is the link to the group webpage for the comparison of performance
and development workflows for other architectures:
Write a program for a microcontroller development board to interact (with local input &/or output devices)
and communicate (with remote wired or wireless devices)
For this assignment, I decided to create a code that reproduces a fragment of the song 'Bad Guy' by
Billie Eilish through a piezoelectric buzzer or speaker :)
The materials are:
Xiao RP2040: It's the microcontroller that will execute the code and control the song playback.
Piezoelectric buzzer or speaker: This component will generate the musical tones to play the song. It
can be obtained from an electronics store. Make sure it's compatible with the voltage and current provided by the Xiao RP2040.
Connection cables: I will use male-to-female jumper cables to connect the piezoelectric buzzer and the Xiao RP2040 on the breadboard.
USB micro cable.
Steep 1: Connecting the piezoelectric buzzer
First, I soldered the male part of the cables to the buzzer cables. Then, I connected one of the cables to pin 0 of the Xiao RP2040.
The other cable was connected to ground (GND) on the Xiao RP2040.
Step 2: Connecting the Xiao RP2040
Connect the Xiao RP2040 to your computer using a micro USB cable.
Step 3: Setting up the development environment
Make sure you have the Arduino IDE software installed on your computer.
Open the Arduino IDE.
Go to Tools > Board and select Raspberry Pi RP2040.
In the same menu, select the correct port to which the Xiao RP2040 is connected.
Step 4: Uploading the code
1. Define the piezoelectric speaker pin: Decide which pin of the microcontroller you will use to connect the piezoelectric speaker
and define this constant at the beginning of the code. In this case, pin 2 is used.
2. Define musical notes and their durations: Define constants for each musical note you'll need in the song. Assign a value in Hz to
each note and define the durations of the notes, such as eighths, quarters, halves, and wholes.
3. Create the playNote function: Write a function that takes the note to play and its duration as arguments and plays the note on the
piezoelectric speaker. The function should have an additional delay after playing each note to separate them.
4. Set up the setup function: In the setup method, we don't need to perform any initialization in this example, so it is left empty.
5. Create the loop function: In the loop method, we define the notes of the "Bad Guy" song and their durations in arrays. Then, we play
the song in a loop using the playNote function.
The final code looks like this:
Step 5: Listening to the song
After the code has been successfully uploaded to the Xiao RP2040, you should start hearing the melody
of "Bad Guy" through the piezoelectric buzzer.
How does it work?
The piezoelectric element is connected to a diaphragm or membrane that amplifies the vibrations generated by the piezoelectric element
to produce an audible sound. This membrane is the visible and tangible part that vibrates to generate sound when an electrical current
is applied to the piezoelectric element. The code uses the piezoelectric speaker connected to the specified pin to play a predefined melody.
The playNote function is responsible for generating musical tones on the speaker by controlling the frequency and duration of the notes.
The loop function takes care of playing the melody in a continuous loop.