Using I²C Sensors With Any Linux Via USB And IIO

Hooking up I2C sensors is something which is generally associated with microcontrollers and SBCs, yet it’s very easy to use such I2C sensors from basically any system that runs Linux. After all, I2C (that is, SMBus) is one of the interfaces that is highly likely to be used on your PC’s mainboard as well as peripherals. This means that running our own devices like the well-known BME280 temperature, pressure and humidity sensor, or Si1145 light sensor should be a piece of cake.

In a blog post from a few years ago, [Peter Molnar] explains in detail how to wire up a physical adapter to add a USB-connected I2C interface to a system. At its core is the ATtiny85 AVR-based MCU, which provides a built-in USB interface, running the I2C-Tiny-USB firmware.

The essential part here is that the MCU shows up to the Linux kernel as an i2c device, requiring the i2c-dev driver to be loaded. After this the I2C device that is connected to the adapter MCU’s I2C bus can be used via the Linux module’s API calls, either directly or via existing drivers. [Peter] found that the BMP280 driver came with Debian Sid, for example.

11 thoughts on “Using I²C Sensors With Any Linux Via USB And IIO

  1. On most non-Apple *Nix computers, you can also use the i2c lines in the VGA, DVI or HDMI plug, which normally are used by the system to either read a ROM chip in the monitor that contains compatible resolutions and refresh rates, or for bi-directional communication between monitor and computer.
    Though a few gpu drivers were clunky at permitting that though, but that’s not so relevant nowadays.

  2. ive used the i2c port on the raspberry pi to expand the io capabilities and add analog sticks via a tiny85. linux makes these things stupid easy. on windows you can spend all day downloading sdks and stll cant get it to work.

  3. > At its core is the ATtiny85 AVR-based MCU, which provides a built-in USB interface

    The T85 does not have a built in USB interface.

    > came with Debian Sid

    Which Sid? Sid was Sid decades ago and Sid is Sid now.

    1. >> At its core is the ATtiny85 AVR-based MCU, which provides a built-in USB interface
      > The T85 does not have a built in USB interface.
      Correct, it was done in software here.

      >> came with Debian Sid
      > Which Sid? Sid was Sid decades ago and Sid is Sid now.
      Correct, the author maybe wanted to express that Sid underwent that change at some point in time already. The i2c-tiny kernel driver was included from 2.6.22 (roughly 2007) onwards, bmp280 driver was introduced in late 2014.

      OP could maybe have done their research.

    2. >The T85 does not have a built in USB interface.

      True, but T85 has a working well enough USB implementation in software. Hence the Digispark T85 boards that are both programmable via USB and usable as USB peripherals (micro keyboards / stream decks, for example).

  4. I get that this website is about hacking things together, but if all you want to do is use I²C sensors with linux, then a USB to I²C master adaptor like the CP2112 should be plug and play or the CH341T (little cheaper) with special drivers work fine for me.

Leave a Reply to PabloCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.