DigiLab : Pulling Data from thin air (and a BMP280 module)

One of the amazing features of Lab401's DigiLab accessory for FlipperZero® is its I2C Probe. If you've ever played around with electronics, microcontrollers or embedded computers like the ESP-32, you'll have no doubt come across I2C.

You can follow along with this tutorial (and the introductory LM75A tutorial) with the DigiLab Module Kit - it has all the modules (with presoldered headers) and cables you need.

It's a communication protocol that works over just two wires that allows for multiple (in theory thousands..) of devices and sensors to be attached to the same lines, and yet still be able to handle direct communication.

Although invented in the 1980s, it's an incredibly important and popular technology. It's no exaggeration that there are literally thousands of types of I2C sensors, and millions of devices that use them!

Modules, modules, modules.

But if you've got an I2C sensor sitting on your desk, how do you interact with it?

Today, you'd typically reach for an Ardunio or Raspberry Pi, and hope someone has written a library for it. Maybe you'll fight with breadboards and jumpers, and maybe you'll wish for a way to talk to the module directly. Or maybe it's an unmarked AliExpress Magical Mystery Chip, and you've got no idea what it does. Or worse, maybe you've need to do something special that the libraries don't cover - and there's no simple way to do it.

Enter the DigiLab , and its I2C Probe tool. You can easily detect devices on the I2C bus, and use the in-built predictive engine to guess what they are. And then - you can get your hands dirty and poke around directly inside the module itself.

Let's get started

In this tutorial, we're going to be investigating the BMP280, an air-pressure sensor from Bosch. These sensors are fairly ubiquitous - but don't be deceived, they are incredibly powerful sensors that can be configured in literally thousands of ways to meet the requirements of millions of devices. At Lab401, we believe that understanding is more important than just doing. The deeper your understanding, the more you'll be able to do.

The BMP280 module, on a breakout board.

At the end of the tutorial, you'll have acquired the following skills:

  • How to communicate with unknown modules via first-principles
  • How to leverage data-sheets to use unknown modules
  • How to use the DigiLab to identify unknown I2C modules
  • How to directly modify the memory / registers of I2C modules
  • Leveraging AI to build useful tools

In this tutorial, we'll cover the following steps:

  1. Connecting the BMP280 to the DigiLab
  2. Detecting and identifying the BMP280
  3. Obtaining and using the data-sheet
  4. Configuring the BMP280
  5. Pulling temperature data
  6. Pulling pressure data
  7. Pulling calibration data
  8. Building a tool to interpret retrieved data

In order to play along at home, you'll only need three things:

Connecting the BMP280 to the DigiLab

First, we'll connect the BMP280 Breakout module to the DigiLab. We'll connect:

  • The DigiLab 3.3V pin to the BMP280's VCC/3.3v pin
  • The DigiLab GND pin to the BMP280's GND pin
  • The DigiLab SCL pin to the BMP280's SCL pin
  • The DigiLab SDA pin to the BMP280's SDA pin

That's all the wiring that we need to do! Important - if you're using a different board, please ensure that you follow what's printed on the PCB to avoid frying your module!

Detecting and identifying the BMP280

Now, connect your DigiLab to your FlipperZero, and head into Apps › GPIO › Lab401/DigiLab. If you haven't already installed the App, you can get it from the Flipper App Store: https://lab.flipper.net/apps/401_digilab.

If it's the first time you've used the DigiLab app, you'll be asked to Calibrate your DigiLab. Follow the instructions on screen - touch the red probe to the +5V pad, and click OK.

In the DigiLab App, head to I2C Probe. The device will rapidly scan for devices, and present you with a list of results. You can navigate the list with the left and right arrows.
If everything was connected properly, you should see two found devices. The DigiLab has an I2C memory chip on it, so there'll always be one device found.

Navigate the list until you see the device 0x76. This number is the address of the device, and it's "somewhat" unique. Click on Info Button.

The DigiLab uses its predictive engine to try to guess the type of module it's connected to. There may be multiple types of module - but it helps you narrow down what you're dealing with. If you navigate the list, you'll see that the BMP280 is found, and that it's a "Temperature and Pressure Sensor" from Bosch. Cool!

At this point, you could click the R/W button to read and write values from the module's memory slots ("registers") - but where would you begin? This is where data-sheets come in.

Obtaining and using the datasheet

A quick web-search brings up a copy of the datasheet for the BMP280 sensor. Perusing the document shows that the sensor is actually quite complex - there's a great deal of functionality tucked into a tiny package. It has multiple filters to deal with spikes, can be polled slowly but accurately, or (very) quickly, has multiple different power modes and resolutions.

More specifically, we're going to have to configure the sensor (ie, write our preferred settings to it) before we can pull data from it.

For our purposes, the document gets really interesting around page 25, when it discusses the different registers. A register is another way to refer to a chunk of memory. According to the documentation, each register in the BMP280 is 8-bits, or 1-byte of data. Each Register has an address (typically referred to in hexadecimal).

Good to see Bosch is looking out for customer using CGA graphics.

In Table 18, we can see the memory layout. There are four sections that seem to be interesting:

  1. : The register containing the device configuration data
  2. : The register containing the measurement configuration
  3. : The registers holding the calibration values
  4. : The registers holding the pressure values
  5. : The registers holding the temperature values

With the information from this table, we can now complete steps 3 - 6:

  • Configuring the BMP280
  • Pulling temperature data
  • Pulling pressure data
  • Pulling calibration data

Configuring the BMP280

