How to use I²C over USB
Introduction
Several routers and embedded devices with OpenWRT-support are equipped with one or more USB ports. In order to risk your warranty by opening your device and soldering an I²C bus to the GPIOs, you can use an USB-I²C adapter to connect to your I²C-devices (e.g. temperature sensors, RTCs, AD-converters, GPIO-expanders, LCD-Drivers). One of those adapters is called i2c-tiny-usb, developed by Till Harbaum. Biggest advantage is the low price (though not as cheap as the GPIO mod) and the support in the Linux kernel (thus making it possible to connect it to your computer running a recent Linux distribution and test it). Though you need some basic soldering skills, and at the moment you need to build OpenWRT from source.
Compiling the kernel module
| | Note: This module is now in trunk, called kmod-i2c-tiny-usb. You can use a snapshot and install this kernel module with opkg. |
Follow the build instructions until you reach the topic building images. At that point you have to edit you kernel configuration:
make kernel_menuconfigMake sure the following items are selected:
- Device Drivers > I2C support > I2C device interface <*> (to get access through /dev/i2c-X)
- Device Drivers > I2C support > I2C Hardware Bus support > Tiny-USB adapter <*>
Continue with the build instructions.
Using the I²C bus
Since the module is compiled into the kernel, the I2C-Tiny-USB adapter can be plugged in. The successful registration can be tested:
dmesg | tail usb 1-3.3: new low speed USB device using ehci_hcd and address 5 usb 1-3.3: New USB device found, idVendor=0403, idProduct=c631 usb 1-3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 1-3.3: Product: i2c-tiny-usb usb 1-3.3: Manufacturer: Till Harbaum usb 1-3.3: configuration #1 chosen from 1 choice i2c-tiny-usb 1-3.3:1.0: version 1.05 found at bus 001 address 005 i2c-adapter i2c-0: connected i2c-tiny-usb device usbcore: registered new interface driver i2c-tiny-usb
If the i2c-tools package is installed, basic operations with i2cdetect, i2cget and i2cset can already be performed.
Precaution
This I²C bus operates at 5V. Make sure not to connect I²C devices incompatible with this voltage level!
doc/howto/usb.i2c-tiny-usb.txt · Last modified: 2011/10/13 22:35 by written_direcon