Skip to content

Week 10 | Output Devices

Overview

This week in the FabAcademy course focuses on output devices such as displays, servo motors, video systems, and speakers. Output devices allow a system to communicate information or actions to the external environment.

Two key aspects when working with output devices are understanding their power consumption and learning how to communicate with them. Measuring power consumption helps ensure that the devices operate safely within the limits of the system, while proper communication enables the microcontroller or control system to send commands and data correctly.

The goal of this week is to learn how to measure the power consumption of OLED in group work and to interface with an LCD display to send and display information in individual assignment.

Group Assignment

In the group assignment, we tried to measured power consumption of a OLED using four power meter.

Individual assignment

For this week I worked with two different type of output devices:

  1. 2004 I²C LCD display

Both devices were connected to my microcontroller board which I made week08 and programmed to demonstrate basic output functionality.


2004 I²C LCD Display

The 2004 LCD is a 20×4 character display that communicates using the I2C protocol. This reduces the number of required pins and makes it easy to connect it to a microcontroller. It is useful for showing sensor values.

Wiring

For wiring, i used its datasheet and XIAO RP2040. A few images I used here, are from these datasheets.

  • VCC → 5V
  • GND → GND
  • SDA → D4 (in RP2040)
  • SCL → D5 (in RP2040)

This is my setup, after wiring that is ready for test and getting errors that always happened during programming.

Two more images from close-up view, that pins clearly can be seen.

A potentiometer on the back that is for adjusting the LCD contrast.

When I turned fully the potentiometer clockwise, the brightness was at its maximum (left image) and when I turned fully anticlockwise, the LCD becomes completely light blue (right image).

Programming with Micropython

I used Micropython to programme it. As I mentioned already, LCD uses I2C protocol to communicate. I used the below simple code:

from machine import Pin, SoftI2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
import time

# define data and clock pins (GP6 SDA, GP7 SCL)
i2c = SoftI2C(scl=Pin(7), sda=Pin(6), freq=50000)

I2C_ADDR = 0x27     # The address in datasheet

# Create LCD object: 4 rows, 20 columns
lcd = I2cLcd(i2c, I2C_ADDR, 4, 20)

# Initialize and turn on backlight
lcd.clear()
lcd.backlight_on()      
# Display text on different lines
#lcd.move_to(0, 0)
#lcd.putstr("FabAcademy2026!")

#lcd.move_to(0, 1)
#lcd.putstr("Oulu SuperFabLab!")

#lcd.move_to(0, 2)
#lcd.putstr("Mohammadreza Omidali")

#lcd.move_to(0, 3)
#lcd.putstr("23-March-2026")

# Display text on different lines
lcd.move_to(0, 0)
lcd.putstr("Week10!")

lcd.move_to(0, 1)
lcd.putstr("IndividualAssignment")

lcd.move_to(0, 2)
lcd.putstr("Output Device")

lcd.move_to(0, 3)
lcd.putstr("23-March-2026")

Before ran the code, from Manage Packages under Tools tab:

I installed both lcd_api and lcd-i2c libraries:

Then, I ran the code, but I got the below errors:

As it shown in above image, the errors were from libraries. So I decided to installed them again. I downloaded lcd_api and lcd_api, and opened new file in Thonny and save them with the same name in RP2040:

Then I tried to run the code again and it was successful.

Result of output

I was able to successfully displayed text on the LCD, confirming that the I²C communication and power supply were functioning correctly.

Programming wit Arduino

First I installed LiquidCrystal_I2C library based on the datasheet:

The Arduino code:

  • Initializes the LCD
  • Prints a welcome message
  • Print today date
  • Updates the screen every second
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 4, 20);

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("FabAcademy 2026");
  lcd.setCursor(0, 1);
  lcd.print("Output Devices");
  lcd.setCursor(0, 2);
  lcd.print("date: ");
  lcd.print(__DATE__);
  lcd.setCursor(15, 3);
  lcd.print("Omid");
}

void loop() {
  lcd.setCursor(0, 3);
  lcd.print("Timer: ");
  lcd.print(millis() / 1000);
}

Result of the Arduino

Reflection

This week helped me understand how different output devices communicate with a microcontroller and how to control them through programming. By working with the I2C LCD display, I learned how the I2C protocol simplifies wiring by reducing the number of required pins while still allowing reliable communication between the microcontroller and the display. This also helped me better understand the importance of checking device addresses and installing the correct libraries when working with external modules.

During the process, I faced issues with missing or incompatible libraries in MicroPython. Troubleshooting these errors required manually downloading the necessary files and saving them directly on the microcontroller. This experience improved my debugging skills and showed me how software dependencies can affect hardware communication.

Programming the LCD in both MicroPython and Arduino environments also helped me compare the workflow and libraries used in each platform. It showed that while the overall logic is similar, the implementation details can differ depending on the development environment.

I used AI for checking the grammar!