-
Notifications
You must be signed in to change notification settings - Fork 34
Arduino I2C libraries
Brian Park edited this page Aug 24, 2021
·
51 revisions
The number of software I2C libraries are still increasing. This pages gives an overview of many libraries for I2C for Arduino boards.
The "Arduino Wire compatible functions" means that the functions are named the same as the functions of the Arduino Wire library, and it is a drop-in replacement for the Arduino Wire library.
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 |
---|---|---|---|---|---|---|
Default | ||||||
Arduino Wire | hardware | yes, TwoWire inherits from Stream
|
If the hardware supports it | no | RX:32, TX:32 | There are a number of different official Wire libraries for the different boards. |
General | ||||||
Steve Marple SoftWire | software | yes, SoftWire inherits from Stream
|
yes | no | RX:user, TX:user | Supports clock pulse stretching. |
XantoI2C | software | no, XantoI2C is top-level |
yes | no | RX:none, TX:none | 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. |
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. |
ATtiny | ||||||
SpenceKonde Wire | hardware | yes, TwoWire inherits from Stream
|
no | no | Default <Wire.h> library in 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. |
ESP8266 | ||||||
ESP8266 Wire | software | yes, TwoWire inherits from Stream
|
no | no | RX:128, TX:128 | The official Wire compatible library of esp8266.com is a software implementation. |
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. |
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 the only library 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.