Week 04

Embedded Programming

This week was also full of challenges. We were able to meet virtually with Professor Roberto from the node, who gave us clearer guidance on the topic we were to address during the week. Thanks to his guidance, we understood that the work was divided into a group component and an individual component, which required better organization and task distribution. Later, we met first virtually and then in person at the Fab Lab UNI to organize ourselves into small groups. This allowed us to develop the group component more efficiently, share ideas, and compare the work done, thus enriching the collective learning experience. Personally, I consider these topics challenging because they are new to me; however, I see them as a challenge that motivates me to continue learning. The most important thing has been maintaining a proactive attitude, seeking additional information, and supporting each other within our group node to achieve our proposed objectives.

Week 3 cover

Assignment Requirements

Group assignment

  • Demonstrate and compare the toolchains and development workflows for available embedded architectures
  • Document your work to the group work page and reflect on your individual page what you learned

Individual assignment

  • Browse through the datasheet for a microcontroller
  • Write and test a program for an embedded system using a microcontroller to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)

Group assignment

Progress Status

This is for reporting progress (not for visitors to click).

Group work Done

Group page link + notes added.

Press-fit kit Done

Missing final photos and conclusions.

Downloads Done

Upload .zip with source files.

Assignment Requirements

Learning outcomes

  • Implement programming protocols..

Have you answered these questions?

  • Linked to the group assignment page✅
  • Browsed and documented some information from a microcontroller's datasheet✅.
  • Programmed a board to interact and communicate✅.
  • Described the programming process(es) you used✅.
  • Included your source code✅.
  • Included ‘hero shot(s)’✅.

Introduction to Embedded Programming

This week was also full of challenges. We were able to meet virtually with Maestro Roberto, from the node, who gave us clearer guidance on the topic we had to address during the week. Thanks to his guidance, we understood that the work was divided into a group part and an individual part, which implied better organization and distribution of tasks. Single image

Group work

During Week 4, which focused on Embedded Programming, my colleague Grace Schwan and the team organized ourselves to demonstrate and compare toolchains and development workflows across different microcontroller families. To better distribute the workload, each team member focused on a specific microcontroller.

In my case, I documented the operation and development environment of the ESP32-C3, while my colleague worked with the RP2040. Afterward, we shared our findings with the team to analyze and compare them with other selected architectures, allowing us to identify similarities, differences, and advantages of each platform.

For more information about our group work and detailed comparison, please visit our group project page .

Single image

Group Assignment Conclusion – Microcontroller Comparison

RP2040 is well balanced: it has dual-core processing, good speed (up to 133 MHz), and enough memory (264 KB SRAM + 2 MB Flash) for medium projects. It’s ideal for local control (LEDs, buttons, sensors, PWM, ADC) and quick development with Arduino or MicroPython.

ESP32-C3 is a good option when wireless connectivity is required, since it includes Wi-Fi and Bluetooth (BLE). It is strong enough for basic IoT applications, and its main advantage is the ability to connect to a network or a phone. The workflow usually includes network setup (Wi-Fi credentials or BLE services).

ESP32-S3 is the most powerful option: it offers higher speed and significantly more memory available on the board (large Flash + PSRAM). This is helpful for heavier tasks, larger libraries, or advanced features, while still maintaining Wi-Fi/BLE connectivity.

ATSAMD11 is the most basic and limited in terms of resources (lower speed and memory). However, it is very useful for learning because it encourages writing efficient firmware and often involves a more “technical” workflow using ARM tools and SWD debugging. It is a good option to demonstrate a workflow different from simply uploading via USB.

Single image

Individual assignment

ESP32-C3 Microcontroller

ESP32-C3 Microcontroller

I chose to study the ESP32-C3 because it combines a compact design with integrated wireless connectivity, making it very powerful for IoT and smart device development. Unlike many basic microcontrollers, it includes built-in Wi-Fi and Bluetooth Low Energy, which allows direct internet communication without requiring additional modules.

