Skip to content

7. Embedded programming

Group assignment requirements

The group assignment for this week is the following:
- Browse through the datasheet for your microcontroller
- Compare the performance and development workflows for other architectures
- Document your work to the group work page and reflect on your individual page what you learned

Microcontroller datasheet

The microcontroller being used is the Xiao SAMD21 which is a micro-sized dev board based on a ATSAMD21G18A-MU microcontroller. To find the specs I am referring to the dev board’s datasheet here, and the microcontroller datasheet here. By going through the datasheet for both the microcontroller and XIAO dev board I learned a lot about the microcontroller including the following:

picture of the XIAO pin layout

The Xiao contains the following pins: 11 PWM pins 11 general digital pins 11 Analog pins 1 I2C interface

The XIAO dev board includes the following components:

  • 1 reset button
  • 1 user button
  • 1 power LED
  • 1 user LED
  • 1 USB connector for programming and power

As for the microcontroller itself, we found the following information from the datasheet:

picture of the microcontroller pin layout

10 PWM pins 38 general digital pins 14 Analog pins 1 I2C interface

As for the microcontroller itself, the ATSAMD21G18A-MU offers the following features:

CPU: ARM Cortex-M0+ running at up to 48MHz Flash Memory: 256KB SRAM: 32KB

screenshot of the system overview

According to the system overview, we learned that it contains the following peripherals:

  • UART
  • SPI
  • I2C
  • ADC

Architectures Comparison

As part of this assignment, we compared the specs of all the microcontrollers we have in the lab.

XIAO SAMD21 Arduino Mega Arduino Uno Raspberry Pi RP2040 Zero
Bit size 32-bit 8-bit 8-bit 32-bit
Max clock 48MHz 16MHz 16MHz 133MHz
CPU/Family/Architecture ARM Cortex-M0+ AVR ATMEGA2560 AVR ATMEGA328P ARM Cortex-M0+
Storage 256KB flash/32KB SRAM 256KB flash/8KB SRAM 32KB flash/2KB SRAM 2MB flash
I/O pins 20 general digital, 11 PWM, 6 Analog 54 digital, 15 analog, 15 PWM 14 digital, 6 analog, 6 PWM 26 digital, 3 analog
Operating voltage 3.3 volts 5 volts 5 volts 3.3 volts
Connectivity - - - Bluetooth, UART, SPI, I2C, GPIO
Price $5 $10 $5 $4
Source datasheet datasheet datasheet datasheet

Observations and Pros/Cons:

From the comparison, we found the following insights:

Arduino Mega:

  • Pros:
  • Offers a high number of I/O pins, suitable for complex projects.
  • Provides ample storage space for program code and data.
  • Cons:
  • Utilizes an 8-bit architecture, limiting computational capabilities compared to 32-bit microcontrollers.
  • Relatively slower clock speed compared to modern microcontrollers.

Arduino Uno:

  • Pros:
  • Offers a balance between simplicity and functionality, making it suitable for beginners and smaller projects.
  • Cost-effective option for basic embedded applications.
  • Cons:
  • Limited number of I/O pins and storage capacity compared to more advanced boards.

XIAO SAMD21:

  • Pros:
  • Utilizes a 32-bit architecture, providing enhanced computational capabilities.
  • Higher clock speed compared to Arduino Uno and Mega.
  • Ample storage and I/O options considering its compact size.
  • Cons:
  • Limited to USB connectivity, potentially restricting certain applications compared to boards with wireless connectivity options.

Raspberry Pi RP2040 Zero:

  • Pros:
  • Offers a 32-bit architecture with a high clock speed, providing enhanced performance.
  • Ample I/O options including Bluetooth connectivity, making it suitable for various applications.
  • Cost-effective option with sufficient storage capacity.
  • Cons:
  • Limited analog pins compared to Arduino boards.
  • Requires familiarity with Linux-based systems for programming and operation.

Considering these factors, each board has its own strengths and weaknesses, making them suitable for different types of projects and applications. While the Arduino Mega offers a higher number of I/O pins and storage compared to the Arduino Uno and XIAO, the XIAO stands out with its 32-bit architecture, higher clock speed, and ample storage and I/O options for its size. The Raspberry Pi RP2040 Zero provides a competitive alternative with its enhanced performance and connectivity options, albeit with some limitations in analog pins and programming environment.


Architectures development workflow

Xiao SAMD21

