6. Embedded programming¶
Group 1 (Ito-Yamada)¶
Assignment 1¶
- Browse through the data sheet for your microcontroller;
Feature | Xiao RP2040 | ATSAMD11C |  ATTINY1614 |
---|---|---|---|
CPU | Arm Cortex-M0+ | Arm Cortex-M0+ | 8-bit AVR |
Clock Speed | 133 MHz | 48 MHz | 20 MHz |
SRAM | 264 KB | 32 KB | 2 KB |
Flash Memory | 16 MB | 256 KB | 16 KB |
UART | 2 | 2 | 1 |
I2C | 2 | 2 | 1 |
SPI | 2 | 2 | 1 |
PWM Channels | 16 | 12 | 8 |
ADC Inputs | 8 | 12 | 8 |
Real-Time Clock | Yes | Yes | Yes |
Temperature Sensor | Yes | Yes | No |
Others | MicroSD card slot | Touch sensor controller, LCD controller | - |
Package | 40-pin QFN | 40-pin QFN | 14-pin SOIC |
Price | Low | Medium | Low |
Suitable Applications | Small and inexpensive development boards, applications requiring a real-time clock, temperature sensor, and microSD card slot | Applications requiring low power consumption, high performance, and a wide range of peripherals | Small electronic devices requiring low power consumption, a small package, and a wide range of peripherals |
Datasheet | download | download | download |
Note: Xiao RP2040 in the above table is the description of the board. While RP2040 has 30 GPIO pins (4 for analog input), Xiao RP2040 has 11 GPIO pins (4 for analog) available on the board.
Conclusion:¶
-
Xiao RP2040: Recommended for users looking for a small and inexpensive development board, or for users who need a real-time clock, temperature sensor, and microSD card slot.
-
ATSAMD11C: Recommended for users who need low power consumption, high performance, and a wide range of peripherals.
-
ATTINY1614: Recommended for small electronic devices that require low power consumption, a small package, and a wide range of peripherals.
Assignment 2¶
- Compare the performance and development workflows for other architectures
We picked up the following two boards.
Feature | Microbit v2.2 | Raspberry Pi Pico |
---|---|---|
Core | nRF52833 (ARM Cortex-M4) | RP2040 (Dual-core ARM Cortex-M0+) |
Max Clock Speed | 64MHz | 133MHz |
Memory (Flash) | 512KB | 2MB |
SRAM | 128KB | 264KB |
Digital I/O Pins | 25 (including 3 dedicated to the accelerometer and magnetometer) | 26 programmable I/O |
Analog Inputs | N/A | 3 ADC channels |
Interfaces | I2C, SPI, UART, Bluetooth Low Energy | I2C, SPI, UART, USB 1.1 Host/Device |
USB | Micro USB (Type-B) | Micro USB (Type-B) |
IO Voltage | 3V (1.8-3.6V) | 3.3V (1.8-3.3V) |
Max Operating Current | 300mA | 300mA |
Special Features | Built-in accelerometer, magnetometer, temperature sensor, light sensor, 25 LED matrix, speaker, microphone | Programmable IO (PIO) for custom peripheral support |
Datasheet | download | download |
Conclusion:¶
Microbit v2.2 is notable for its built-in sensors and 25 LED matrix, making it particularly suited for educational purposes and beginners to learn programming and electronics. It also includes Bluetooth Low Energy for wireless communication.
Also, please read the individual assignment page for further inforamtion about micro:bit.
Raspberry Pi Pico, on the other hand, features a more powerful dual-core processor and larger memory, plus the unique Programmable IO (PIO) for custom peripheral support, making it more versatile for a wide range of projects, including those requiring custom hardware interfaces.
Raspberry Pi Pico setup steps:¶
- Adjust Google Chrome settings for downloads.
- Download and install MicroPython firmware on the Raspberry Pi Pico.
- Connect the Raspberry Pi Pico to the computer using a USB cable, ensuring the “BOOTSEL” button is pressed while connecting.
- Install Thonny IDE on your computer, which is used for writing and uploading code to the Raspberry Pi Pico.
- Configure Thonny with MicroPython for Raspberry Pi Pico.
- Write and run a simple program to blink LEDs randomly.
Sample Code¶
import machine
import utime
import random
pwm_red = machine.PWM(machine.Pin(16))
pwm_green = machine.PWM(machine.Pin(17))
pwm_blue = machine.PWM(machine.Pin(18))
pwm_red.freq(1000)
pwm_green.freq(1000)
pwm_blue.freq(1000)
while True:
# Generate RGB value randomly.
red = random.randint(0, 255)
green = random.randint(0, 255)
blue = random.randint(0, 255)
# Controlling LED by PWM
pwm_red.duty_u16(int(red * 65536 / 256))
pwm_green.duty_u16(int(green * 65536 / 256))
pwm_blue.duty_u16(int(blue * 65536 / 256))
utime.sleep(0.05)
Also, please read the individual assignment page for further inforamtion about Raspberry Pi Pico and Thonny IDE.