<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aadarsh Mandal</title>
    <description>The latest articles on DEV Community by Aadarsh Mandal (@codedbyaadarsh).</description>
    <link>https://dev.to/codedbyaadarsh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4169428%2F45b88c0a-7320-43c2-ab16-6eeef858809c.png</url>
      <title>DEV Community: Aadarsh Mandal</title>
      <link>https://dev.to/codedbyaadarsh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codedbyaadarsh"/>
    <language>en</language>
    <item>
      <title>My First Linux I2C Driver: BMP280 on Raspberry Pi 4, Part 1</title>
      <dc:creator>Aadarsh Mandal</dc:creator>
      <pubDate>Mon, 23 Nov 2026 17:44:37 +0000</pubDate>
      <link>https://dev.to/codedbyaadarsh/my-first-linux-i2c-driver-bmp280-on-raspberry-pi-4-part-1-5c0f</link>
      <guid>https://dev.to/codedbyaadarsh/my-first-linux-i2c-driver-bmp280-on-raspberry-pi-4-part-1-5c0f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;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. &lt;br&gt;
&lt;strong&gt;series&lt;/strong&gt; : &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Falkgs96spmr88d7ysw3q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Falkgs96spmr88d7ysw3q.png" alt="series parts overview" width="406" height="453"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What you need
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;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).&lt;/li&gt;
&lt;li&gt;BMP280 sensor module&lt;/li&gt;
&lt;li&gt;Female-to-female jumper wires &lt;/li&gt;
&lt;li&gt;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).&lt;/li&gt;
&lt;li&gt;A laptop running linux ( any linux distro will work).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Where i'm starting from
&lt;/h3&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;li&gt;Ensure the i2c tool and i2c support are there in the configuration.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# config.txt &lt;/span&gt;
&lt;span class="c"&gt;# Enable the primary hardware I2C controller (i2c-1 on pins 3 and 5)&lt;/span&gt;
&lt;span class="nv"&gt;dtparam&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;i2c_arm&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;on

&lt;span class="c"&gt;# Enable the primary UART on GPIO 14/15 (pins 8 and 10)&lt;/span&gt;
&lt;span class="nv"&gt;enable_uart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;/code&gt;&lt;/pre&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Wiring
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;BMP280 to Pi header&lt;/strong&gt; (physical pin numbers):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;BMP280&lt;/th&gt;
&lt;th&gt;Pi pin&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;VCC&lt;/td&gt;
&lt;td&gt;1 (3.3V)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GND&lt;/td&gt;
&lt;td&gt;6 (GND)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SDA&lt;/td&gt;
&lt;td&gt;3 (GPIO2)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SCL&lt;/td&gt;
&lt;td&gt;5 (GPIO3)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning&lt;/p&gt;
&lt;p&gt;
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 &lt;code&gt;0x76&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Optional USB-serial adapter (CP2102), for the boot console:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Adapter&lt;/th&gt;
&lt;th&gt;Pi pin&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GND&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RXD&lt;/td&gt;
&lt;td&gt;8 (Pi TX)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TXD&lt;/td&gt;
&lt;td&gt;10 (Pi RX)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning&lt;/p&gt;
&lt;p&gt;
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.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What is I2C?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;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.
&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is BMP280 sensor Module?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5t1ewye0n62hu57z7aqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5t1ewye0n62hu57z7aqx.png" alt="BMP280 Module Sensor" width="440" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bmp280 sensor module is a temperature and pressure sensor module manufactured by bosch. It supports the both SPI and I2C communication protcols. &lt;/li&gt;
&lt;li&gt;It's operating voltage is 1.8 to 3.6v, so we use the rpi 3.3v power supply pin to power it.&lt;/li&gt;
&lt;li&gt;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. &lt;/li&gt;
&lt;li&gt;As per the datasheet, the I2C address is &lt;code&gt;0x76&lt;/code&gt; when SDO is tied to GND and &lt;code&gt;0x77&lt;/code&gt; when tied to VCC. 
### Verifying the connection on board&lt;/li&gt;
&lt;li&gt;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.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 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 -- -- -- -- -- -- -- -- -- 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;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 &lt;code&gt;UU&lt;/code&gt;, but here we sees address which is &lt;code&gt;0x76&lt;/code&gt; means its free).&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What's next?
&lt;/h3&gt;

&lt;p&gt;In Part 2, we will start writing the skeleton of our Linux kernel module and register our I2C driver!&lt;/p&gt;
&lt;h3&gt;
  
  
  Important links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/codedby-aadarsh" rel="noopener noreferrer"&gt;
        codedby-aadarsh
      &lt;/a&gt; / &lt;a href="https://github.com/codedby-aadarsh/custom-linux-distribution-for-rpi" rel="noopener noreferrer"&gt;
        custom-linux-distribution-for-rpi
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A minimal linux distribution for raspberry pi 4b board created using buildroot
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;A minimal linux distro for raspberry pi 4b&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;A learning project: a minimal Buildroot Linux image for the Raspberry Pi 4B.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Tested with&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;&lt;div class="table-wrapper-paragraph"&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;table&gt;

&lt;thead&gt;

&lt;tr&gt;

&lt;th&gt;Item&lt;/th&gt;

&lt;th&gt;Version&lt;/th&gt;

&lt;/tr&gt;

&lt;/thead&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;td&gt;Board&lt;/td&gt;

&lt;td&gt;Raspberry Pi 4B (4 GB)&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Kernel&lt;/td&gt;

&lt;td&gt;6.12.x (Raspberry Pi kernel, built by Buildroot)&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Buildroot&lt;/td&gt;

&lt;td&gt;2026.02.1&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;Host&lt;/td&gt;

&lt;td&gt;Ubuntu / any Linux&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Repo layout&lt;/h2&gt;
&lt;/div&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;.
├── 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
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;1. Host prerequisites&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;Buildroot needs the usual build tools. On Debian/Ubuntu:&lt;/p&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;sudo apt install build-essential git wget cpio unzip rsync bc file libncurses-dev \
    python3 libssl-dev&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;See the Buildroot manual for the full list for your Buildroot version.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;2. Get the sources&lt;/h2&gt;

&lt;/div&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;git clone &lt;span class="pl-k"&gt;&amp;lt;&lt;/span&gt;this-repo-url&lt;span class="pl-k"&gt;&amp;gt;&lt;/span&gt; my_rasberrypi_project
git clone https://gitlab.com/buildroot.org/buildroot.git&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you want…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/codedby-aadarsh/custom-linux-distribution-for-rpi" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>raspberrypi</category>
      <category>iot</category>
      <category>c</category>
    </item>
  </channel>
</rss>