The ESP32-C3 is based on a RISC-V architecture, offering efficient performance and low power consumption, which makes it ideal for embedded systems and energy-efficient applications. It is well suited for portable projects, home automation, sensor networks, and real-time data monitoring.

Additionally, it supports multiple programming environments such as Arduino IDE, MicroPython, and ESP-IDF, making it flexible for both beginners and advanced users who want to explore different development platforms.

ESP32-C3 General Information

General Information

  • Manufacturer: Espressif Systems
  • Model: ESP32-C3
  • Architecture: 32-bit RISC-V (single-core)
  • Maximum Clock Speed: Up to 160 MHz
ESP32-C3 Technical Specifications

Memory

  • Internal SRAM: ~400 KB
  • Internal ROM: Included (for boot and system functions)
  • Internal Flash: Not integrated into the base chip (uses external QSPI Flash; usually included in the module)
  • External Memory Support: QSPI interface for Flash

GPIO (Input/Output)

  • Up to 22 multi-function GPIO pins (depending on the module)
  • Logic Level: 3.3 V
  • Configurable as digital input or output
  • Interrupt support

Analog-to-Digital Conversion

  • 12-bit Analog-to-Digital Converter (ADC)
  • Multiple ADC channels (depending on module configuration)
  • Internal temperature sensor (for internal chip monitoring)

Communication

  • 2 × UART
  • 1 × I2C
  • 1 × SPI
  • 2.4 GHz Wi-Fi (802.11 b/g/n)
  • Bluetooth 5 (BLE)
  • Integrated USB Serial/JTAG (on some models)

Pulse Width Modulation (PWM)

  • Multiple PWM channels (based on LEDC timers)
  • Configurable frequency and resolution

DMA

  • DMA support to optimize data transfers and reduce CPU load

Timers

  • Hardware timers
  • Watchdog timer
  • High-precision system timers

Special Features

  • Integrated wireless connectivity (Wi-Fi + Bluetooth Low Energy)
  • Hardware cryptographic acceleration (AES, SHA, RSA, ECC)
  • Secure Boot support and Flash encryption

Electrical Characteristics

  • Operating voltage: 3.3V
  • Does not tolerate 5V on GPIO pins
  • Low power modes (Light sleep, Deep sleep)
  • Can be powered by 5V via USB on development boards (internally regulated to 3.3V)
Package Information

Package

  • Package Type: QFN-48 (48-pin package)
  • Description: Quad Flat No-leads (QFN)
  • Total Pins: 48 physical pins
  • Mounting Type: Surface Mount Device (SMD)
ESP32-C3 - Precauciones y Mapa de Pines

Precauciones de Hardware (Importante)

  • GPIO 3.3 V: No aplique señales superiores a 3,3 V en los pines de E/S para evitar daños permanentes.
  • Fuente de alimentación: Puede ser alimentado con 5 V a través de los pines de alimentación o USB (regulado internamente a 3,3 V).
  • Batería + USB-C: Evite conectar el USB-C mientras haya una batería conectada, ya que puede generar riesgo eléctrico.

Mapa de Pines (Resumen Funcional)

Entradas Analógicas (ADC)

  • D0 = GPIO26
  • D1 = GPIO27
  • D2 = GPIO28
  • D3 = GPIO29

I2C

  • D4 = SDA (GPIO6)
  • D5 = SCL (GPIO7)

UART

  • D6 = TX (GPIO0)
  • D7 = RX (GPIO1)

SPI

  • D8 = SCK (GPIO2)
  • D9 = MISO (GPIO4)
  • D10 = MOSI (GPIO3)

Control

  • BOOT: Activa el modo bootloader para programación.
  • RESET: Reinicia el microcontrolador.
Single image

ESP32 Datasheet: Download the ESP32 Datasheet (PDF)

ESP32-C3 Bootloader Recovery

Recovering the Bootloader and Port (when it “disappears”) on the ESP32-C3

