How to get data from i2c device via usb in Linux

I have a temperature sensor that connects with a USB-I2C adapter ( http://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm ) I connected this device to my Linux computer (suse10). I typed in dmesg and saw

usb 3-3: new full speed USB device using ohci_hcd and address 10
usb 3-3: new device found, idVendor=0403, idProduct=6001
usb 3-3: new device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-3: Product: FT232R USB UART
usb 3-3: Manufacturer: FTDI
usb 3-3: SerialNumber: A7007K93
usb 3-3: configuration #1 chosen from 1 choice
ftdi_sio 3-3:1.0: FTDI USB Serial Device converter detected
drivers/usb/serial/ftdi_sio.c: Detected FT232BM
usb 3-3: FTDI USB Serial Device converter now attached to ttyUSB0

      

But I don't know how to read the current temperature.

updated 1: Actually the I2C bus can connect up to 127 sensors. But I have no idea how to list the addresses of the available sensors.

Can someone give me some hints? thanks in advance

+2


source to share


1 answer


Your adapter allows you to send I2C commands over a virtual serial port. A serial port has been created for you. You need to open it and send commands to it. These commands are specific to the device you are connected to. See the example in the link you provided to get an idea.

It's hard to give you correct instructions without a technical description. Most likely, your device will use a single byte address, and the reading procedure will look like this:

[I2C_AD1] [Device I2C address + Read bit] [Device Address register] [Number of bytes to read]
0x55 0xXX 0x00 0x01

      



You need to send 4 bytes to the serial port. The first instructs the USB to I2C converter to send the read command. The second is the address of the device connected to the I2C bus. I2C devices use 7-bit addresses (0-127). They are usually specified with one bit shifted to the left. So you need to scan these addresses (iterate from 0 to 127, shift left one bit, set bit 0 to 1):

([0x00 - 0x7F] << 1) | 1

      

Since we have no data, I cannot say anything about the last two bytes. You can try to use dummy values. If the device is connected to a scanned I2C address, it must respond with NACK to an attempt to read a nonexistent register. Reading commands sent to an I2C address that does not match the actual device should be ignored.

+4


source







All Articles