VSCode Icon

File

Edit

View

Go

Run

Terminal

Help

Pratik Poudel - Visual Studio Code

All projects

PROJECT CASE STUDY · EMBEDDED SYSTEMS

RaspberryPi-PICO

A MicroPython project using a Raspberry Pi Pico to read temperature and humidity from a DHT22 sensor and display the measurements on a 16×2 I²C LCD.

At a glance

Type
Microcontroller / sensor project
Board
Raspberry Pi Pico · RP2040
Language
MicroPython
Sensor
DHT22 temperature and humidity
Display
16×2 I²C LCD

The challenge

This project connects a physical sensor to a microcontroller and makes its readings understandable without needing a computer display. It combines sensor communication, GPIO pin configuration, I²C display output, and a repeating measurement loop.

What the code does

Reads the DHT22

Uses a DHT22 driver to obtain temperature and relative-humidity readings.

Initializes the LCD

Sets up I²C bus 0 with GPIO 0 for SDA and GPIO 1 for SCL, then detects the LCD address.

Connects the sensor

Configures the DHT22 data line on GPIO 15 of the Raspberry Pi Pico.

Displays live values

Refreshes the LCD with temperature and humidity values and also prints readings to the serial console.

Hardware and data flow

The main program initializes the I²C LCD, reads the DHT22 sensor, writes the two measurements to separate LCD rows, prints the values, and repeats after a short delay.

DHT22 · GPIO 15→Raspberry Pi Pico→16×2 LCD · I²C 0
Raspberry Pi PicoRP2040MicroPythonDHT22I²C16×2 LCDGPIO

Implementation note

The repository includes a DHT22 driver file that retains its upstream MIT copyright notice. The main program integrates that driver with the Pico pins and LCD output.

Measurement cycle

  1. Initialize the I²C bus and LCD, then configure the DHT22 data pin.
  2. Request a temperature and relative-humidity sample from the sensor driver.
  3. Format the readings for the two-row character display and print them to serial output.
  4. Wait briefly and repeat, keeping the display refreshed with the latest sample.

Hardware integration notes

The program uses GPIO 15 for the DHT22 data signal and I²C bus 0 on GPIO 0 (SDA) and GPIO 1 (SCL) for the LCD. The LCD address is discovered during initialization, which avoids assuming a single address across compatible modules. The sensor driver is kept as a separate file rather than mixing its low-level protocol with display logic.

Scope and possible extensions

This is a compact local monitoring demonstration. It does not currently provide network telemetry or long-term data logging. Natural next steps include sensor-error handling, configurable sampling intervals, min/max tracking, and exporting readings.

What this project demonstrates

  • Using MicroPython to program a Raspberry Pi Pico.
  • Reading a digital environmental sensor.
  • Configuring GPIO and an I²C peripheral.
  • Presenting hardware readings on a character LCD and serial output.