On the ESP32-C3, if the programming port disappears from your computer, you can manually force bootloader mode:

  1. Press and hold the BOOT button.
  2. Connect the board to your computer via USB.
  3. If required, press and release the RESET button while holding BOOT.
  4. Release the BOOT button after a few seconds.

The microcontroller will enter Download Mode, and the USB serial port will become available again for uploading firmware from the Arduino IDE or ESP-IDF.

Unlike the RP2040, the ESP32-C3 does not appear as a storage device, but rather as a USB serial port.

Note about the Integrated LED

On many ESP32-C3 boards, the integrated LED may operate with inverted logic, depending on the manufacturer's design:

  • In some cases, the LED turns on with a LOW signal.
  • And turns off with a HIGH signal.

This depends on the specific board's circuitry, so it is recommended to check the schematic or perform a quick test to verify its behavior.

Lessons Learned – Exploring the ESP32-C3 Datasheet

  • I learned to quickly identify key information in the ESP32-C3 datasheet, such as the 32-bit RISC-V architecture, clock frequency (up to 160 MHz), internal memory, voltage levels, and available peripherals (ADC, PWM, UART, I²C, SPI, Wi-Fi, and Bluetooth).
  • I understood that the 3.3V logic level is critical, since GPIO pins operate exclusively at 3.3V even if the board is powered with 5V via USB.
  • I learned to correctly interpret pin assignments, differentiating between the actual GPIO numbers (GPIO0, GPIO1, etc.) and the labels printed on the board (D0, D1, etc.).
  • I clarified the difference between power pins and signal pins, ensuring that digital and analog signals always respect the 3.3V logic level.
  • I discovered how the BOOT and RESET process works to recover the board when the programming port disappears, entering Download Mode to reload firmware.
  • I learned that the integrated LED behavior may be inverted, sometimes turning on with a LOW signal and off with a HIGH signal.
  • I realized that the ESP32-C3 is ideal for IoT projects due to its integrated Wi-Fi and Bluetooth connectivity and compatibility with Arduino IDE, ESP-IDF, and MicroPython.

Software and Workflow – ESP32-C3

  • Software: I used the Arduino IDE on Windows with the ESP32 board package installed (ESP32 by Espressif Systems), selecting the ESP32-C3 board model.
  • Connection: I connected the ESP32-C3 board to my computer using a USB-C data cable. The board was recognized as a USB serial (COM) port.
  • Upload Steps: If necessary, I pressed and held the BOOT button to enter Download Mode, then clicked Upload in the Arduino IDE. After uploading, the board automatically restarted and ran the program.
  • Local Input: A pushbutton connected to a GPIO pin was used to start the LED sequence.
  • Local Output: Three LEDs connected to digital output pins blinked following a programmed pattern.
  • Communication: I used the Serial Monitor in the Arduino IDE to display messages, confirm button presses, and monitor program cycles.

Code Improvements – ESP32-C3

  • Replaced the traditional delay() function with a non-blocking timing approach using millis(), allowing the program to remain responsive while handling timing tasks.
  • Configured the pushbutton using INPUT_PULLUP and implemented software debounce to ensure stable and reliable button readings.
  • Triggered the LED sequence only once per button press (press-event detection) instead of repeating continuously while the button is held down.
  • Organized the LED pins using an array structure to keep the code cleaner, more readable, and easier to scale.

Wiring (Pins Used)

  • LEDs: Connected to pins D0, D6, and D7, each with a current-limiting resistor connected to GND.
  • Button: Connected to D1 and GND, configured using INPUT_PULLUP. In this setup, the pin reads HIGH when not pressed and LOW when pressed.

Arduino Installation and ESP32-C3 Setup

1. Download and Install Arduino IDE

Go to the official website: https://www.arduino.cc/en/software

  1. Download the version for your operating system (Windows, Mac, or Linux).
  2. Run the installer.
  3. Accept the permissions and make sure USB Drivers are selected.
  4. Finish the installation and open the program.

2. Add ESP32-C3 Support

Step 1: Add Board Manager URL

  1. Go to File → Preferences.
  2. In “Additional Board Manager URLs” paste:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
    
  1. Click OK.

