4. Embedded Programming¶
Assignments and Assessment this week¶
- Group assignment:
- Demonstrate and compare the toolchains and development workflows for available embedded architectures
-
Document your work to the group work page and reflect on your individual page what you learned
-
Individual assignment:
- Browse through the datasheet for a microcontroller
- Write and test a program for an embedded system using a microcontroller to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)
Learning outcomes¶
- Implement programming protocols.
Have you answered these questions?¶
- Linked to the group assignment page
- Browsed and documented some information from a microcontroller’s datasheet
- Programmed a board to interact and communicate
- Described the programming process(es) you used
- Included your source code
- Included ‘hero shot(s)’
Group Assignment¶
Individual Assignment¶
Browse through the datasheet for a microcontroller¶
I read through several micro controllers’ data sheets.
-
ESP32C3¶
—> SEEED Studio ESP32C3 Explanation
—> Purchasing Seeed Studio XIAO ESP32-C3 USD $4.90
Specification
| Parameter | Description |
|---|---|
| Processor | ESP32-C3 SoC RISC-V single-core 32-bit chip processor with a four-stage pipeline that operates at up to 160 MHz |
| Wireless | Complete 2.4GHz Wi-Fi subsystem Bluetooth Low Energy 5.0/ Bluetooth Mesh |
| On-chip Memory | 400KB SRAM & 4MB Flash |
| Interface | 1x UART(Universal Asynchronous Receiver / Transmitter) 1x IIC(Inter‑Integrated Circuit) 1x SPI(Serial Peripheral Interface) 11x GPIO(General‑Purpose Input / Output)(PWM) 4x ADC (Analog to Digital Converter) 1x Reset button 1x Boot button |
| Dimensions | 21 x 17.8mm |
| Power(Typ.) | Max 3.3V Output Current: 500mA Test Condition: BAT Pin Input @ 3.8V Source Capability: 3A Charging current: 380mA(Fast) / 40mA(Trickle) Input voltage (VIN): 5V Input voltage (BAT): 3.7V |
| Deep Sleep Power Consumption | Deep Sleep Mode: 44 μA |
| Wi-Fi Enabled Power Consumption |
Active Mode: 75 mA Modem-sleep Mode: 25 mA Light-sleep Mode: 4 mA |
| BLE Enabled Power Consumption | Modem-sleep Mode: 27 mA Light-sleep Mode: 10 mA |
| Working Temperature | -40°C ~ 85°C |
Pin Map¶
Pin List¶
| XIAO Pin | Function | Chip Pin | Alternate Functions | Description |
|---|---|---|---|---|
| 5V | VBUS | Power Input/Output | ||
| GND | ||||
| 3V3 | 3V3_OUT | Power Output | ||
| D0 | Analog | GPIO2 | ADC1_CH2, | GPIO, ADC |
| D1 | Analog | GPIO3 | ADC1_CH3 | GPIO, ADC |
| D2 | Analog | GPIO4 | ADC1_CH4, FSPIHD, MTMS | GPIO, ADC |
| D3 | Analog | GPIO5 | ADC2_CH0, FSPIWP, MTDI | GPIO, ADC |
| D4 | SDA(Serial Data Line) | GPIO6 | FSPICLK, MTCK | GPIO, I2C Data |
| D5 | SCL(Serial Clock Line) | GPIO7 | FSPID, MTDO | GPIO, I2C Clock |
| D6 | TX(Transmit) | GPIO21 | U0TXD | GPIO, UART Transmit |
| D7 | RX(Receive) | GPIO20 | U0RXD | GPIO, UART Receive |
| D8 | SCK(Serial Clock) | GPIO8 | GPIO, SPI Clock | |
| D9 | MISO (Master In, Slave Out) | GPIO9 | GPIO, SPI Data | |
| D10 | MOSI (Master Out, Slave In) | GPIO10 | FSPICS0 | GPIO, SPI Data |
| MTDO | GPIO7 | JTAG (Joint Test Action Group) | ||
| MTDI | GPIO5 | JTAG, ADC | ||
| MTCK | GPIO6 | JTAG, ADC | ||
| MTMS | GPIO4 | JTAG, ADC | ||
| Reset | CHIP_EN | EN (Enable) | ||
| Boot | GPIO9 | Enter Boot Mode | ||
| U.FL-R-SMT1 | LNA_IN | UFL antenna (for Wi‑Fi / Bluetooth / GPS) | ||
| Light | VCC_3V3 | CHG-LED |
-
ESP32 Datasheet¶
-
Nomenclature
-
Pin Layout

* Pin Overview