Let's start by configuring the BMP280. We don't have any highly technical requirements (ie, we don't need ultra-low-power mode, or ultra-quick polling). We can check on page 26 for details on how this configuration value is built up. A run-of-the-mill configuration value is composed as follows:

0xF5 - Device Configuration

  • Bit 7,6,5 -> (1000ms standby time)
  • Bit 4,3,2 -> (filter coefficient = off)
  • Bit 1 ->
  • Bit 0 -> (disables 3-wire SPI)
  • Final Value: in binary, or in hex.

0xF4 - Measurement Configuration

  • Bit 7,6,5 -> (Temperature oversampling x1)
  • Bit 4,3,2 -> (Pressure oversampling x1)
  • Bit 1,0 -> (Normal mode - continuous measurements)
  • Final Value: in binary, or in hex.

OK - now we know that if we write those values into their corresponding registers, the module will start measuring data, and we'll be able to read it back! Let's head back to the DigiLab to write the values!

In the DigiLab App, go to I2C Probe, and select the device with the address of 0x76. This time, click on the R/W Button - and you'll be taken to a screen where you can enter the register you want to modify.

Enter the register F5 (you can type it in, or use the arrow keys to increase the address) and click OK. Now we're prompted how much data we should read from the register. From the document, we know that it's 1-byte, so we enter 1 and click OK.

We're now inside the DigiLab's built in hex-editor, and peering directly into the memory of the BMP280. Using the arrow keys, set the value of the register to and click OK. You'll get a confirmation that the chip was programmed.

Now, do the same for the 0xF4 register, setting its value to and click OK. Again, you'll get a confirmation that the chip was programmed. Congratulations! The BMP280 is now configured and measuring data according to your configuration values. Next step - let's read out the values!

Pulling the temperature data

You might have guessed it - to pull out the temperature data, we need to check out the values in the registers . Go through each register, and note the data down somewhere.

Pulling the pressure data

Repeat the process for the pressure data, in registers . Again, go through each register, and note the data down somewhere.

Pulling the calibration data

The BMP280 self-calibrates using a variety of different data-points. In order to correctly translate the pressure and temperature values, we also need to note the calibration data. So, repeat the process a final time, for registers .

All in all, you should have a 3 bytes of temperature data, 3 bytes of pressure data, and 26-ytes of calibration values - something like:

Temperature Data
0xFA: 0x88 0xFB: 0x27 0xFC: 0x00
Pressure Data 0xF7: 0x54 0xF8: 0x8C 0xF9: 0x00 Calibration Data 0x88: 37 0x89: 70 0x8A: d0 0x8B: 68 0x8C: 32 0x8D: 00 0x8E: 1C 0x8F: 90 0x90: 25 0x91: D6 0x92: D0 0x93: 0B 0x94: 04 0x95: 1B 0x96: 40 0x97: 00 0x98: F9 0x99: FF 0x9A: B4 0x9B: 2D 0x9C: E8 0x9D: D1 0x9E: 88 0x9F: 13 0xA0: 00 0xA1: 4B

Building a tool to interpret retrieved data

We're ready to transform the data into something human readable. According to the spec-sheet (on page 21), the data is stored in a format called "16-bit two's complement". Instead of spending hours fighting to build a tool, we're leverage AI to build us out an interpreter. We used the agent / cli tool Aider with Claude Opus, but any model or means would work just fine.

Make a javascript calculator tool that takes temperature values from 0xFA-0xFC and pressure values from 0xF7-0xF9, and the calibration values from 0x88-0xA1 - from a BMP280 module, and provides a temperature output (in °C) and a pressure output in hectoPascals.

Visit the calculator online here

We can feed our data into the resulting tool, and it will output the correct temperature and pressure values from the sensor.

We can even extend the tool to estimate altitude. Calculating altitude is fairly simple:


The only variable we're missing is "sea_level_pressure". We can either use a "global average", 1013.25hPa, but the results will have a large margin of error. Alternatively, we can retreive the sea_level_pressure from a nearby weather-station!

Modify the Calculator form as follows:
1) When Calculate Temperature and Pressure has been clicked, and results have been calculated, add a button under the "Debug Information" frame: "Estimate Altitude (Requires Localisation)".

Under this button, add in italics: "Localisation data is used to send an anonymous request to the Open-Meteo API, to retrieve the QNH/Sea-level air pressure value nearest to you. This allows us to estimate your current altitude."

When the user clicks this button, request their localisation data via the browser. If they decline, show an error frame that says: "Sorry, we cannot estimate the altitude without localisation data."

If we have the user's localisation data, send a request to Open-Meteo to retrieve the QNH value closest to their location.

If there's an error, show it in a frame If we get successful information, use all the data to estimate the user's current altitude.

Visit the calculator online here

Now, the tool can even estimate elevation! In our opinion, the ability to rapidly accomplish side-quests is a perfect tool for AI. Traditionally, this type of tool would have taken at least an hour to finish - removing focus from our primary goals.

Summing Up

We've seen the Lab401 DigiLab's I2C Probe function is incredible useful. It's powerful, versatile, but simple to use. It abstracts all the hard parts of communication, and uses its "Prediction Engine" to identify different modules, and even lets you read and write values directly to the module.

Exploring I2C modules has traditionally been pretty clunky, or requires more expensive tools, writing code and is generally not an easy experience. The DigiLab makes I2C exploration not only simple, but accessible to anyone, so your curiosity isn't blocked by frustrations.

Homework task

We mentioned that the DigiLab has a on-board I2C memory chip! With everything you've learned, your homework task is to use the DigiLab to detect and identify the memory chip, and then write some values to it. You can check if it's worked - by disconnecting the DigiLab and reconnecting it - the data you've written will still be saved in memory. If you ever need to secretly store some data that you don't want your Flipper to know about, now you've got a hiding spot!

Resources

The two tools for interpreting the BMP280 sensor data are available on GitHub for experimentation and adaptation : https://github.com/lab-401/digilab-tutorial-bmp280

Related articles

Go to full site