Week 4 Embedded programming

It was a challenging week for me and I gained some embedded programming experience. Includes simple programming language, microcontroller features, etc. When the control program is running, it's really interesting.

Learning Objectives

Group assignment:

I have practiced embedded programming using Arduino Uno, micro:bit v2, and XIAO ESP32C3.

1. Tech specs

1.1 Comparison Between Arduino Uno, micro:bit v2, and XIAO ESP32C3

Feature Arduino Uno micro:bit v2 XIAO ESP32C3
Microcontroller ATmega328P nRF52833 ESP32-C3 (32-bit RISC-V)
Memory Flash: 32 KB, SRAM: 2 KB, EEPROM: 1 KB Flash: 512 KB, RAM: 128 KB Flash: 4 MB, SRAM: 400 KB
GPIO Pins 14 digital pins (6 support PWM), 6 analog input pins 25 programmable GPIO pins (including 3 analog inputs) 11 GPIO (6 PWM, 4 ADC, 1 DAC)
Communication Interfaces UART, SPI, I2C BLE, NFC, USB, SPI, I2C Wi-Fi, BLE, UART, SPI, I2C
Power Supply USB or External Power (7-12V) USB or Battery Pack (2xAAA Batteries) USB-C (5V), Li-Po Battery (3.7V)
Dimensions Approx. 68.6 mm x 53.4 mm Approx. 52 mm x 43 mm 21 mm x 17.5 mm
Programming Environment Arduino IDE (Primarily C/C++) MakeCode, MicroPython Arduino IDE, PlatformIO (C/C++)
Arduino Uno micro:bit v2 XIAO ESP32C3

1.2 Arduino Uno

The Arduino UNO is the best board to get started with electronics and coding. Datasheet

1.2.1 Board topology

1 1

1.2.2 Schematic diagram

1 1

1.2.3 Connector Pinouts

1

๐Ÿ› ๏ธ1.2.4Install Arduino IDE on Windows

โœ… Visit the Official Website Website

๐Ÿ’พ Download for Windows,Click on Windows Installer (for Windows)

๐Ÿ’ป Install the Arduino IDE

  1. Double-click the downloaded .exe file
  2. Accept the license agreement
  3. Select all components (default options are fine)
  4. Choose an installation location (or keep default)
  5. Click Install and wait for it to finish
  6. Click Finish to launch the Arduino IDE

1.2.5 Upload and Run Arduino Program

Step-by-Step Guide:

  1. ๐Ÿ”Œ Connect the Arduino Board: Use a USB cable to connect the Arduino to computer.
  2. ๐Ÿ–ฅ Open Arduino IDEArduino official website.
  3. โš™๏ธ Select Board & Port:
    • Go to Tools โ†’ Board and select your Arduino Uno.
    • Go to Tools โ†’ Port and select the correct port COM5.
  4. ๐Ÿ“‹ Code: Open the code.
  5. โœ… Compile & Upload Code:
    • Click the โœ”๏ธ (checkmark icon) to verify the code.
    • Click the โฌ†๏ธ (upload icon) to upload the code.
  6. ๐Ÿ“Ÿ Open Serial Monitor:
    • Go to Tools โ†’ Serial Monitor .(shift+alt+M)
    • Set baud rate to 9600.
    • Check code

1.3 micro:bit v2

The micro:bit is a tiny programmable computer designed by the BBC for education. Datasheet

1

1.3.1 Connector Pinouts

1 1

1.3.2 How to Run a Program on micro:bit

๐Ÿ› ๏ธ What You Need:

๐Ÿงฉ Method A: Using MakeCode (Block-Based Programming)

  1. Go to https://makecode.microbit.org
  2. Click "New Project" to start coding with blocks
  3. Click "Download" to get the .hex file
  4. Connect your micro:bit to your computer via USB
  5. Drag and drop the .hex file to the micro:bit drive
  6. The program will upload and start running automatically

๐Ÿง‘โ€๐Ÿ’ป Method B: Using Python (MicroPython)

  1. Go to https://python.microbit.org
  2. Write your Python code, for example:
from microbit import * while True: display.scroll("Hello!") sleep(1000)
  1. Click "Download" to get the .hex file
  2. Connect your micro:bit and drag the file into the drive

๐Ÿ“Œ Tips:

1.4 XIAO ESP32C3

The Seeed Studio XIAO ESP32C3 is a tiny and powerful development board with Wi-Fi and BLE capabilities, based on the ESP32-C3 RISC-V processor. Datasheet

