en:usbi2c
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | en:usbi2c [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Converter from USB to I²C or SMBus - USBI2C01A ====== | ||
+ | |||
+ | [[en: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | This module could solve such problem by using the [[http:// | ||
+ | |||
+ | ===== 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 [[https:// | ||
+ | |||
+ | 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 [[en: | ||
+ | sudo pip install pymlab | ||
+ | | ||
+ | Then a new I2C interface may be used in the system, as is mentioned in the page [[en:i2c]]. 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 " | ||
+ | h = hid.device() | ||
+ | h.open(0x10C4, | ||
+ | | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | | ||
+ | h.write([0x02, | ||
+ | time.sleep(0.1) | ||
+ | for k in range(10): | ||
+ | h.write([0x04, | ||
+ | time.sleep(0.1) | ||
+ | h.write([0x04, | ||
+ | time.sleep(0.1) | ||
+ | | ||
+ | print " | ||
+ | h.close() | ||
+ | | ||
+ | except IOError, ex: | ||
+ | print ex | ||
+ | | ||
+ | print " | ||
+ | |||
+ | //This example should be executed as root in default configuration.// | ||
+ | |||
+ | <WRAP info round> | ||
+ | The details of HIDAPIO acces to IO ports should be found in [[http:// | ||
+ | |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 **/ | ||
+ | |||
+ | SUBSYSTEM==" | ||
+ | SUBSYSTEM==" | ||
+ | | ||
+ | ==== 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. | ||
+ | |||
+ | kaklik@UST-vyvoj: | ||
+ | i2c-0 i2c | ||
+ | i2c-1 i2c | ||
+ | i2c-2 i2c | ||
+ | i2c-3 i2c | ||
+ | i2c-4 i2c | ||
+ | i2c-5 i2c | ||
+ | i2c-6 i2c | ||
+ | i2c-7 smbus | ||
+ | i2c-8 smbus | ||
+ | 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: | ||
+ | | ||
+ | 00: -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | ||
+ | 70: 70 -- -- -- -- -- -- -- | ||
+ | kaklik@UST-vyvoj: | ||
+ | |||
+ | We see that device with address //0x70//, which is the [[en: | ||
+ | |||
+ | ==== Examples of connected I²C devices ==== | ||
+ | |||
+ | === CLKGEN01B === | ||
+ | |||
+ | Connection of the clock generator. This case is used in [[en: | ||
+ | |||
+ | [[en: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | |||
+ | === MAG01A === | ||
+ | |||
+ | Magnetometer connection. | ||
+ | |||
+ | [[en:mag]] | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | === GPIO === | ||
+ | |||
+ | [[cs: | ||
+ | |||
+ | {{youtube> | ||
+ | |||
+ | ===== Related pages ===== | ||
+ | |||
+ | * [[en: | ||
+ | * [[en: | ||
+ | * [[en: | ||
+ | |||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
en/usbi2c.txt · Last modified: 2014/12/27 21:34 (external edit)