Skip to content
Ruby I2C library
Branch: master
Clone or download
Xasin Version bump
Latest commit ee146fc Jun 15, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
rules Initial import. Aug 3, 2012
test Unified the MCP23017 and MCP23008 drivers in one meta-module and a ge… May 15, 2013
.gitignore Gemspec update. Aug 7, 2012
README.rdoc Author-Change and gemspect update Jun 12, 2018
i2c.gemspec Version bump Jun 15, 2018


I2C - Ruby I2C library


Interface to Linux I2C (a.k.a. TWI) implementations. Right now targeted at the Raspberry Pi, but should work with any linux i2c-dev I2C-hardware.


The library is split into two parts:

  • A backend for accessing the I2C bus (right now only through the i2c-dev

in Linux, other impementations are possible).

  • Drivers for I2C enabled ICs.


To use the i2c-dev backend it is necessary to load the “i2c-dev” linux kernel module. This is not done automatically even if the module for the underlying I2C-hardware is. To automatically load the i2c-dev driver on startup add it to /etc/modules. Also the device file (usually /dev/i2c-0) must be user accessible. A working (at least on a RaspberryPi running Raspbian) udev rule file is available (rules/88-i2c.rules) and can be installed to /etc/udev/rules.d/.


The backends are instantiated through the #I2C::create method. depending on the format of the passed bus descriptor the correct backend is invoked.

Right now there is only a i2c-dev backend available

i2c-dev Backend

Backend for the Linux I2C implementation. Accepts device file names as bus descriptors. E.g.

I2C.create(“/dev/i2c-0”) returns an instance of I2C::Dev attached to the first I2c bus on the system.



16 bit IO-Expander MCP23017 from Microchip. Provides a wiringpi-ruby compatible API and may therefore be used as a drop-in replacement for IO tasks on a Raspberry Pi. Datasheet:


8 bit IO-Expander MCP23008 from Microchip. Basically a small version of the MCP23017. Datasheet:


The low-level IO (mainly in i2c-dev.rb) was extracted from Ruby-I2C ( by Jonas Bähr <>



  • Pierre Paques

Copyright / Licence

This code may be used under the terms of the GNU General Public Licence, Version 2.

Copyright © 2018 David Bailey <> Copyright © 2012 Christoph Anderegg <> Copyright © 2008 Jonas Bähr <>

You can’t perform that action at this time.