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

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.

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

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



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:

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:

l2c oled 1306

4x buttons
2x 10k resistors

a red and green led

piezo buzzer
Getting started

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

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


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

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.

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 |