Skip to content

Scroll Indicator

I2C Sensor Seduction: DigiLab + Flipper

I2C Sensor Seduction: DigiLab + Flipper

The DigiLab is an accessory for FlipperZero made by Lab401 and tixlegeek, that aims to be the first tool you reach for when exploring electronics. It's got a built-in scope tool & probe tool, and leverages sound, light and vibrations as physical feedback tools - enabling an entirely new and curiously intuitive way to explore circuits.

It's also got an I2C Probe tool. You've probably heard of I2C, and if you've built any Arduino or RaspberryPi-based gadgets that have attached gizmos, you've probably even used I2C.

I2C is a communication protocol, built in the 1980s, but remains the defacto protocol today for lower-speed communications between modules and sensors because of its simplicity (it only uses two wires), flexibility (you can have up to 127+ devices on the same lines, and speak to them individually!) and ubiquity (almost everything speaks I2C).

Before you fall asleep, here's the key question: why should I get excited about a tool that speaks 40-year old protocol?

The reality is, working with I2C devices, even today, can be very frustrating. Most I2C sensors are just micro computers that you can communicate with. Let's say you've got a temperature sensor, and you want to know what the temperature is. In theory, you can just ask it what the temperature is, and it will tell you. In reality, you need to wire the sensor up to some type of computer - an Arduino, an ESP-32, a Raspberry PI. Then need to setup a programming environment for the host device, and then find a library or write code to try to interface with the sensor. It's super inefficient, and feels awkward. Why can't you just reach into the sensor, grab the data and be done, no fuss?

With the DigiLab's I2C Probe, working with I2C is a breeze. Hook up the module, and it's automatically detected (and even supports multiple modules at the same time). It also identifies each module with its inbuilt Predictive Engine. Sending and Retrieving data is done via the built-in UI and hex-editor. All in all, you can connect, detect, identify and interact with an I2C module in minutes, as opposed to hours.

Let's get started

In this tutorial, we're going to learn how to connect and read data from a sensor in under under a minute. We're going to work with the LM75A sensor - a very popular temperature sensor. We'll see how we can connect the module, identify it, and read temperature data directly from the sensor - no code, no debugging.

The LM75ADPSensor on a breakout board.There are many LM75A breakout boards, but this is my own.

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 read the memory / registers of I2C modules
  • Leveraging AI to build useful tools

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

  1. Connecting the LM75ADP to the DigiLab
  2. Detecting and identifying the LM75ADP
  3. Obtaining and using the data-sheet
  4. Reading temperature data
  5. Building a tool to interpret retrieved data

Please note: The DigiLab can also write data to I2C devices, giving you complete control to configure sensors, write to memory chips, etc. We've got another tutorial on Using the DigiLab with a BMP280 Sensor - a much more complex sensor, which requires reading and writing. It's a bit more involved, but nevertheless you can control it completely with the DigiLab. If you want to learn how to interact completely with sensors and modules, it's a recommended read!

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

Connecting the LM75A to the DigiLab

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

  • The DigiLab 3.3V pin to the LM75A's VCC/3.3v pin
  • The DigiLab GND pin to the LM75A's GND pin
  • The DigiLab SCL pin to the LM75A's SCL pin
  • The DigiLab SDA pin to the LM75A'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 LM75

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 0x46. 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 LM75B is found, and that it's a "Temperature Sensor" from NXP. 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 LM75A sensor.

Scanning the document, we see that the sensor can actually do a bunch of interesting things (it can also be used as a thermostat, which will trigger at specific temperatures). However, what we're most interested in is on page 6, with the Register List (Table 5). A Register is the name for a chunk of memory where data is stored. Think of it like a postbox. It has a number, you can put things into it, take things out of it, and depending on the size, store different amounts in it.

The LM75A stores the temperature data in the Register with the address: 0x00. The register has a total size of 2-bytes.

Page 8 describes how the data is encoded, and gives some examples on how to decode it. Now, we know where to get the data, how much data to get, and how to convert it to something human-readable!

Reading temperature data

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

Enter the register 00 (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 2-bytes, so we enter 2 and click OK.

We're now inside the DigiLab's built in hex-editor, and peering directly into the memory of the LM75. We can see that there's two bytes of data. This is the temperature response from the module!

Take note of these two bytes: In our example, 1E 20

Building a tool to interpret retrieved data

Now we've retrieved the data, we need to convert it to a human readable form. The datasheet gave us information on how the data is encoded, and a bunch of examples. We can leverage this data and an AI engine to build a tool to decode the data

We are working with an LM75A temperature sensor.
The sensor holds the temperature data in two 8-bit data bytes, consisting of one Most Significant Byte (MSByte) and one Least Significant Byte (LSByte).

- Only 11 bits of those two bytes are used to store the Temp data in 2's complement format with the resolution of 0.125 °C.
- In the MSByte, all bits are used.
- In the LSByte, only bits 7, 6, 5 are used.

The remaining bits are discarded.

The bits are mapped as follows:
MSByte Bit 7: `D10`
MSByte Bit 6: `D9`
MSByte Bit 5: `D8`
MSByte Bit 4: `D7`
MSByte Bit 3: `D6`
MSByte Bit 2: `D5`
MSByte Bit 1: `D4`
MSByte Bit 0: `D3`
LSByte Bit 7: `D2`
MSByte Bit 6: `D1`
MSByte Bit 5: `D0` 
Temperature is calculated with the following method:
1. If the Temp data MSByte bit D10 = 0, then the temperature is positive and

Temp value (°C) = +(Temp data) * 0.125 °C.

2. If the Temp data MSByte bit D10 = 1, then the temperature is negative and

Temp value (°C) = -(2’s complement of Temp data) * 0.125 °C.

Build a Javascript tool that takes two Hexadecimal bytes as input, and decodes the corresponding temperature. Remember to convert the hexadecimal to binary, discard the bits 4, 3, 2, 1 and 0 from LSByte. Then map the bit values of MSByte and LSByte as per the above table, and perform the conversion.

AI will gurgle away for a while, and then you'll hopefully end up with a tool that will convert the temperature data from the module into something human readable. While we're hesitant to declare AI a net-positive, LLMs allow us to rapidly iterate tools that would previously have distracted from the main task at hand.

Congratulations!

Congratulations - you've just learned how to use the DigiLab to tame I2C modules. As you can see, the DigiLab abstracts multiple layers of complexity, allowing you to work directly with modules. While in this tutorial we only read data, you can just as easily write data. We've got an upcoming article on using the DigiLab to configure a more complex module by writing directly to the module.

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 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

Our tool for interpreting the LM75A sensor data is available on GitHub for experimentation and adaptation : https://github.com/lab-401/digilab-tutorial-lm75a

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

Leave a comment

Comments must be approved before appearing

* Required fields