I2C Pico USB Adapter: Part 4 - Usage
In this last part, I will show a few ways to use the adapter under Linux and Windows.
Accessing an I2C device with Python, under Windows |
Linux
The i2c-tiny-usb started under Linux, and a driver is standard on Linux.
A few utilities are available in the i2c-tools package (you probably will need to install it with your distro's package manager). To check if the adapter is working and recognized use
sudo i2cdetect -l
The output should include a line like "i2c-n i2c-tiny-usb at ...", where 'n' is a number that identifies the I2CBUS. You will use this number in other i2c-tools commands. To check the address of connected devices, use
sudo i2c-detect n
You will first get a warning that probing for i2c devices can have bad effects on some devices, you can use the -y option to suppress this warning.
The 'i2c-get' and 'i2c-put' commands can be used to read and write to and from I2C devices that use the concept of registers, where a read is preceded by a write of the register's address (form 0x00 to 0xFF).
Details for the i2c-tools commands can be found on the man pages.
Like most devices, the i2cbus can be accessed like a file. The name is '/dev/i2c-n', and there are a few ioctl functions available. Documentation can be found at https://www.kernel.org/doc/Documentation/i2c/dev-interface. It is not hard to write small C programs to interact with I2C devices.
Windows
Windows does not have built-in support for the adapter, but we can still use it. You will need to install a driver (libusb) for the adapter. The easiest way is to use Zadig (https://zadig.akeo.ie/). Plug the adapter, run Zadig, and select "libusb-win32".
There are many ways to use libusb under Windows. In my testing, I used PyUSB (https://github.com/pyusb/pyusb) with Python 3. Notice that this is a low-level API that just gives access to the adapter's endpoints.
Comments
Post a Comment