4.Embedded Programming¶
Group Assignment: Embedded Programming¶
Simulation with TinkerCAD and Arduino UNO¶
Before touching any hardware, we started with a simulation. TinkerCAD lets you wire up virtual components and run code without risking anything, so it made sense to begin there.
We set up an Arduino UNO with a 4-pixel NeoPixel strip. The goal was simple: make each LED show a different color.
The code uses the Adafruit NeoPixel library. In setup() we initialize the strip and turn everything off. In loop() we go through each pixel with a for loop and use a switch/case to assign a different color to each one — blue, green, red, yellow.
#include <Adafruit_NeoPixel.h>
#define PIN 4
#define NUMPIXELS 4
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
strip.setBrightness(50);
}
void loop() {
for(int i=0; i<NUMPIXELS; i++) {
switch(i) {
case 0: strip.setPixelColor(i, strip.Color(0, 0, 255)); break;
case 1: strip.setPixelColor(i, strip.Color(0, 255, 0)); break;
case 2: strip.setPixelColor(i, strip.Color(255, 0, 0)); break;
case 3: strip.setPixelColor(i, strip.Color(255, 255, 0)); break;
}
}
strip.show();
delay(100);
}
This exercise helped us understand the two main building blocks of an Arduino program: setup() runs once at startup, loop() runs forever. Everything lives inside those two functions.
Programming the XIAO RP2040¶
Next we moved to real hardware — the Seeed Studio XIAO RP2040, a small but capable board with a built-in RGB LED.
First we installed Arduino IDE and added the RP2040 board library through the Board Manager.
The onboard LED is on pin 12, with a separate power enable pin on pin 11. You have to pull that pin HIGH or the LED doesn’t turn on at all — something worth knowing.
The program cycles through red, green, and blue with 500ms delays between each color. Nothing complicated, but it confirmed the board and toolchain were set up correctly.
#include <Adafruit_NeoPixel.h>
#define PIN_RGB 12
#define PIN_POWER 11
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN_RGB, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(PIN_POWER, OUTPUT);
digitalWrite(PIN_POWER, HIGH);
pixels.begin();
}
void loop() {
pixels.clear();
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0, 255, 0));
pixels.show();
delay(500);
pixels.setPixelColor(0, pixels.Color(0, 0, 255));
pixels.show();
delay(500);
}
STM32F3DISCOVERY Board¶
The third platform was the STM32F3DISCOVERY. This one has a steeper setup curve than Arduino, but the workflow is more representative of professional embedded development.
Generating code with STM32CubeMX¶
STM32CubeMX is a graphical tool that generates initialization code and HAL (Hardware Abstraction Layer) files based on your board configuration. You pick your board, set your peripherals, choose a project type (we used CMake), and it generates the skeleton project.
Setting up VS Code¶
We used VS Code as the editor and compiler. On Linux, you need a few packages first:
sudo apt update
sudo apt install -y gcc-arm-none-eabi openocd make cmake ninja-build
Then we installed the STM32CubeIDE extension pack in VS Code. It picks up the generated project structure automatically. The Cortex-Debug extension adds real-time debugging.
Write your code in main.c, hit run — that’s it.
Summary¶
Three boards, three different toolchains. TinkerCAD and Arduino are the easiest starting point. The XIAO RP2040 works almost identically in Arduino IDE. STM32 takes more setup but gives you more control and a workflow that’s closer to what’s used in industry.
Tools¶
- Arduino IDE
- Seeed Studio XIAO RP2040
- USB cable
- Computer
Individual Assignment¶
During the group work, we explored different microcontrollers and their capabilities. I chose the Seeed Studio XIAO RP2040 because of its compact size and compatibility with Arduino IDE.
I selected the XIAO RP2040 because it is small, easy to use, and suitable for future project integration.

- Downloaded and installed Arduino IDE.
- Opened the Seeed Studio website.
- Copied the board manager URL.

- Added the URL into Arduino IDE preferences.

- Installed the XIAO RP2040 board package.

- Connected the XIAO RP2040 to the computer.
- Selected the correct board from the menu.

- Selected the COM port.
Before making connections, I reviewed the RP2040 pinout diagram to better understand the pin functions and avoid incorrect wiring.

Programming¶
After studying the RP2040 pinout, I created a simple program to test input reading from pin D0.
The code initializes serial communication and sets pin D0 as an input.
The program continuously reads the digital state of the pin and prints “CLOSED” or “OPEN” in the Serial Monitor depending on the input signal.
- Serial.begin(9600) initializes serial communication
- pinMode(D0, INPUT) sets pin D0 as input
- digitalRead(D0) reads the pin state
- Serial.println outputs the result
Code¶
void setup() {
pinMode(D0, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(D0) == HIGH) {
Serial.println("CLOSED");
} else {
Serial.println("OPEN");
}
}
Code Screenshot¶

Serial Output¶
OPEN
CLOSED
OPEN

This test helped me understand how to read digital input signals and verify hardware connections.
Functions and Variables (Additional Learning)¶
During this week, I also explored basic programming concepts such as functions and variables in Arduino.
Example Code¶
#define pin1 17
int distSens = 17;
float var2 = 17.444;
String var3 = "hello Gyumri";
bool var4 = true;
const int var5 = 68;
void myFunc() {
digitalWrite(pin1, HIGH);
delay(500);
digitalWrite(pin1, LOW);
delay(500);
}
void setup() {
pinMode(pin1, OUTPUT);
Serial.begin(9600);
}
void loop() {
myFunc();
}
Code Example Image¶

Key Concepts¶
- Function → reusable block of code
- Variables → store data
- setup() → runs once
- loop() → runs continuously
Common Mistakes¶
#defint pin1 14 // incorrect
char var3 = "text"; // incorrect
bool var4 = tru; // incorrect
Correct version:
#define pin1 14
String var3 = "text";
bool var4 = true;