Week 4. 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.

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.

Onshape Logo

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
Features - ATtiny412
CPU8-bit AVR® Processor
Clock speedUp to 20 MHz
Flash memory4 KB
SRAM256 B
Power1.8V- 5.5V
I/O pins6 GPIO pins
Bluetooth/WiFi:No

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
Features - RP2040
CPUDual-core Arm Cortex-M0+
Clock speedUp to 133 MHz
Flash memory16 MB
SRAM264 KB
Power1.8V - 3.3V
I/O pins30 GPIO pins
Bluetooth/WiFi:No

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
Features - ESP32-C3
CPU32-bit RISC-V single-core processor
Clock speedUp to 160 MHz
Flash memory4 MB
SRAM400 KB
Power3.0V - 3.6V
I/O pins22 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

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. Code

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. Video

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.

ZIP

Wokwi

Download File