• Home
  • About me
  • Assigments
  • Final Project
  • Agreement

Embedded Programming

Group Assignment:

  • Demonstrate and compare the toolchains and development workflows for available embedded architectures.

  • Individual Assignment:

  • Browse through the data sheet for your microcontroller write a program for a microcontroller,and simulate its operation,to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)
  • Extra credit: test it on a development board
  • Extra credit: try different languages &/or development environments

  • Morning Sunshine Haggard GIFfrom Morning Sunshine GIFs

    Have you answered these questions?

    Linked to the group assignment page ✅

    Browsed and documented some information from your microcontroller's datasheet ✅

    Programmed your simulated board to interact and communicate ✅

    Described the programming process(es) you used ✅

    Included your source code ✅

    Included ‘hero shot(s)’ ✅


    Group assignment

  • Demonstrate and compare the toolchains and development workflows for available embedded architectures.
  • Image

    This week is a big challenge for me because I don't know anything about programming, but here I am, studying and staying up all night to achieve results! Help! 😄

    For our group project, I researched two microcontrollers: the RP2040 and the ESP32-C3.

    Here is the link to learn more about the group project.



    Reflections

    During the analysis of the RP2040 and ESP32-C3 microcontrollers, I was able to realize the main differences and features of each one, which helped me better understand their applications and advantages.

    1. RP2040 (Xiao RP2040): This Raspberry Pi microcontroller seemed very interesting to me because of its simplicity and energy efficiency. It has an ARM Cortex-M0+ dual-core processor at 133 MHz, which makes it suitable for projects requiring low power consumption. Additionally, with its 26 GPIO pins and support for multiple communication protocols like PWM, SPI, I2C, and UART, I realized it's a very versatile option for IoT and robotics projects. The ease of programming it with environments like Arduino or MicroPython also makes it appealing, as it allows me to get my projects up and running quickly.
    2. ESP32-C3: On the other hand, the ESP32-C3 caught my attention because of its power and connectivity. With a 32-bit RISC-V processor at 160 MHz, along with built-in Wi-Fi and Bluetooth 5.0, it’s an excellent option for projects requiring wireless communication. This microcontroller seems ideal for IoT applications that need internet or Bluetooth connectivity. Its compact size and multiple interface options make it very versatile and useful for a wide range of projects.

    In summary, both microcontrollers have their own advantages depending on the type of project I want to develop. The RP2040 is perfect if I'm looking for efficiency and simplicity in low-power projects, while the ESP32-C3 is a more powerful and connected option, ideal for projects that need wireless connectivity.


    Individual Assignment:

    Image

  • Browse through the data sheet for your microcontroller write a program for a microcontroller,and simulate its operation,to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)
  • Extra credit: test it on a development board
  • Extra credit: try different languages &/or development environments



  • 1.Instructor's Guide

    Image

    To start this assignment, I met with Ronal after class on Wednesday. He gave me some electronic components to help me develop the assignment. The next day, one of my instructors, Cristian, handed me some electronic components from Ifurniture and explained to me, in basic terms, how they worked. That same day, I went to Paruro to buy some things I still needed. 😊🔧📚



    Image

    I also met with my instructor Vaneza, who gave me some tips to improve my documentation and some basic concepts that I should keep in mind for this assignment. 📑💡

    Image

    On February 15th, Ulises prepared a master class in Spanish where he taught us how to use programming languages like Arduino API, C++, and MicroPython. During the session, he provided us with resources and practical examples to apply these languages in electronics projects.



    2. Programming Protocol

    Microcontroller Selection: RP 2040 Microcontroller

    Feature Specification
    Processor 2 ARM Cortex-M0+ cores at 133 MHz
    SRAM 264 KB
    Flash Memory Up to 16 MB external via QSPI
    GPIO 26 I/O pins, 4 of them analog
    Peripherals 2 UART, 2 SPI, 2 I²C, 16 PWM channels, 4 ADC channels
    USB Connectivity USB 1.1 (Host and device)
    PIO (Programmable I/O) 8 state machines
    RTC (Real-Time Clock) Yes
    Temperature Sensor Yes
    Manufacturing Process 40 nm
    Package QFN-56 (7x7 mm)

    The RP2040 is a microcontroller created by Raspberry Pi, which acts as the "brain" of many electronic devices. It's a small chip used to control how different devices work, such as robots, smart lights, or even educational tech projects.

    Here is the link: Data Sheet



    Implementing Programming Protocols on the RP2040

    To communicate the microcontroller with other devices, it's essential to use standard protocols. Here’s a general flow:

    1. Select the protocol (UART, I²C, SPI, or USB).
    2. Assign the correct GPIO pins using the RP2040 datasheet.
    3. Initialize the protocol in code (C/C++ or MicroPython).
    4. Transmit and receive data, managing buffers if needed.
    5. Verify communication via serial monitor, oscilloscope, or logic analyzer.

    Each protocol serves different purposes:

  • UART: basic PC or module communication.
  • I²C: ideal for sensors.
  • SPI: fast data exchange (e.g., displays).
  • USB CDC: virtual serial without extra hardware.


  • Development Environment Setup:

    Arduino IDE

    Image

    I downloaded Arduino from the official website. Here’s the link so you can download it too. I configured the location where I would save the software on my computer.



    Image

    I opened a new whiteboard to start my programming.



    Image

    In the "Boards Manager," I selected the XIAO RP 2040 microcontroller.



    Image

    I selected "Raspberry Pi Pico / RP2040" and installed the package.



    Image

    I encountered an issue when trying to recognize the XIAO RP 2040 device on my laptop, as it was not being detected properly. Ulises advised me to use Thonny, so I decided to proceed with that approach. Below, I will explain how to install Thonny.


    Thonny

    Image

    I downloaded Thonny (here’s the link), which is an integrated development environment (IDE) designed specifically for Python programming. It’s very popular among beginners due to its simple and user-friendly interface. Thonny makes it easy to write, run, and debug Python programs, and has features like:

  • A user-friendly interface with minimal distractions.
  • An integrated debugger that allows you to follow the code flow step by step.
  • Simplified package management, which makes it easy to install additional libraries.
  • Support for Python on microcontrollers, like using MicroPython on devices such as the Raspberry Pi Pico.


  • Image

    I searched for the "Raspberry Pi Pico / Pico H" variant and installed the package. 🖥️📥



    Image

    This selected part is a variable, but what is a variable?

    In the context of MicroPython and microcontrollers like the Raspberry Pi Pico or the XIAO RP2040, variables are used to store information such as sensor inputs, calculated values, or device configurations. Additionally, Thonny provides an environment where you can view and manage these variables while debugging your code.



    Image

    This part is known as a function. It is a block of code that performs a specific task and can be reused multiple times within the program.

    In the context of MicroPython and microcontrollers like the Raspberry Pi Pico or the XIAO RP2040, functions are useful for breaking the code into smaller, manageable parts. For example, you could create a function to read a sensor and another to control a motor, making your program more organized and easier to maintain.



    Image

    I opened the program. The great thing about the XIAO RP 2040 microcontroller is that I can import specific libraries to interact with hardware, such as controlling motors, screens, sensors, and more.

    In the MicroPython Official Library, I can find a complete list of supported libraries, thoroughly documented, for working with various microcontrollers like the Raspberry Pi Pico and XIAO RP 2040.

    Code Writing - LED

    Now we start to experiment a bit.

    With some light control libraries already in hand, we started to test and experiment.

                                    from machine import Pin, Timer
                                    ledAzul = Pin(25, Pin.OUT)
                                    ledRojo = Pin(17, Pin.OUT)
                                    ledVerde = Pin(16, Pin.OUT)
    
                                    Counter = 0
                                    Fun_Num = 0
     
                                    def fun(tim):
                                        global Counter
                                        Counter = Counter + 1
                                        print(Counter)
                                        ledVerde.value(1)
                                        ledRojo.value(1)
                                        ledAzul.value(Counter%2)
        
     
                                    tim = Timer(-1)
                                    tim.init(period=1000, mode=Timer.PERIODIC, callback=fun)
                                    

    Simulation in Wokwi Led

    I conducted a simulation of the same LED in the Wokwi program, using a Raspberry Pi Pico as the base, which is the closest to the RP2040 microcontroller. This will help me carry out future simulations more easily and efficiently.



    Code Execution - LED

    Now, I’m running a test for blinking LED lights using multiple lights connected to specific pins. In this case, I have three LEDs: one blue, one red, and one green, and the code is designed to make the blue LED blink periodically.

    I’m using the Timer module from MicroPython to set up a periodic interrupt that updates the LEDs' states every second. In this example, the green and red LEDs stay on, while the blue LED blinks every second. The Counter variable is incremented each time the interrupt function is executed, and the state of the blue LED changes depending on whether the counter is even or odd.

    Motion Sensor

    As part of the practice, I will use a motion sensor to create a program and also a simulation.

    In this case, I connected a PIR sensor (Passive Infrared) to the microcontroller to detect changes in the environment, such as the movement of a person. The sensor generates a digital signal that can be read from a pin on the microcontroller. At first, it was a bit frustrating because the sensor didn’t react as expected, but after adjusting the settings and wait times in the code, I got it to work properly.

    For this exercise, I am using a HC-SR501 motion sensor.

    Image

    The HC-SR501 is a PIR (Passive InfraRed) motion sensor, and it has three main pins for its operation.

  • VCC: Connect to 5V or 3.3V.
  • GND: Connect to GND on the development board.
  • OUT: Connect to a digital pin on the board to read the output (HIGH/LOW).

  • Code Writing - HC-SR501

    I used the following code:

                                        from machine import Pin
                                        import time
    
                                        # Initialize PIR sensor on pin D1 (GPIO1) as input
                                        pir = Pin(1, Pin.IN)
                                        # Initialize LED on pin D0 (GPIO0) as output
                                        led = Pin(0, Pin.OUT)
    
                                        # Optional: Calibration delay for PIR sensor (30-60 seconds)
                                        print("Calibrating PIR sensor...")
                                        for i in range(30):
                                            print(f"Calibration time remaining: {30 - i} seconds")
                                            time.sleep(1)
                                        print("Calibration complete!")
                                        print("Monitoring for motion...")
    
                                        while True:
                                            motion_detected = pir.value()  # Read PIR sensor value
        
                                            if motion_detected:
                                                print("Motion detected!")
                                                led.value(1)  # Turn LED ON
                                            else:
                                                led.value(0)  # Turn LED OFF
        
                                                time.sleep_ms(1)  # Short delay to reduce CPU usage
                                    

    Simulation in Wokwi Motion Sensor

    Now, I will carry out the simulation in Wokwi.



    Code Execution - HC-SR501

    During this activity, I encountered some difficulties, as the sensor did not respond to motion detection, but only activated when I touched a nearby object. I believe the issue is related to the microcontroller. I will be checking the system in the coming days to improve this process. Nevertheless, I felt very happy to get to this point, as I know nothing about electronics.


    Reflections

  • Developing this assignment, without prior knowledge of electronics, was truly a challenge. I still find it a bit difficult to understand some concepts, but I am reading and continuing my learning process to better understand the architecture. I managed to create two simulations in Tinkercad: one of them was playing with the built-in LEDs on the Xiao RP2040, using the green, red, and blue colors. Additionally, I was able to simulate a motion sensor.
  • It was very helpful to print the specifications of the Xiao RP2040 to understand the pins and, in the same way, the motion sensor. This allowed me to understand where to connect each circuit. I still have a lot to learn, but we’re making progress!

  • Access to files

  • Blink Leds
  • Motion Sensor


  • < Previous Page Next Page >

    © copyright 2025. Designed by Evelyn Cuadrado

    fabcloud/fabacademy/2025/labs/lima/students/evelyn-cuadrado