Week 4. Embedded programming¶
Group Assignment¶
This week we completed a group assignment related to microcontroller programming. The goal of the week was to understand how a microcontroller works, how to write and upload a program, and how to study the operation of input and output pins.
We explored different types of microcontrollers, specifically Arduino and RP2040, along with their main features. During the group work, we conducted an experiment using the RP2040 microcontroller to study the fundamental principles of its programming. We wrote the required code, uploaded it to the device, and tested the built-in RGB LED by producing blinking lights in different colors.
Throughout this process, we became familiar with program structure, the uploading workflow, and the practical use of microcontroller input/output pins, which helped us better understand how microcontrollers operate.
The full documentation and results of the group assignment can be viewed at the following link: Group Assignment Link
Individual Assignment¶
This week, as part of the individual assignment, I worked with the Seeed Studio XIAO RP2040 microcontroller.
First, I downloaded and installed the Arduino IDE software. Then, I added RP2040 board support to the Arduino IDE using the Board Manager. For this, I added the following link in the Additional Boards Manager URLs field in Preferences:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
After that, I downloaded and installed the RP2040 package from the Board Manager.
I placed the microcontroller on a breadboard and connected a potentiometer as an analog input. The potentiometer was connected as follows: - One end → 3.3V - The other end → GND - The middle pin (wiper) → Analog pin (A0)
Next, I programmed the microcontroller using the Arduino IDE environment. I wrote a program that reads the potentiometer value from the analog input (A0) and displays it in the Serial Monitor. In the code, I used the analogRead function to read the value and Serial.println to print it.
Using programming, I read the potentiometer value and sent it to the Serial Monitor. By rotating the potentiometer, the measured value changed, which confirmed that the analog input was functioning correctly.
In addition, I studied the RP2040 pinout diagram to better understand the function of each pin.
This helped me identify which pins support analog input, digital I/O, power, and communication protocols. Understanding the pinout made it easier to correctly connect the components and avoid wiring mistakes.
Through this experiment, it became clear how a physical movement (rotating the potentiometer) is converted into a digital value inside the program.
Voltage Calculation¶
I connected the potentiometer as a voltage divider: one end to 3.3V, the other end to GND, and the middle pin (wiper) to A0.
When I rotate the potentiometer, the ratio of the resistances changes, and the voltage at the A0 pin changes from 0V to 3.3V.
The voltage is calculated using the voltage divider formula:
[ V_{pin} = \frac{3.3V \cdot X}{10} ]
This means:
- When X = 0 → Vpin = 0V
- When X = 10 → Vpin = 3.3V
So, the A0 pin receives a voltage in the range from 0V to 3.3V.
ADC Values¶
The RP2040 microcontroller converts this analog voltage into a digital value (ADC conversion).
In the Arduino environment, a 10-bit resolution is used, which means:
- 0V → 0
- 3.3V → 1023
So, the voltage range 0 – 3.3V corresponds to the digital range 0 – 1023.
What I Did in This Experiment¶
In this experiment, I:
- Connected a potentiometer as an analog input
- Read the voltage from the A0 pin using a program
- Observed how rotating the potentiometer changes the digital value
This shows how a physical movement → changes the voltage → the microcontroller converts it into a number → and the program displays that value.