Skip to content

DevBlocky/hptdisplay

Repository files navigation

Humidity, Pressure, and Temperature Display

A scratch RTOS-driven embedded application that measures humidity (RelH), pressure (hPa), and temperature (C) using a Raspberry Pi 3B+, BME280, and SSD1306 over I2C.

Using the BCM2835 (RPI 3B+ SoC) peripheral technical manual, SSD1306 datasheet, and BME280 datasheet I wrote the entire kernel from scratch. This application runs bare-metal on my Raspberry Pi 3B+ after the GPU bootloader firmware loads kernel8.img into memory and executes it. I also used other resources to learn and debug the Aarch64 architecture like QEMU, Anthropic's Claude, bztsrc's raspi3-tutorial, and the ARM architecture documentation.

Raspberry Pi 3B+ Setup

Resources: (for other hobbyists)

From Repo to Running

Before starting, there are a few pieces of hardware we need:

  • Raspberry Pi 3B+
  • BME280 sensor + breakout board
  • SSD1306 128x64 display + breakout board
  • UART to USB dongle (optional, for serial debugging)
  • Breadboard
  • Jumper wires

All of these can easily be found on amazon for fairly cheap. The most expensive item is the Raspberry Pi, at $54 when I looked.

Building kernel8.img

First, you need to download the Aarch64 toolchain for your platform. I used WSL (linux), so I downloaded arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf.tar.xz. Make sure you download the aarch64-none-elf version so that it generates ELF files, which are transformed into binary images.

Extract the download's folder, and move it into this repo's root folder as toolchain. Alternatively, it can be placed anywhere and you can modify the TOOLPREFIX environment variable (see Makefile).

Once your toolchain is established, you can run make to build kernel8.img.

Creating bootfs

  • Using Raspberry Pi Imager

    1. Format a micro-SD card using Raspberry Pi Imager. I would recommend choosing the "Raspberry Pi OS Lite (64-bit)" option.
    2. You should see a new drive called bootfs. Delete all files in here except: bootcode.bin, fixup.dat, and start.elf
    3. Copy config.txt and kernel8.img from here into bootfs
  • From Scratch

    1. Format a micro-SD card as FAT32
    2. Go to https://github.com/raspberrypi/firmware/tree/master/boot and copy bootcode.bin, fixup.dat, and start.elf into the formatted SD card
    3. Copy config.txt and kernel8.img from here into the SD card

Your bootfs should look like this:

Raspberry Pi bootfs

Connecting the wires

Plug your BME280 and SSD1306 into the breadboard. Then, connect the GPIO pins to the breadboard corresponding input pins for each module:

  • Ground to the breadboard ground (then to each module)
  • 3.3V to the breadboard positive (then to each module)
  • GPIO2 SDA to the BME280 and SSD1306 SDA inputs
  • GPIO3 SCL to the BME280 and SSD1306 SCL inputs

My BME280 also came with two extra pins: CSB and SD0.

  • CSB is used for SPI, which I am not using and the datasheet said to connect to 3.3V in I2C operation
  • SD0 changes the address of the I2C module if positive, so connect to ground for this

For UART, connect:

  • Another GPIO ground to UART dongle ground
  • GPIO UART TX to UART dongle RX
  • GPIO UART RX to UART dongle TX
  • NOTE: If the UART dongle comes with power pins (mine did), DO NOT connect them to the Raspberry Pi

Here's a good visual reference for Raspberry Pi 3B+ pins:

Raspberry Pi 3B+ pinout

Starting the application

Now that everything is connected, you can plug in your micro-SD card and power cable into the Raspberry Pi and start it. It should immediately start showing an output on the SSD1306 if you did everything right.

Examples

Humidity (in relative humidity)

SSD1306 displaying humidity

Pressure (in hPa/mbar)

SSD1306 displaying pressure

Temperature (in degrees C)

SSD1306 displaying temperature

About

Humidity, Pressure, and Temperature display on a Raspberry Pi 3B+ using a SSD1306 and BME280

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors