Skip to content

Week_04

embedded programming assignment:

• browse through the data sheet for a microcontroller
      • write and test a program for an embedded system using a microcontroller
         to interact (with input &/or output devices)
         and communicate (with wired or wireless connections)
      • extra credit: assemble the system
      • extra credit: try different languages &/or development environments

BEHOLD!… THE RP2350

I chose the Xiao seeed RP2350 because because I am both a Rasperry Pi fanboy and a Xiao seeed fanboy

w4_1.jpg

It’s really good!

I have used the RP2040 in the form of the pico W in the past to teach IoT and it is awesome

This is an upgrade and it comes in the awesome Xiao Seeed small form factor.

w4_5.jpg

It is powerful and versatile and available in different form factors and in RISCV and Arm

w4_6.jpg

And both Xiao Seeed and Raspberry Pi always have amazing documentation:

w4_3.jpg

w4_4.jpg

w4_2.jpg

First task for this week:

• write and test a program for an embedded system using a microcontroller to interact (with input &/or output devices) and communicate (with wired or wireless connections) • extra credit: assemble the system

Qpad:

w4_7.jpg

Since its Chinese spring festival and no deliveries are arriving I will attempt to make a Qpad like hand held game conesole with the rp2350 with stuff I have in my home maker space

I have:

w4_8.jpg

l2c oled 1306

w4_9.jpg

4x buttons

w4_10.jpg 2x 10k resistors

w4_11.jpg

a red and green led

w4_12.jpg

piezo buzzer

Getting started

w4_13.jpg

breadboard and connectors

I want to experiment with AI and see which one is best for coding fun devices like this so I put the following prompt into Chat gpt, Google Gemini and Claude.

Prompt:

“I want to make a pacman style game for a prototype hand held gaming system. the system will consist of a Xiao Seeed rp2350, a l2c oled1306, a piezo buzzer, a red led, a green led and 4 buttons. I want to use thonny IDE to program the rp2350”

Claude gave the best response and even gave a wiring guide, libraries, instructions as well as the code in a folder containing the files in text format without being prompted

w4_14.jpg

I downloaded the files and opened the wiring guide and assembled the circuit

## Wiring Diagram

### Pin Connections:

#### I2C OLED Display (SSD1306):

OLED VCC → Xiao 3.3V
OLED GND → Xiao GND
OLED SDA → Xiao GPIO 6 (I2C1 SDA)
OLED SCL → Xiao GPIO 7 (I2C1 SCL)


#### Piezo Buzzer:

Buzzer (+) → Xiao GPIO 26
Buzzer (-) → Xiao GND


#### LEDs:

Red LED (+) → Xiao GPIO 27 (with 220Ω resistor)
Red LED (-) → Xiao GND

Green LED (+) → Xiao GPIO 28 (with 220Ω resistor)
Green LED (-) → Xiao GND


#### Control Buttons:

Button UP → Xiao GPIO 2 (one side) and GND (other side)
Button DOWN → Xiao GPIO 3 (one side) and GND (other side)
Button LEFT → Xiao GPIO 4 (one side) and GND (other side)
Button RIGHT → Xiao GPIO 5 (one side) and GND (other side)


It worked perfectly but I had the screen upside down to fit everything perfectly and claud didn’t know this so i simply asked claude to flip the display vertically

Setup:

For this assignment I will be using Thonny IDE and the Micropython programming language so we will need to download thonny and the mycropython uf2 file for the Xiao Seeed

IDE Thonny

uf2: uf2

w4_16.jpg

w4_15.jpg

it worked perfectly the buttons on the left are for up and down and the buttons on the right are for left and right the green led flashes when pac man eats something and the red one flashes when you die with an accompanied sound from the piezo buzzer

pacman_game.py

SETUP_GUIDE.md

ssd1306.py

neil_fortune_teller_xiao_rp2350.jpg

I didn’t know about PIO

During the global lecture the Oracle (Neil) mentioned PIO and mentioned that they can be used to interface with components using assembly language which allows you to avoid one of the drawbacks of using a microcontroller that uses python which is having access to the libraries necessary for each component. This was news to me and sounds like a game changer so I did some research using AI.

w4_18.jpg

What PIO is (simple explanation)

PIO is a set of tiny, dedicated hardware state machines inside the microcontroller that you can program to control pins directly — independently of the main CPU.

Think of it like:

  • The CPU = the brain doing logic and calculations
  • PIO = small robotic assistants that handle precise signal timing

They can run tasks in parallel while the CPU does something else.

Why PIO exists

Normally, when a microcontroller needs to:

  • Generate a waveform
  • Read a custom protocol
  • Bit-bang a communication signal
  • Precisely time pulses

…the CPU has to constantly babysit the pins.PIO removes that burden.

It lets you:

  • Create custom hardware behaviors
  • Offload timing-critical work
  • Run multiple digital protocols at once

Pin mapping

XIAO pin Function Chip pin Backup function Description
five V VBUS Power input/output
GND
three v three 3V3_OUT Power output
D0 analog GPIO26 GPIO, ADC
D1 analog GPIO27 GPIO, ADC
D2 analog GPIO 28 GPIO, ADC
D3 SPIO_CSN GPIO5 GPIO, SPI
D4 SDA one GPIO six GPIO, I2C data
D5 SCL1 GPIO 7 GPIO, I2C clock
D6 TX zero GPIO 0 GPIO, UART send
D7 RX0 GPIO1 GPIO, UART reception
D8 SPIO_SCK GPIO2 GPIO, SPI clock
D9 SPIO_MISO GPIO4 GPIO, SPI data
D10 SPIO_MOSI GPIO3 GPIO, SPI data
D11 RX1 GPIO21 GPIO, UART reception
D12 TX1 GPIO20 GPIO, UART send
D13 SCL0 GPIO17 GPIO, I2C clock
D14 SDA 0 GPIO16 GPIO, I2C data
D15 SPI1_MOSI GPIO11 GPIO, SPI data
D16 SPI1_MISO GPIO 12 GPIO, SPI data
D17 SPI1_SCK GPIO 10 GPIO, SPI clock
D18 SPI1_Csn GPIO nine Csn
ADC_BAT GPIO29 Read the battery voltage value
Reset run run
boot RP2040_BOOT Enter the startup mode
CHARGE_LED NCHG CHG-LED_Red
RGB LED GPIO22 RGB LED
USER_LED GPIO25 User indicator light_yellow