XIAO RP2040 Pin Map
Firstly, I wanted to make a system by pushing a button to light the LED and send a message to PC that lighting condition either light on or light off.
Plug in XIAO RP2040 USB-C to PC USB-C port by pressing the Board’s reset button locates at the bottom left.
Connect the board to PC via USB-C.
If the PC could consider the USB-C input as the external board, you will see the following;
RP2040 being designed for “Rasberry Pi”, the setup of Adruino IDE should be chosen as “Rasberry Pi”.
As a beginner, I asked Copilot the following question to see how the normal programming would be.
I am using XIAO RP2040.
connect from XIAO RP2040 D0 to a Button Switch
Button Switch to ??? which pin should I input?
GRD pin to resister
resister to LED light -
LED light + to ??? which pin should I input?
I had following answer from copilot;
| Purpose | Pin |
|---------|--------|
|Button input|D0|
|LED output|D1|
|Ground|GND|
|Power|Not needed (we use internal pull‑up)|
We will: * Use INPUT_PULLUP for the button (no resistor needed for the button) * Use one resistor (220–330Ω) for the LED
2️⃣ Wiring (important part) ✅ Button wiring (D0) You asked:
Button Switch to ??? which pin should I input?
Correct wiring: D0 ─── Button ─── GND
One side of the button → D0 Other side of the button → GND No resistor needed (we use internal pull‑up)
Logic:
Button NOT pressed → D0 = HIGH Button pressed → D0 = LOW
✅ LED wiring (D1) You asked:
GND pin to resistor to LED light – LED light + to ??? which pin should I input?
Correct wiring: D1 ─── Resistor (220–330Ω) ─── LED + (long leg) LED – (short leg) ─── GND
So:
D1 → resistor → LED + LED − → GND
⚠️ LED polarity matters:
Long leg = + Short leg = −
✅ Summary wiring diagram (text) XIAO RP2040
D0 ── Button ── GND
D1 ── 220Ω ── LED(+) LED(-) ── GND
3️⃣ Arduino program (Button toggles LED + sends message) This program:
Press button → LED toggles ON / OFF Sends message to PC:
“LED is ON” “LED is OFF”
Complete code by Copilot¶
const int buttonPin = D0;
const int ledPin = D1;
bool ledState = false;
bool lastButtonState = HIGH;
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // internal pull-up
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
}
void loop() {
bool buttonState = digitalRead(buttonPin);
// Detect button press (HIGH → LOW)
if (lastButtonState == HIGH && buttonState == LOW) {
ledState = !ledState; // toggle LED
digitalWrite(ledPin, ledState);
if (ledState) {
Serial.println("LED is ON");
} else {
Serial.println("LED is OFF");
}
delay(200); // simple debounce
}
lastButtonState = buttonState;
}
4️⃣ What you will see 🔹 On the board
Press button → LED turns ON Press again → LED turns OFF
🔹 On PC (Serial Monitor, 115200 baud) LED is ON LED is OFF LED is ON
5️⃣ Common mistakes to avoid ❌ Connecting LED without resistor ❌ Connecting button to 3.3V instead of GND when using INPUT_PULLUP ❌ Forgetting LED polarity ❌ Using D0 for Serial RX (XIAO RP2040 is OK, unlike Arduino Uno)
In order to understand the meaning of each command, I also asked Copilot as follows;
Can you explain the meaning of each coding line of following coding line by line?
I made explanation sheet based on the explanation from Copilot as follows;
Firstly, I copied above code into my Arduino IDE as follows;

Although the board works as requested, there is an error at the bottom end of the Arduino IDE telling “Not Connected. Select a board and a port to connect automatically.”
Then I asked the copilot again as follows;
Serial monitor is telling not connected to the board
Copilot: That message is normal Arduino IDE 2 behavior and it means Arduino IDE does not currently know which board + port to connect the Serial Monitor to. We’ll fix it step by step. This is not a wiring problem.
✅ What the message means
“Not connected. Select a board and a port to connect automatically.”
This means one (or both) of these is missing:
❌ Board not selected ❌ Port not selected
Serial Monitor cannot connect until BOTH are selected.
✅ Step‑by‑step fix (do this in order) ✅ 1. Close Serial Monitor First, close the Serial Monitor tab.
✅ 2. Select the Board (very important) In Arduino IDE menu: Tools → Board → Seeed RP2040 Boards → Seeed XIAO RP2040
✅ After this, the board name should appear at the top bar of Arduino IDE.
✅ 3. Select the Port (this fixes 90% of cases) Now go to: Tools → Port
You should see one new port after plugging in the board. Choose:
Windows → COMx macOS → /dev/tty.usbmodemXXXX Linux → /dev/ttyACM0
✅ If no port appears, see section ⚠️ If NO port appears below.
✅ 4. Upload the sketch again Click Upload (→) and wait for: Done uploading.
✅ This confirms the board + port are correct.
✅ 5. Open Serial Monitor again Tools → Serial Monitor
Now the yellow bar should be gone ✅
✅ 6. Set Baud Rate Bottom‑right of Serial Monitor: 115200
Must match: C++Serial.begin(115200);その他の行を表示する
✅ Expected result Now when you press the button, you should see: LED is ON LED is OFF
Following the guidance of Copilot, I selected Port as follows;
Serial Monitor Selected;
Then, the Serial Monitor responded as follows;
Press button circuit with XIAO RP2040¶
Here under is the video of “Push Button LED”.
I need to understand why it sometimes changes the behavior by “continuous pushing” and “one quick pushing”.