1.4.1 Schematic Diagram

xiao_schematic xiao_schematic2

1.4.2 Connector Pinouts

xiao_pinout

๐Ÿ› ๏ธ 1.4.3 Install Arduino IDE and Setup for XIAO ESP32C3

โœ… Visit the Official Arduino Website Arduino IDE

๐Ÿ’พ Install Board Manager URL: Open Preferences and add this URL:https://espressif.github.io/arduino-esp32/package_esp32_index.json

xiao_schematic2

๐Ÿ”ง Board Manager: Go to Tools โ†’ Board โ†’ Boards Manager, search for ESP32 and install it.

๐Ÿ’ก Select Board: Go to Tools โ†’ Board and select Seeed XIAO ESP32C3.

xiao_schematic2 xiao_schematic2

1.4.4 Upload and Run Program

Step-by-Step Guide:

  1. ๐Ÿ”Œ Connect XIAO ESP32C3: Use a USB-C cable to connect it to your computer.
  2. ๐Ÿ–ฅ Open Arduino IDE
  3. โš™๏ธ Board & Port:
    • Tools โ†’ Board โ†’ Seeed XIAO ESP32C3
    • Tools โ†’ Port โ†’ COMxx
  4. ๐Ÿ“‹ Write or Open Code
  5. โœ… Compile & Upload:
    • Click the โœ”๏ธ icon to verify
    • Click the โฌ†๏ธ icon to upload
  6. ๐Ÿ“Ÿ Open Serial Monitor:
    • Tools โ†’ Serial Monitor (Shift + Alt + M)
    • Set baud rate to 115200

๐Ÿ“Œ Tips:

โœ… Summary

๐ŸŸฆ Arduino Uno

Arduino Uno is ideal for more advanced users who want flexibility and hardware control. Great for robotics, sensors, and real-world device building.

๐ŸŸฉ micro:bit

micro:bit is perfect for beginners and education. It has built-in features that make learning fast and fun, especially in classrooms.

๐ŸŸง XIAO ESP32C3

XIAO ESP32C3 is compact yet powerful, making it excellent for IoT projects, wearable tech, and wireless applications. With built-in Wi-Fi, BLE, and support for modern development tools, it bridges the gap between beginner boards and professional solutions.

Individual assignment:

2.1 Dual-color light

Using an Arduino UNO board to design a red-green dual-color LED system

2.1.1 Code

1

2.1.2 Running & Testing

1 1

2.2 RGB light with seven colors

Using a micro:bit to create a seven-color LED system

2.2.1 Code

1

2.2.2 Running & Testing

2.3 Smiley face and heart button lights

Using a micro:bit to create smiley face and heart button lights>

2.3.1 Code

1

2.3.2 Running & Testing

2.4 Timer

Using a micro:bit to build a timer

2.4.1 Code

1

2.4.2 Running & Testing

2.5 Rainbow LED blinking

Using the Seeed Studio XIAO ESP32-C3 to control a multi-color LED

2.5.1 Code

1

2.5.2 Running & Testing

2.6 XIAO ESP32C3 Scanning Bluetooth Devices

Connect the XIAO ESP32C3 to your computer using a USB Type-C data cable to scan for available Bluetooth devices nearby.

2.6.1 Code

1

2.6.2 Running & Testing

1

2.7 XIAO ESP32C3 as a Bluetooth Server

Connect the XIAO ESP32C3 to your computer using a USB Type-C data cable. Use your smartphone to search for the XIAO ESP32C3 development board and send the string โ€œhelloโ€ to display it in the Serial Monitor.

1

2.7.1 Code

1

2.7.2 Download and Install the LightBlue App on Your Smartphone

LightBlue App (Android)

1

Turn on Bluetooth on your smartphone, place it close to the XIAO ESP32C3, scan for devices, and connect to the device named โ€œMyESP32โ€.

Tap the CONNECT button next to MyESP32.

1

Tap the section at the bottom showing Readable and Writable properties.

1

In the Data format dropdown menu, select UTF-8 String.

In the WRITTEN VALUES field, enter "Hello" and click WRITE.

1

2.7.3 Testing

You will see the text string "Hello" displayed in the Serial Monitor of the Arduino IDE.

1

Process video

CODE

Code2.1 for this week Code2.2 for this week Code2.3 for this week Code2.4 for this week Code2.5 for this week Code2.6 for this week Code2.7 for this week