Skip to content

Arduino I2C libraries

Koepel edited this page May 16, 2022 · 51 revisions

Overview of Arduino I2C libraries

The number of software I2C libraries are still increasing. This pages gives an overview of many libraries for I2C for Arduino boards.

The original Wire library for AVR processors is described in https://www.arduino.cc/en/Reference/Wire. Different platforms using different microcontrollers will provide their own versions of the <Wire.h> library and are preinstalled when their "Arduino Core" is installed. These alternative Wire libraries are mostly compatible with API of the original AVR Wire library, but many of them will deviate slightly from the AVR version to implement additional functionality that is available only for the particular microcontroller.

Most 3rd party I2C libraries will also try to follow the same API as the original AVR Wire library. However, many of them don't. In the table below, the "Arduino Wire compatible functions" column indicates whether the given library is mostly compatible with the original Arduino AVR Wire library. In this context, compatibility means source-code API level, instead of runtime level. The default Wire library for each platform will use a class named TwoWire. Some 3rd party I2C libraries will inherit from the TwoWire class, but it is also possible to provide API compatibility without subclassing TwoWire. In fact, since the design of the TwoWire class does not allow polymorphism (see https://github.com/Testato/SoftwareWire/issues/28), it is often better for the 3rd party class to avoid inheriting its implementation from TwoWire or even Stream (see https://github.com/Testato/SoftwareWire/pull/32).

The software I2C libraries are generally master-mode only. There are a few I2C software slave implementations, but they do not follow the I2C requirements and are only for one type of processor.

Library Hardware / Software Arduino Wire compatible functions Multiple I2C buses Slave mode RX/TX Buffer Sizes Notes
General
Steve Marple SoftWire software yes, SoftWire inherits from Stream yes no RX:user, TX:user Supports clock pulse stretching. The RX and TX buffers are supplied by the user, so can be any length.
XantoI2C software no, XantoI2C is top-level yes no RX:0, TX:0 Made from scratch, using straighforward Arduino functions. Receive functionality incomplete, no ACK/NACK from master to slave
SWire software yes, SoftWire is top-level yes no RX:32, TX:32 Based upon XantoI2C. Implements receive functionality.
felias-fogg SlowSoftWire software yes, SlowSoftWire inherits from Stream yes no RX:32, TX:32 Using compatible standard Arduino functions. Using the Stream class, just like the Arduino Wire library.
Seeed-Studio Arduino Software I2C software yes, SoftwareI2C is top-level yes no RX:0, TX:0 No delayMicroseconds() between bit transitions. Breaks some devices on some fast 32-bit processors due to exceeding I2C clock maximum. Uses digitalWrite() to set SDA line actively to HIGH instead of relying on passive pullup resistors, which may cause problems on open-drain I2C lines.
AceWire software yes, TwoWireInterface, SimpleWireInterface, SimpleWireFastInterface are top-level yes no RX:0, TX:0 Provides an adapter class that delegates to other 3rd party libraries. Also provides 2 simple bigbanging implementations.
AVR
Arduino Wire hardware yes, TwoWire inherits from Stream no no RX:32, TX:32 Preinstalled Wire library for AVR.
SoftwareWire software yes, SoftwareWire is top-level yes no RX:32, TX:0 Runs at 100kHz clock speed on a Arduino Uno.
felis-fogg SoftI2CMaster software yes, SoftWire inherits from Stream yes ? no RX:32, TX:0 using assembly for timing.
todbot SoftI2CMaster software yes, SoftI2CMaster inherits from TwoWire yes no RX:0, TX:0 Inherits from TwoWire so SoftI2CMaster inherits the RX/TX buffers used in TwoWire but does not use them
DSSCircuits I2C-Master-Library hardware no, I2C is top-level ? no RX:32, TX:32 A single 32-byte buffer is shared between RX and TX.
Greiman SoftI2cMaster software no, SoftI2cMaster and FastI2cMaster inherit from I2cMasterBase which is top-level ? no RX:0, TX:0 Uses its own fastDigitalWrite() functions to write to port registers directly.
HardWire hardware yes, TwoWire inherits from Stream ? no RX:32, TX:32 Similar to Arduino Wire. Class name clashes with <Wire.h> so cannot be included into the same source code, even indirectly.
jm_Wire hardware yes, TwoWire inherits from Stream yes no RX:32, TX:32 Copies most of the <Wire.h> library from AVR and adds time-out and concurrency tweaks.
SoftIIC software no, SoftIIC is top-level yes yes RX:0, TX:0 Software I2C for master and slave mode. The software slave mode works with some restrictions.
BitBang_I2C software no, provides C functions not C++ classes no no RX:0, TX:0 Supports ATmega, ATtiny, and Raspberry PI. Larry Bank has also a Multi-BitBang version.
Two-Wire Interface hardware no no no unlimited Non-blocking. With timeouts. Supports SMBus.
ATtiny
SpenceKonde Wire hardware yes, TwoWire inherits from Stream no no RX:32, TX:32 Preinstalled Wire library for the ATTinyCore
TinyWireM hardware no, USI_TWI is top-level no no RX:32, TX:32 For ATtiny microcontrollers. Master mode.
TinyWireS hardware yes, USI_TWI_S is top-level yes (note on request handler) yes RX:16, TX:16 For ATtiny microcontrollers. Slave mode.
USIWire hardware yes, USIWire is top-level no no RX:16, TX:16 For ATtiny microcontrollers.
TinyI2C hardware no, TinyI2CMaster is top-level no no RX:0, TX:0 For ATtiny microcontrollers.
Arduino SAMD
Wire hardware yes, TwoWire inherits from Stream yes no RX:256, TX:256 Default preinstalled Wire library for Arduino's SAMD21 boards.
SparkFun SAMD
Wire hardware yes, TwoWire inherits from Stream yes no RX:256, TX:256 Default preinstalled Wire library for SparkFun's SAMD21 boards.
STM32
Wire hardware yes, TwoWire inherits from Stream yes no RX:32, TX:32 Preinstalled Wire library for STM32duino.
ESP8266
ESP8266 Wire software yes, TwoWire inherits from Stream no no RX:128, TX:128 Preinstall Wire library for ESP8266.
brzo_i2c software no, provides C functions not C++ classes no no RX:0, TX:0 Written in assembly for the ESP8266. Up to 1 MHz clock speed.
ESP32
Wire hardware yes, TwoWire inherits from Stream yes no RX:128, TX:128 Preinstalled Wire library for ESP32. Predefines 2 instances: Wire and Wire1.

Notes:

  • There is a I2C library by rinkydinkelectronics.com which is the only library that uses shiftOut() for the 8 databits, and after that it reads or writes the acknowledge bit. This is also one of a very few libraries that sets the SDA signal as a output HIGH and LOW instead of relying on the pullup resistor. When the Slave should respond, the SDA signal is set as input, just before the rising clock of SCL to avoid a shortcut.
  • The I2C Anything by Nick Gammon can be used to read and write variables and data that are longer than a byte in a easy way.
  • Beside master and slave, there are also I2C sniffers.
  • As far as I know, none of the software implementations support multi-master I2C buses.