WEEK 4

TASK
MONDAY
WEDNESDAY
FRIDAY
MONDAY

✦ Embedded Programming

During week 4, I focused on the fundamentals of embedded programming and understanding how microcontrollers work and how they are programmed to interact with their environment. I explored different microcontroller families and reviewed the datasheet of a selected device to understand its architecture, memory, voltage and peripherals. Following that, I wrote and tested a simple embedded program to interact with input/output devices. For this assigment I will be consulting our Group Assignment.

◆ Exploration of Microcontroller Families

I started by researching and reviewing the datasheets of different microcontrollers belonging to the main families. The purpose of this analysis was to compare their main technical characteristics in order to determine which option is the most suitable for my final project. Part of the information was consulted from the Group Assignment.

Pinout Diagram

✦ ATtiny412

The ATtiny412 is an 8-bit AVR microcontroller integrates flash memory, SRAM, configurable I/O pins, timers, and communication interfaces within a small footprint, making it suitable for simple control systems. Its architecture allows efficient instruction execution and predictable performance.

Pinout Diagram
Feauture
Description
CPU
8-bit AVR® Processor
Clock speed
Up to 20 MHz
Flash memory
4 KB
SRAM
256 B
Power
1.8V- 5.5V
I/O pins
6 GPIO pins
Bluetooth/WiFi
No

✦ R2040

The RP2040 is a 32-bit microcontroller designed by Raspberry Pi, it is optimized for performance and flexibility, offering a significant amount of SRAM and programmable I/O capabilities. Due to its higher processing power and expanded memory, the RP2040 is suitable for more complex embedded applications that require multitasking or advanced peripheral control.

Pinout Diagram
Feauture
Description
CPU
Dual-core Arm Cortex-M0+
Clock speed
Up to 133 MHz
Flash memory
16 MB
SRAM
264 KB
Power
1.8V
I/O pins
30 GPIO pins
Bluetooth/WiFi
No

✦ ESP32-C3

The ESP32-C3 is a single-core Wi-Fi and Bluetooth 5 (LE) microcontroller SoC, based on the open-source RISC-V architecture. It strikes a balance between power, cost, and performance. It is known for its security features and its great community support, making it ideal for IoT projects.

Pinout Diagram
Feauture
Description
CPU
32-bit RISC-V single-core processor
Clock speed
Up to 160 MHz
Flash memory
4 MB
SRAM
400 KB
Power
3.0V - 3.6V
I/O pins
22 GPIO pins
Bluetooth/WiFi
Yes

◆ Comparative Analysis

While all three devices are microcontrollers, they target different application areas. On one hand, AVR microcontrollers are characterized by their simplicity and low power consumption, making them suitable for basic embedded systems. Meanwhile, the RP2040 offers a higher performance with a dual-core architecture and large SRAM, enabling more complex embedded applications. Finally, the ESP32 stands out due to its integrated wireless communication capabilities, although it has additional complexity and higher power consumption.

✦ Virtual Laboratory - Wokwi

As an exercise for this assignment, I used Wokwi to simulate a simple lamp system based on the RP2040 (Raspberry Pi Pico) and programmed it using MicroPython. In this setup, I decided to do a potentiometer, which is used as an analog input to control the brightness of an LED.

01. Open Wokwi

New Proyect > Raspberry Pi Pico > MicroPython

GitLab Login

02. Add Components

Add: Potentiometer, NeoPixel Compatible LED Ring (WS2812), Resistor (220).

GitLab Login

03. Circuit Connections

The potentiometer was connected to an ADC pin of the RP2040 to provide an analog input signal, while the NeoPixel LED Ring was connected to a digital GPIO pin through a current-limiting resistor.

GitLab Login

04. Final Result

Once everything was connected, I started the simulation. The final result is a dimmable lamp simulation where light intensity is controlled using a potentiometer.

GitLab Login

05. My Code

There are different embedded languages ​​that can be used to program code, just like: C, C++, Rust and Python; for this task I will be using the last one.


from machine import Pin, ADC
import neopixel
import time

# Potentiometer (GP26)
potentiometer = ADC(26)

# NeoPixel LED Ring (GPI15)
NUM_LEDS = 16
np = neopixel.NeoPixel(Pin(15), NUM_LEDS)

while True:
    pot_value = potentiometer.read_u16()

    if pot_value < 3000:
        brightness = 0
    else:
        brightness = pot_value // 256

    for i in range(NUM_LEDS):
        np[i] = (brightness, brightness, brightness)

    np.write()
    time.sleep(0.05)
    

06. Simulation

✦ Weekly Reflection

At the beginning of this week, embedded programming felt intimidating. However, step by step, I started understanding how microcontrollers operate and how inputs and outputs interact through code. Working in simulation gave me the space to experiment and make mistakes without fear. Although it required patience and debugging, it gave me confidence to continue developing interactive elements for my final project.

✦ Download Here

In this section, you can find the downloadable source files developed during this week.

ZIP

Wokwi

Download File