Feb 11, 2026

Week 4

AI prompt: “This week 4 need to learn embedded programming. We explore what is microcontrollers, Arduino and Stm32, c, c++ and Arduino ide. Uart pio. Can you generate image when grandmothers of this image started this week?”

Embedded Programming

This week, we thoroughly studied how microcontrollers work, became familiar with the tools required to program them, and learned the theoretical differences between them. I can confidently say that programming microcontrollers is one of the most interesting directions in programming because it combines both coding and creativity.

Group assignment

For the group assignment, we used a I2C LCD display, Arduino UNO, and jumper wires. The goal was to install the Arduino IDE, understand the workflow, and print text on the LCD screen.

To begin, I decided to follow the official Arduino documentation. While reading the documentation, I quickly realized that it was necessary to install the LiquidCrystal library in the Arduino IDE. To install it, I navigated to Sketch → Include Library → Manage Libraries, searched for LiquidCrystal, and installed it.


After preparing the programming environment, the next step was to connect the LCD to the Arduino UNO and then connect the Arduino to the computer. When connecting the Arduino to the computer, several additional configurations were required to select the correct port and establish communication.


Next, I identified the pins on the LCD module and connected them to the corresponding pins on the Arduino.


After completing the hardware setup, I moved to the Arduino IDE to write the logic for printing text on the LCD screen.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 or 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello Onik jan");
}

void loop() {
  // Nothing here
}

After adding the code, saving it, and uploading it to the Arduino, the text successfully appeared on the LCD screen.


After completing all these steps, I realized that I could have simply used the ready-made example codes available for printing text on the LCD -_-



Individual assignment

Arduino Uno, C++


At first, I began my experiments with a simpler setup, meaning I started programming on the Arduino Uno. To make the assignment slightly more challenging, I decided to display the classic “Hello World” message along with a timer. However, this time I used an LCD screen that did not include a built-in potentiometer, which meant I had to assemble the full circuit on a breadboard. The required components are shown in the image.


I assembled everything based on the Arduino documentation. I used the reference images shown below, which were also downloaded from the Arduino documentation.

After creating a new file and adding the code, I obtained the following result.

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink();
  delay(3000);
}


To further increase the complexity, I programmed the LCD to display a timer and added a joystick to use its button functionality. I specifically chose a joystick instead of a regular button because I plan to integrate a joystick into my system in the future.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 

const int JOYSTICK_BUTTON = 8; // Pin for the SW pin on joystick
unsigned long startTime;
unsigned long elapsedTime;
byte seconds, minutes, hours;

void setup() {
  pinMode(JOYSTICK_BUTTON, INPUT_PULLUP);
  lcd.begin(16, 2);
  lcd.print("Timer: ");
  startTime = millis();
}

void loop() {
  // Check if joystick button is pressed (LOW means pressed)
  if (digitalRead(JOYSTICK_BUTTON) == LOW) {
    startTime = millis(); // Reset the start marker to "now"
  }

  elapsedTime = (millis() - startTime) / 1000;

  seconds = elapsedTime % 60;
  minutes = (elapsedTime / 60) % 60;
  hours = (elapsedTime / 3600) % 100;

  lcd.setCursor(0, 1);
  if (hours < 10) lcd.print('0');
  lcd.print(hours);
  lcd.print(':');
  if (minutes < 10) lcd.print('0');
  lcd.print(minutes);
  lcd.print(':');
  if (seconds < 10) lcd.print('0');
  lcd.print(seconds);
  lcd.print("   "); // Extra spaces to clear old digits
}

Here is the assembled circuit and a video demonstrating the result.



Thonny, Micropython



Now I continued my experiments by programming another microcontroller and using a different programming language. I chose MicroPython, and I programmed the Seeed Studio XIAO RP2040 microcontroller.

The Seeed Studio XIAO RP2040 is a compact, thumb-sized development board featuring the powerful Raspberry Pi RP2040 chip, designed for small-scale and wearable projects. It supports multiple programming platforms including Arduino, MicroPython, and CircuitPython.

The required components were:

  • Seeed Studio XIAO RP2040
  • I2C LCD
  • Wires
  • Breadboard
  • USB Cable

I assembled the circuit by reading the documentation from the Seeed Studio Wiki Platform and using the reference image shown below.

To program using MicroPython, I installed Thonny. Since my computer and operating system had changed (not by my choice 😄), I installed it using the following method.

After completing the installation, I configured the settings by selecting Raspberry Pi Pico as the Interpreter and choosing the correct port. This step specifies the physical serial connection between the computer and the development board and selects the appropriate MicroPython port for the device.

Next, I created a new file by navigating to File → New and wrote a simple program to print "Hello, XIAO!" on the LCD screen.

After pressing Save and Run, I encountered the following error.

from machine import I2C,Pin
from pico_i2c_lcd import I2cLcd
import time

# Configure I2C
i2c = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000)

# Scan and check if any devices are found
devices = i2c.scan()

if not devices:
    print("No I2C device found! Check your wiring and power.")
else:
    LCD_ADDR = devices[0]
    print(f"I2C device found at address: {hex(LCD_ADDR)}")
    # Initialize 16x2 LCD
    lcd = I2cLcd(i2c, LCD_ADDR, 2, 16)
    lcd.putstr("Hello, XIAO!")

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ImportError: no module named 'pico_i2c_lcd'
>>> 

After researching and analyzing the issue, I realized that I needed to install two additional libraries. To interface an I2C LCD with MicroPython in Thonny, two library files are required:

  • lcd_api.py – contains general LCD command functions
  • pico_i2c_lcd.py – handles Pico-specific I2C communication

I created two new files and placed the corresponding code inside them (which I downloaded from the provided source).


this is code for timer

from machine import I2C, Pin
from pico_i2c_lcd import I2cLcd
import time

# Configure I2C
i2c = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000)
button = Pin(26, Pin.IN, Pin.PULL_UP)

devices = i2c.scan()
if not devices:
    print("No I2C device found!")
else:
    lcd = I2cLcd(i2c, devices[0], 2, 16)
    
    while True:
        lcd.clear()
        lcd.putstr("Timer Started!")
        start_time = time.ticks_ms()
        
        while True:
            # 1. Calculate total elapsed seconds
            elapsed = time.ticks_diff(time.ticks_ms(), start_time) // 1000
            
            # 2. Break down into H:M:S
            hours = (elapsed // 3600)
            minutes = (elapsed % 3600) // 60
            seconds = elapsed % 60
            
            # 3. Display formatted time (00:00:00)
            lcd.move_to(0, 1)
            # :02d ensures 2 digits (e.g., 05 instead of 5)
            lcd.putstr(f"Time: {hours:02d}:{minutes:02d}:{seconds:02d}")
            
            # Check for Reset Button
            if button.value() == 0:
                time.sleep(0.2) # Simple debounce
                break 
                
            time.sleep(0.1)


this is video of timer working



conclusion


Files for download


Arduino Files

Thonny Files



AI prompt: “And generate an image when finished this week.”