This microcontroller can be programmed via Arduino IDE which is based on C/C++. I tried programming it to do a simple blink

Setting up Arduino IDE:

  • Download and install Arduino IDE from the official website.
  • Install the board support package for XIAO by adding the Seeeduino SAMD boards URL to the Arduino IDE preferences.
  • Select the XIAO board from the board manager.

Programming:

  • Open Arduino IDE.
  • Write the code for the blink sketch.
  • Select the correct board and port.
  • Upload the code to the XIAO board.

// Pin D0 has an LED connected on Seeeduino XIAO
int led = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin D0 as an output.
  pinMode(led, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

The programming process for the XIAO SAMD21 microcontroller board, appears efficient and straightforward, with quick compilation and upload times. The board handles the process smoothly, utilizing a reasonable amount of program storage space (13% of maximum) and completing tasks such as chip erase and multi-page write swiftly without errors.

Arduino Uno

Programming the Arduino Uno is done through the Arduino IDE, which is based on C/C++. Below are the steps to set up the Arduino IDE and program the Uno for a simple blink sketch:

Setting up Arduino IDE:

  • Download and install Arduino IDE from the official website.
  • Ensure the correct drivers are installed for the Arduino Uno, if necessary.
  • Select the Arduino Uno board from the Tools > Board menu.

Programming:

  • Open Arduino IDE.
  • Write the code for the blink sketch.
  • Select the correct board (Arduino Uno) and port.
  • Upload the code to the Arduino Uno board.

// Pin 13 has an LED connected on Arduino Uno
int led = 13;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(led, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

The programming process for the Arduino Uno is similar to the XIAO SAMD21, offering a familiar and efficient workflow through the Arduino IDE. With successful compilation and upload, the Uno reliably executes tasks like blinking an LED. Compilation of the provided sketch utilizes only 936 bytes (2%) of the program storage space, while global variables utilize a mere 9 bytes (0%) of dynamic memory, underscoring the Uno’s efficient resource usage and suitability for various embedded projects.

Arduino Mega

Programming the Arduino Mega is achieved through the Arduino IDE, which is based on C/C++. Below are the steps to set up the Arduino IDE and program the Mega for a simple blink sketch:

Setting up Arduino IDE:

  • Download and install Arduino IDE from the official website.
  • Ensure the correct drivers are installed for the Arduino Mega, if necessary.
  • Select the Arduino Mega board from the Tools > Board menu.

Programming:

  • Open Arduino IDE.
  • Write the code for the blink sketch.
  • Select the correct board (Arduino Mega) and port.
  • Upload the code to the Arduino Mega board.

// Pin 13 has an LED connected on Arduino Mega
int led = 13;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(led, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

The programming process for the Arduino Mega closely resembles that of the XIAO SAMD21 and Arduino Uno, employing the Arduino IDE for a smooth and intuitive experience. Upon successful compilation and upload, the Mega demonstrates its proficiency in executing tasks like LED blinking. Notably, the compiled sketch utilizes a minimal 1548 bytes (0%) of program storage space, while global variables consume only 9 bytes (0%) of dynamic memory. These statistics underscore the Mega’s efficient resource utilization and its adaptability for diverse embedded applications.

Raspberry Pi RP2040 Zero

Programming the Raspberry Pi RP2040 Zero using the Arduino IDE offers a familiar and efficient workflow. Below are the steps to set up the Arduino IDE and upload a simple blink program to the RP2040 Zero:

Setting up Arduino IDE:

  • Download and install the latest version of the Arduino IDE from the official Arduino website.
  • Install the Arduino Core for Raspberry Pi RP2040 by adding the board manager URL to the Arduino IDE preferences.
  • Install the Raspberry Pi RP2040 Zero board support package from the board manager.

Programming:

  • Open Arduino IDE.
  • Write the code for the blink program.
  • Select the correct board (Raspberry Pi RP2040 Zero) and port.
  • Upload the code to the RP2040 Zero board.

// Pin 29 has an LED connected on RP2040 Zero board
int led = 29;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 29 as an output.
  pinMode(led, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

The programming process for the Raspberry Pi RP2040 Zero using the Arduino IDE provides a seamless experience, leveraging the familiarity of the IDE and the capabilities of the RP2040. The sketch uses 52260 bytes (2%) of program storage space, well within the maximum limit of 2093056 bytes, and global variables consume 10232 bytes (3%) of dynamic memory, leaving ample space for local variables.