User Tools

Site Tools

Translations of this page?:

en:usbi2c

Converter from USB to I²C or SMBus - USBI2C01A

I²C is widely used bus intended for connection of various sensors on short distances. But it is not usual to interface this bus at personal computers because it is not accessible as standard interface. 1)

USBI2C01A

This module could solve such problem by using the Silicon Labs CP2112 IO, which is direct converter between USB and SMBus or I²C respectively.

Use of the module

The module is enumerated as standard HID device by default. Such behavior allows use without special drivers on every operating system. But some operating systems contain special software for manipulating with I2C/SMBus. In such case is useful to change generic USB HID driver by special driver which connect the MLAB module as standard I2C or SMBus interface.

HIDAPI connection method

HIDAPI is software interface to access HID devices from Linux, Windows or MAC OS. The library works on all mayor computer platforms and architectures. The prerequisite to get HIDAPI work is libusb-1.0 library installed in the system.

Ubuntu 14.04

We should install hidapi and some other packages by running.

sudo apt-get install libudev-dev libusb-1.0-0-dev libhidapi-dev python-setuptools python-pip python-smbus cython 

Then we only need package Pymlab

sudo pip install pymlab

Then a new I2C interface may be used in the system, as is mentioned in the page I²C bus as an MLAB's component. The module allows even direct access to its GPIO pins.

The example of Python LED blinking script on USBI2C01A IO ports
import hid
import time

try:
    print "Opening device"
    h = hid.device()
    h.open(0x10C4, 0xEA90)

    print "Manufacturer: %s" % h.get_manufacturer_string()
    print "Product: %s" % h.get_product_string()
    print "Serial No: %s" % h.get_serial_number_string()

    h.write([0x02, 0xFF, 0x00, 0x00, 0x00])  # sets output to open-drain
    time.sleep(0.1)
    for k in range(10):
        h.write([0x04, 0xFF, 0xFF])  # writes 1 to all  8 outputs pins.
        time.sleep(0.1)
        h.write([0x04, 0x00, 0xFF])  # writes 0 to all 8 outputs pins.
        time.sleep(0.1)

    print "Closing device"
    h.close()

except IOError, ex:
    print ex

print "Done"

This example should be executed as root in default configuration.

The details of HIDAPIO acces to IO ports should be found in this document

Correct setting of access right to USB

If we need an access to USBI2C01B module without root privileges we need to create a file SiliconLabs.rules in /etc/udev/rules.d directory. The file should contains:

SUBSYSTEM=="usb", ATTRS{idVendor}=="10c4", MODE="0666"
SUBSYSTEM=="usb_device", ATTRS{idVendor}=="10c4", MODE="0666"

Linux Kernel

The Linux is a case of operating system in which system access to I2C or SMBus interfaces currently exists. In Linux is useful to change generic HID driver by new software module in the kernel. The CP2112 IO is directly supported in Linux kernel from 3.16. In that case a loading of i2c-dev Linux kernel module is only required operation. We should do this by sudo modprobe i2c-dev. Then we should see a new I²C interface in system bus list.

kaklik@UST-vyvoj:~$ sudo i2cdetect -l
i2c-0	i2c       	i915 gmbus ssc                  	I2C adapter
i2c-1	i2c       	i915 gmbus vga                  	I2C adapter
i2c-2	i2c       	i915 gmbus panel                	I2C adapter
i2c-3	i2c       	i915 gmbus dpc                  	I2C adapter
i2c-4	i2c       	i915 gmbus dpb                  	I2C adapter
i2c-5	i2c       	i915 gmbus dpd                  	I2C adapter
i2c-6	i2c       	DPDDC-B                         	I2C adapter
i2c-7	smbus     	CP2112 SMBus Bridge on hiddev0  	SMBus adapter
i2c-8	smbus     	CP2112 SMBus Bridge on hiddev0  	SMBus adapter
kaklik@UST-vyvoj:~$

If we the new interface we should use it exactly same as standard system I²C bus. But CP2112 does not support SMBus Quick Write function. Then we should avoid use of the Quick Write by -r parameter as is demonstrated in following example:

kaklik@UST-vyvoj:~$ sudo i2cdetect -y -r 8 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         
kaklik@UST-vyvoj:~$

We see that device with address 0x70, which is the I²C Hub module in that case.

Examples of connected I²C devices

CLKGEN01B

Connection of the clock generator. This case is used in Radio Meteor Detector Station design.

Digital clock generator CLKGEN01B

The example of use the CLKGEN01B module and USBI2C01A

MAG01A

Magnetometer connection.

mag

 USBI2C01A module connected to MAG01A magnetometer.

GPIO

References

en/usbi2c.txt · Last modified: 2014/12/27 22:34 by kaklik