Step 2: Install ESP32 Package

  1. Go to Tools → Board → Boards Manager.
  2. Search for: esp32.
  3. Select the package from Espressif Systems.
  4. Click Install.

3. Select the ESP32-C3 Board

  1. Go to Tools → Board.
  2. Select ESP32C3 Dev Module.

4. Install Libraries

  1. Go to Sketch → Include Library → Manage Libraries.
  2. Search for the required library (WiFi, Servo, etc.).
  3. Click Install.

5. Test with Blink Example

  1. Go to File → Examples → 01.Basics → Blink.
  2. Connect the ESP32-C3.
  3. Select the port in Tools → Port.
  4. Click Upload.

If everything is correct, the LED should blink.

Arduino installation on the web

search for bookstores

library installation

library installation

Arduino and ESP32-C3 Installation

LED Connection Process - ESP32-C3

Process carried out: LED connection and testing on ESP32-C3

For this practice, an ESP32-C3 programmed using Arduino IDE was used.

Materials Used

  • 1 LED
  • 1 resistor (220Ω to 1kΩ, recommended 330Ω or 1kΩ)
  • Jumper wires
  • Breadboard

Connection Procedure

First, the LED was placed across the central gap of the breadboard to properly separate its terminals. The LED legs were identified as follows:

  • Long leg = positive (+)
  • Short leg = negative (–)

The connection was then made as follows:

  1. The GPIO2 (D2) pin of the ESP32-C3 was connected to a row on the breadboard.
  2. One leg of the resistor was placed in the same row.
  3. The other leg of the resistor was connected to the row where the long leg of the LED was located.
  4. The short leg of the LED was connected to the GND pin of the ESP32-C3.

Connection Summary

GPIO2 → Resistor → Long leg of the LED
Short leg of the LED → GND

Programming and Testing

A basic code was uploaded that configures GPIO2 as a digital output. In the main loop, the LED turns on for 500 milliseconds and then turns off for 500 milliseconds, creating a continuous blinking effect.

Code: GPIO2 Blink (ESP32)
const int LED_PIN = 2;  // GPIO2

void setup() {
  pinMode(LED_PIN, OUTPUT);
}
h
void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(500);
  digitalWrite(LED_PIN, LOW);
  delay(500);
}

