Embedded Programming adios
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
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! 😄
This week, I met with Armando Calcina both in person and virtually to make progress on the group assignment. It was a challenge, but we’re moving forward. I received instructions from my instructor, Vaneza Caycho, who made several recommendations to help me gather information and research microcontrollers. Ronal also explained a lot to me about this topic, electronics, and programming; he was very patient and helped me a lot. Cristian provided me with some basic concepts that would help me with this assignment. With nothing more to say, let’s start the documentation! 😄📚
Group assignment
Demonstrate and compare the toolchains and development workflows for available embedded architectures.
Unique group
Evelyn Cuadrado & Armando Calcina
Armando and I decided to conduct research on two microcontrollers. I took responsibility for investigating the XIAO RP2040 microcontroller, while Armando researched an Arduino. Later, we created a comparative table between both microcontrollers to analyze their features and differences.
XIAO-RP-2040
Here you can view and download the data sheet.
The Seeed Studio XIAO RP2040 is as compact as the Seeed Studio XIAO SAMD21 but offers more power. It is equipped with the powerful dual-core RP2040 processor, capable of running at a flexible clock speed of up to 133 MHz, while maintaining low energy consumption. Additionally, the XIAO RP2040 features 264 KB of SRAM and 2 MB of integrated Flash memory, allowing for more programs to be stored and executed. Despite its small size, this board delivers excellent processing performance with minimal power usage.
Features
Powerful MCU: Dual-core ARM Cortex M0+ processor, flexible clock speed up to 133 MHz
Rich on-chip resources: 264 KB of SRAM and 2 MB of integrated Flash memory
Flexible compatibility: Compatible with Micropython/Arduino/CircuitPython
Easy project operation: Compatible with breadboards and SMD design, no components on the back
Small size: As small as a thumb (21 x 17.8 mm), perfect for portable devices and small projects
Multiple interfaces: 11 digital pins, 4 analog pins, 11 PWM pins, 1 I2C interface, 1 UART interface, 1 SPI interface, 1 SWD debug pad interface
Technical specifications
Item |
Value |
CPU |
Dual-core ARM Cortex M0+ processor up to 133MHz |
Flash Memory |
2MB |
SRAM |
264KB |
Digital I/O Pins |
11 |
Analog I/O Pins |
4 |
PWM Pins |
11 |
I2C interface |
1 |
SPI interface |
1 |
UART interface |
1 |
Power supply and dowloading interface |
Type-C |
Power |
3.3V/5V DC |
Dimensions |
21x17.8x3.5mm |
XIAO ESP 32C3
Here you can view and download the data sheet.
Seeed Studio XIAO ESP32C3 is an IoT mini development board based on the Espressif ESP32-C3 WiFi/Bluetooth dual-mode chip. ESP32-C3 is a 32-bit RISC-V CPU, which includes an FPU (Floating Point Unit) for 32-bit single-precision arithmetic with powerful computing power. It has excellent radio frequency performance, supporting IEEE 802.11 b/g/n WiFi, and Bluetooth 5 (BLE) protocols. This board comes included with an external antenna to increase the signal strength for your wireless applications. It also has a small and exquisite form-factor combined with a single-sided surface-mountable design. It is equipped with rich interfaces and has 11 digital I/O that can be used as PWM pins and 3 analog I/O that can be used as ADC pins. It supports four serial interfaces such as UART, I2C and SPI.
Features
Powerful CPU: ESP32-C3, 32bit RISC-V singlecore processor that operates at up to 160 MHz
Complete WiFi subsystem: Complies with IEEE 802.11b/g/n protocol and supports Station mode, SoftAP mode, SoftAP + Station mode, and promiscuous mode
Bluetooth LE subsystem: Supports features of Bluetooth 5 and Bluetooth mesh
Ultra-Low Power: Deep sleep power consumption is about 43μA
Better RF performance: External RF antenna include
Battery charging chip: Supports lithium battery charge and discharge management
Rich on-chip resources: 400KB of SRAM, and 4MB of on-board flash memory
Ultra small size: As small as a thumb(21x17.8mm) XIAO series classic form-factor for wearable devices and small projects
Reliable security features: Cryptographic hardware accelerators that support AES-128/256, Hash, RSA, HMAC, digital signature and secure boot
Rich interfaces: 1xI2C, 1xSPI, 2xUART, 11xGPIO(PWM), 4xADC, 1xJTAG bonding pad interface
Single-sided components, surface mounting design
Specifications Comparison
Item |
Seeed Studio XIAO ESP32C3 |
Seeel XIAO RP2040 |
Processor |
ESP32-C3 32 bit RISC-V @160MHz |
RP2040 Dual-core M0+@133Mhz |
Wireless Connectivity |
WiFi and Bluetooth 5 (BLE) |
N/A |
Memory |
400KB SRAM, 4MB onboard Flash |
264KB SRAM 2MB onboard Flash |
Built-in Sensors |
N/A |
N/A |
Interfaces |
I2C/UART/SPI |
I2C/UART/SPI |
PWM/Analog Pins |
11/4 |
11/4 |
Onboard Buttons |
Reset/ Boot Button |
Reset/ Boot Button |
Onboard LEDs |
Charge LED |
Full-color RGB/ 3-in-one LED |
Battery Charge Chip |
Built-in |
N/A |
Programming Languages |
Arduino/ MicroPythonType-C |
Arduino/ MicroPython/ CircuitPython |
Conclusion of the Comparison between the Microcontrollers: Seeed XIAO ESP32-C3 and Seeed XIAO RP2040
ChatGPT provided me with a detailed explanation of what microcontrollers are and how they work. Thanks to this information, I was able to better understand the characteristics and differences between the Seeed XIAO ESP32-C3 and the Seeed XIAO RP2040, which allowed me to make a more accurate and informed comparison.
Performance and Processor:
- The ESP32-C3 uses a 32-bit RISC-V processor and has built-in support for Wi-Fi and Bluetooth LE. This makes it ideal for applications that require wireless connectivity.
- The RP2040, on the other hand, features a dual-core ARM Cortex-M0+ processor, which provides good performance for general processing, but lacks built-in wireless capabilities.
Connectivity:
- The ESP32-C3 excels in projects that require Wi-Fi and Bluetooth connectivity, making it ideal for IoT (Internet of Things) applications and projects that need wireless communication.
- The RP2040 lacks direct wireless connectivity, so additional modules like Wi-Fi or Bluetooth would be necessary if the project requires such features.
Memory
- Both microcontrollers offer sufficient memory, but the RP2040 provides 264 KB of SRAM and 2 MB of flash memory, allowing for the storage of larger programs and more complex tasks without the need for additional modules.
- The ESP32-C3 has less SRAM (up to 400 KB), but its ability to handle wireless communication gives it an advantage in projects where connectivity is essential.
Compatibility and Ecosystem:
- Both microcontrollers are compatible with popular platforms like Arduino and Micropython, making them accessible for quick prototyping and for developers familiar with these environments.
- However, the ESP32-C3 has a more developed ecosystem, especially in terms of wireless communication, with libraries and projects geared toward IoT applications.
Power Consumption:
- The ESP32-C3 is designed to be energy-efficient, especially for tasks involving wireless communication.
- The RP2040 is also energy-efficient, but it is better suited for tasks that do not require continuous wireless connectivity.
Reflections
Based on the comparison, I personally believe that the SEEED XIAO RP2040 is the best option for the project I have in mind. Since the project will be relatively simple and does not require Wi-Fi connectivity or internet access, the features of the RP2040 better suit my needs.
The main focus of my project is to work with sensors, allowing it to turn on and/or move based on specific conditions.The SEEED XIAO RP2040, with its dual-core processor and efficient processing power, provides the necessary performance to effectively handle these sensors without the need for additional communication modules.
This simplifies the design and reduces costs, as I don't need to worry about integrating wireless connectivity. In summary, the RP2040 seems to be the best choice for projects like mine that focus on basic interaction with sensors and devices without the need for external connectivity.
Individual Assignment:
The Seeed Studio XIAO RP2040 is a small yet powerful board, featuring a dual-core ARM Cortex M0+ processor running at up to 133 MHz, 264KB of SRAM, and 2MB of Flash memory. It is compatible with MicroPython, Arduino, and CircuitPython, and has multiple interfaces including 11 digital pins, 4 analog pins, 11 PWM pins, 1 I2C interface, 1 UART, and 1 SPI.
The size is only 21x17.8 mm, making it ideal for small projects or portable devices. It operates with a 3.3V/5V power supply and connects via a Type-C port. It is also compatible with Seeed Studio’s XIAO expansion boards.Click here to learn more about this board.
Here is a summary of the pins, as they are important for connecting to other sensors and/or components.
- Power Pins:
3V3: Provides regulated 3.3V power.
GNDGround connection.
VBAT:Connected to a battery (if used), allows the retention of the non-volatile memory (RTC).
- General Purpose Input/Output (GPIO) Pins:
GPIO0 - GPIO28:These are general-purpose digital pins (configurable as inputs or outputs). Some of these pins also support additional functions such as PWM, I2C, SPI, UART, and ADC (Analog-to-Digital Conversion).
GPIO1 - GPIO4:Used for UART (serial communication).
GPIO10 - GPIO13:Support SPI (high-speed serial communication).
GPIO26 - GPIO28:Support ADC for reading analog signals.
- Communication Pins:
I2C:Uses GPIO4 (SDA) and GPIO5 (SCL) for I2C communication.
SPI:Uses GPIO10 (MOSI), GPIO11 (MISO), GPIO12 (SCK), and GPIO13 (CS) for SPI communication.
UART: GPIO0 (TX) and GPIO1 (RX) are used for UART communication.
- Analog Input Pins:
GPIO26 - GPIO28:Used for ADC (Analog-to-Digital Conversion), allowing you to read voltage levels between 0 and 3.3V.
- Special Pins:
RUN:Allows you to reset the microcontroller.
BOOTSEL:Used to put the board into bootloader mode for program flashing.
- Other Pins:
LEDThe Xiao RP2040 has a built-in LED on GPIO25, which can be controlled to indicate the board's status.
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. 😊🔧📚
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. 📑💡
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.
I opened a new whiteboard to start my programming.
In the "Boards Manager," I selected the XIAO RP 2040 microcontroller.
I selected "Raspberry Pi Pico / RP2040" and installed the package.
I had an issue trying to recognize the device on my laptop, in this case, the XIAO RP 2040. It wasn’t being recognized properly, so Ulises advised me to wait and use Thonny later.
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.
I searched for the "Raspberry Pi Pico / Pico H" variant and installed the package. 🖥️📥
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.
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.
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.
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)
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.
I also did a second test using a motion sensor. 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.
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).
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
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!