Introduction

This article is going to be a series where I'll write a BMP280 driver from scratch. I have no prior experience of writing a I2C device driver. I've written a char device driver before , but only on QEMU,so this is my first time working with real hardware and I2C subsystem. I'll be figuring things out as i go. The end goal of this series is a working BMP280 device driver that lets us read temperature and pressure from the user space. This is a learning project, not a production-quality code.
series :
series parts overview

What you need

  1. Raspberry Pi 4B board(any RAM variant works or any other linux capable SoC board with I2C support, exact pin numbers or wiring will differ).
  2. BMP280 sensor module
  3. Female-to-female jumper wires
  4. USB-to-TTL serial adapter like CP2102( optional , but good to have, in case the ssh doesn't work or something goes wrong during boot).
  5. A laptop running linux ( any linux distro will work).

Where i'm starting from

Before starting this, i validated my board with a minimal headless Linux distribution created using buildroot. You can also use the Raspberry Pi OS Lite. But if you want to follow along using buildroot, here is what you will need to do:

  1. Enable the ssh , select the openssh or dropbear package as you like. If you are planning to use ssh over wifi , then you also have to enable the wifi on board.
  2. Ensure the i2c tool and i2c support are there in the configuration.
  3. If you are using the uart, then you may also need to enable the serial console. Add the following lines in the config.txt on your boot partition.

    # config.txt  # Enable the primary hardware I2C controller (i2c-1 on pins 3 and 5) dtparam=i2c_arm=on # Enable the primary UART on GPIO 14/15 (pins 8 and 10) enable_uart=1 
  • My config is in the repo linked at the end. Also, read the readme file in the repo for the instruction as you may need to do a little bit of manual configuration.

Wiring

BMP280 to Pi header (physical pin numbers):

BMP280 Pi pin
VCC 1 (3.3V)
GND 6 (GND)
SDA 3 (GPIO2)
SCL 5 (GPIO3)

Warning

On a standard BMP280 sensor module, CSB is pulled up(kept HIGH for I2C mode), while SDO is typically pulled down to set default I2C address 0x76.

Optional USB-serial adapter (CP2102), for the boot console:

Adapter Pi pin
GND 6
RXD 8 (Pi TX)
TXD 10 (Pi RX)

Warning

watch out here, you connect the RX to TX or TX to RX, never TX to TX or RX to RX, the reason is simple receiver pin on one board need to be connected to the transmitter pin of the other to listen. Don't connect uart module 5V or VCC pin to the Raspberry Pi power supply pin as it can damaged your board. Other than these three GND ,TX and RX pins, leave other ones disconnected.

What is I2C?

  • Inter integrated circuit communication protocol also known as two wire interface. This communication protocol is a half duplex, synchronous, multi master slave protocol. Every slave has an address, master talk to slave by addressing on bus. It uses two wires: SDA(serial data line), used for data transfer and SCL(serial clock line) , generated by master to synchronize the data transfer.
  • Unlike USB devices, I2C are non discoverable. A USB device announce itself to the OS the moment you plug it in, whereas an I2C chip will sit silently until the master address it.
  • Since Linux kernel can't auto detect the presence I2c devices. On x86 system, it handled by ACPI table. In the embedded systems ARM boards, we use the device tree to tell the Linux what sort of the devices or hardware the soc is attached to, but for testing our driver we can skip the device tree part first , and manually instantiate device from user space.

What is BMP280 sensor Module?

BMP280 Module Sensor

  • Bmp280 sensor module is a temperature and pressure sensor module manufactured by bosch. It supports the both SPI and I2C communication protcols.
  • It's operating voltage is 1.8 to 3.6v, so we use the rpi 3.3v power supply pin to power it.
  • To choose the communication mode you can connect CSB pin to VCC or left floating is for I2C mode(if your module has a pullup resistor on board), and connecting with the ground pin makes it SPI mode.
  • As per the datasheet, the I2C address is 0x76 when SDO is tied to GND and 0x77 when tied to VCC. ### Verifying the connection on board
  • Before writing single line of kernel code, we should verify that the Raspberry Pi board is actually sees the BMP280 on I2C bus. Boot up the board, login via ssh or your serial console,run the following command.
# i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- 76 -- -- -- -- -- -- -- -- -- 
  • If you see the 76 in the output as above. It confirms two things: our wiring is good, and no other driver claiming the device(In case of address in use, in the very same place you will be seeing UU, but here we sees address which is 0x76 means its free).

What's next?

In Part 2, we will start writing the skeleton of our Linux kernel module and register our I2C driver!

Important links

  • GitHub logo codedby-aadarsh / custom-linux-distribution-for-rpi

    A minimal linux distribution for raspberry pi 4b board created using buildroot

    A minimal linux distro for raspberry pi 4b

    A learning project: a minimal Buildroot Linux image for the Raspberry Pi 4B.

    Tested with


























    Item Version
    Board Raspberry Pi 4B (4 GB)
    Kernel 6.12.x (Raspberry Pi kernel, built by Buildroot)
    Buildroot 2026.02.1
    Host Ubuntu / any Linux

    Repo layout

    . ├── config/ │ ├── rpi4b_defconfig # Buildroot config │ └── linux.config # kernel config ├── rasberrypi_overlay/ # rootfs overlay (files copied into the image) │ └── etc/ │ ├── network/interfaces │ └── ssh/sshd_config ├── examples/ │ └── wpa_supplicant.conf.example # copy and edit (see step 4) └── README.md 

    1. Host prerequisites

    Buildroot needs the usual build tools. On Debian/Ubuntu:

    sudo apt install build-essential git wget cpio unzip rsync bc file libncurses-dev \ python3 libssl-dev

    See the Buildroot manual for the full list for your Buildroot version.

    2. Get the sources

    git clone <this-repo-url> my_rasberrypi_project git clone https://gitlab.com/buildroot.org/buildroot.git

    If you want…