As a result, the LED blinked correctly, confirming that the assembly and programming were successful.

  • Design file (SVG/DXF)
  • ⬇️ Download Code 1 (.ino)

    LED Connection Process - ESP32-C3

    LED Connection Process - ESP32-C3

    Electronic Validation and Circuit Functionality

    ERC & DRC Results

    To validate the electronic design, both ERC (Electrical Rules Check) and DRC (Design Rules Check) were performed using the design software.

    • ERC (Electrical Rules Check): verified that all schematic connections are correct, with no unconnected pins or electrical conflicts.
    • DRC (Design Rules Check): confirmed that the design follows basic connection and layout rules.

    The results showed no critical errors, confirming that the circuit is electrically correct.

    Note: In this stage, no PCB was fabricated. The circuit was implemented and tested using a breadboard. Therefore, the DRC validation applies only at the digital design level, not physical manufacturing.

    Circuit Functionality

    The circuit is based on an ESP32-C3 microcontroller, which acts as the main control unit and operates at a 3.3V logic level.

    A simple LED circuit was implemented using GPIO2, with a resistor (between 330Ω and 1kΩ) to limit current and protect the component.

    Signal Flow

    • The ESP32-C3 sends a digital signal from GPIO2.
    • The signal passes through the resistor.
    • It reaches the LED, turning it ON or OFF.
    • The circuit is completed through the GND connection.

    The microcontroller is programmed to alternate between HIGH and LOW signals, creating a blinking effect:

    • HIGH: LED turns ON
    • LOW: LED turns OFF

    It is important to note that in some ESP32-C3 boards, the LED may operate with inverted logic, meaning it turns ON with a LOW signal and OFF with a HIGH signal, depending on the board design.

    This breadboard test allowed validation of the circuit’s correct behavior and the interaction between the microcontroller and basic electronic components.

    Errors and Solutions - ESP32-C3

    Errors Found and Solutions – ESP32-C3

    Error 1: “D1 was not declared in this scope”

    Cause:

    The ESP32-C3 does not use the D1, D2, D3 naming convention like the Arduino UNO. Instead, it works directly with the actual GPIO pin numbers.

    Solution:

    Use the real GPIO number in the code.

    const int LED_PIN = 2;  // GPIO2
        

    Error 2: COM port busy or not found

    Possible Causes:

    • Incorrect port selected in the IDE
    • Faulty USB cable or charging-only cable
    • Driver not recognized by the system

    Solution:

    • Reconnect the board
    • Verify the correct port in Tools → Port
    • Replace the USB cable with a data cable
    • Restart the Arduino IDE if necessary

    Error 3: The LED was not blinking

    Possible Causes:

    • LED reversed (incorrect polarity)
    • Resistor incorrectly connected
    • Wrong GPIO pin defined in the code
    • Breadboard wiring mistake

    Solution:

    • Verify that the long leg is the anode (+)
    • Confirm that the resistor is connected in series
    • Make sure the GPIO number in the code matches the physical connection
    • Double-check all wiring before uploading the program again

    These errors were part of the learning process and helped improve the understanding of how the ESP32-C3 works, as well as the importance of carefully checking both the code and the hardware connections.

    Single image

    LED Simulation with ESP32-C3 in Wokwi

    The simulation was carried out using Wokwi, an online electronics simulator.

    1. Open Wokwi:
      Go to the Wokwi website and click on "New Project".
    2. Select the board:
      Choose the ESP32-C3 (XIAO ESP32-C3).
    3. Add components:
      Add the following components:
      • 1 red LED
      • 1 resistor (220Ω)
    4. Make the connections:
      Connect the circuit as follows:
      • GPIO2 (D2) → Resistor → LED anode
      • LED cathode → GND
    5. Programming:
      Insert the following code:
      Code: Basic LED ON (ESP32)
      void setup() {
        pinMode(2, OUTPUT); // Set pin as output
      }
      
      void loop() {
        digitalWrite(2, HIGH); // Turn on LED
      }
      
    6. Run the simulation:
      Click on "Start Simulation".

    Result: The LED turns on, confirming that the circuit works correctly.

    Single image Single image

    Learning - Programming of ESP32-C3

    • The ESP32-C3 does not use nomenclature like “D1”.
    • It is essential to respect the 3.3 V supply.
    • The upload process is different from the RP2040.
    • I better understood how COM ports work.
    • I learned to debug both hardware and software errors.
    • I understood the practical difference between ARM (RP2040) and RISC-V (ESP32-C3).
    • Correctly reading the datasheet helps prevent electrical mistakes.

    Individual Conclusions ESP32-C3

    This lab allowed me to understand the real difference between microcontrollers of different architectures. It was not just about programming, but about understanding:

    • Pin mapping
    • Environment configuration
    • Voltage levels
    • Firmware upload flow
    • Error diagnosis

    Working physically with the ESP32-C3 helped me consolidate concepts that seem simple in theory but require attention to detail in practice.

    Group Conclusions (RP2040 vs ESP32-C3)

    Programming two different microcontroller families allowed us to understand that the development workflow depends not only on the code, but also on correct environment configuration (board selection, drivers, and COM port management).

    The ESP32-C3 required more attention to setup details, especially using GPIO numbers instead of Arduino-style D pins and correctly selecting the COM port. This showed that many initial errors were related to the toolchain rather than the program logic.

    The RP2040 provided a more straightforward workflow for local hardware prototyping (button and LEDs), making debugging simpler and faster.

    As a team, we reinforced a structured debugging methodology:

    • Verify wiring
    • Select correct board and port
    • Compile
    • Upload
    • Validate using LED behavior and Serial Monitor

    Downloads

  • Source files (.zip)