In simple terms: i2cdevlib is a collection of libraries written for common I2C devices. Each device (such as MPU6050, HMC5883, BMP085, etc.) has a “device class,” and these device classes rely on a common I2C abstract class called I2Cdev. What are the benefits? The device classes only handle the “human-friendly interface” (like readAccelX()), while the underlying bit/byte read/write details are managed by I2Cdev. This way, when you switch platforms (Arduino, PIC, MSP430, or even your own bit-banging), you only need to modify I2Cdev, and the other device classes remain unchanged.
What Pain Points Does It Solve?
- • No need to dig into register bits every time: the device classes encapsulate common functionalities.
- • Multi-platform reuse: abstracting the underlying I2C makes porting easier.
- • Many examples: popular devices usually come with example code that can be run directly.
- • Memory savings: I2Cdev is designed for static use, allowing multiple devices to share the same I2C object, saving space.
- • Supports multiple I2C buses (the new version can accept different Wire objects under Arduino): friendly for those who want to connect multiple IMUs directly.
Installation Instructions: The repository is quite large and contains code for many platforms, so installation is not as straightforward as a typical Arduino library with a “one-click install.” Here are the most common steps for Arduino, applicable to both Windows and Linux.
Steps:
- 1. Download the Zip from the repository or use git clone: git clone https://github.com/jrowberg/i2cdevlib.git
- 2. Navigate to the Arduino directory in the repo and find the two folders you need (usually I2Cdev and the specific device, like MPU6050).
- 3. Copy these two folders to your Arduino library directory (usually under Documents/Arduino/libraries/), or place them directly in the libraries folder at the same level as your project.
- 4. Restart the Arduino IDE or rescan libraries.
- 5. Open the example, modify the serial baud rate, adjust the pins (if necessary), and upload to run.
Tip: On Linux, you can use symbolic links (ln -s) to maintain a central repository; on Windows, use mklink /D to do something similar. This makes future updates easier.
Common Use Cases
- • Want to get acceleration and gyroscope data from MPU6050? Use the library’s encapsulated getAcceleration()/getRotation().
- • Want to read temperature and pressure from BMP085 and calculate altitude? The library has readTemperature()/readPressure().
- • Need multiple I2C or several identical IMUs? The new version supports passing different Wire objects, allowing you to do this without relying on an I2C multiplexer.
A Small Table: Typical Device Support and Features
| Device (Common) | Complete Class Available | Example/Documentation | Applicable Scenarios |
| MPU6050 | Yes | Complete examples (acceleration/gyroscope/filter) | Flight control, attitude estimation |
| HMC5883 | Yes | Basic magnetometer reading example | Compass, heading |
| BMP085/BMP180 | Yes | Temperature/pressure, altitude calculation | Barometric altitude, environmental monitoring |
| Any I2C Sensor | Depends on the specific device | If not available, you can write your own class and submit a PR | Custom device classes can be reused |
Advantages
- • A large number of device classes covering common sensors.
- • Unified code style, easy to read and extend.
- • Many examples, quick to get started.
- • Supports multiple platforms, with good I2C abstraction.
- • Community and documentation (includes Doxygen documentation and the website i2cdevlib.com).
Disadvantages
- • The repository is too large, and the structure is not modernized—unlike current single libraries that can be managed directly in the IDE.
- • It has been around for a while, and some platforms/implementations may not be optimal or are no longer maintained.
- • If your device is not in the library, you need to manually add classes following the existing style, which can be a bit of work.
- • For beginners, understanding the basic concepts of I2C is necessary for troubleshooting; it is not completely “foolproof.”
Conclusioni2cdevlib is a very practical collection of “device layers” suitable for engineers and enthusiasts who want to quickly integrate I2C sensors into their projects, hoping for portable code and reduced repetitive work. The main drawbacks are the organization of the repository and its age, but the value of its functionality and examples remains high. When doing product-level porting, it may require restructuring the underlying code, but as a development prototype and learning resource, it is still one of the top choices.
Project address: https://github.com/jrowberg/i2cdevlib