1

I am trying to get my laptop to communicate with my SRF02 sensor, which is using a USB-I2C interface. My laptop is running Debian Jessie.

Problem:

When I run sudo i2cdetect -y 0 I see no devices at all. This is the same for port 1 but beyond that lots of devices display at random places (eg port 4 shows a nearly full table). At none of the ports < 3 is EX70 taken, which is the device's default location.

I have tried auto loading i2c-dev on startup but the problem persists. The module docs say you need the FTDI VCP driver but this should be included in the Linux kernel.

I am convinced this is a software issue because I was able to get data using the exact same device and setup from a computer running Windows 8.

There are a lot of posts about this already but all of them are specifically Raspberry Pi based, and use the Raspbian and GPIO pins instead of USB.

EDIT: Here is a link to the dmesg output just after plugging in the device. The log is too large to post here :P http://pasted.co/38dc9292

Thanks in advance,

Max

5
  • VCP means "virtual COM port", so I'd assume the device to show up as ttyUSB*. Please include the dmesg output directly after you plug in the USB device.
    – dirkt
    Jan 28, 2017 at 15:57
  • Yes, it does show up up in dmesg: dmesg | grep ttyUSB [12013.441398] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0 [13409.273405] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0 [13411.102498] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0
    – Slidon
    Jan 28, 2017 at 18:10
  • I really mean "all the log after you put it in", not just the lines containing "ttyUSB". The other lines would have told you if any extra kernel modules are loaded, I2C or otherwise. Please edit your question and include all lines. Also, have you tried using it via the /dev/ttyUSB0 device? Just read from or write to it. What protocol does the sensor use over the serial port? You got documentation for it?
    – dirkt
    Jan 28, 2017 at 20:17
  • Soz, for misunderstanding, I've posted the full dmesg output. I don't know about accessing it via /devv/ttyUSB0, how would I do this? I don't know exactly which protocol is being used apart from this line from docs: "The USB-I2C module uses the FTDI FT232R USB chip to handle all the USB protocols" robot-electronics.co.uk/htm/usb_i2c_tech.htm
    – Slidon
    Jan 28, 2017 at 21:26
  • Looking at your "robot-electronics" link, it seems your hardware is simplifying the i2c API by providing you with a new layer on top of it that requires you only to write and read /dev/ttyUSB0 with special commands that are listed in the link. Look under "Commands" for these, such as the byte hex value 0x53. i2cdetect is therefore inappropriate.
    – meuh
    Jan 29, 2017 at 14:54

2 Answers 2

2

The relevant lines from dmesg are:

[  518.172735] usb 1-3: new full-speed USB device number 4 using xhci_hcd
[  518.306677] usb 1-3: New USB device found, idVendor=0403, idProduct=6001
[  518.306686] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  518.306689] usb 1-3: Product: FT232R USB UART
[  518.306692] usb 1-3: Manufacturer: FTDI
[  518.306695] usb 1-3: SerialNumber: AK04P01W
[  518.309382] ftdi_sio 1-3:1.0: FTDI USB Serial Device converter detected
[  518.309442] usb 1-3: Detected FT232RL
[  518.309445] usb 1-3: Number of endpoints 2
[  518.309448] usb 1-3: Endpoint 1 MaxPacketSize 64
[  518.309450] usb 1-3: Endpoint 2 MaxPacketSize 64
[  518.309453] usb 1-3: Setting MaxPacketSize 64
[  518.309771] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0

These are the relevant lines, because by the timestamps they belong together, as reaction to what happens when you plugin the device, and they happen long enough after the boot messages so there's no connection to that.

As you can see, a new USB device is detected, you are given details of the device, and in reaction to that, the module ftdi_sio is loaded, which provides the special device files /dev/ttyUSB0. If no kernel driver would habe been loaded, you could hunt (e.g. with google, or grep the kernel source) for the vendor/product combination (0403:6001, also shown in lsusb), and then try to find a kernel driver for this device.

The bcm2708 driver mentioned in the other answers isn't relevant at all: That's a driver for the I2C bus e.g. for the Raspberry Pi, and not for your laptop.

But we already have a working driver, which just provides a serial interface, and has no connection to the kernel I2C infrastructure. So lmsensors, i2detect etc. all won't work (unless you write or find an additional driver).

The website of your USB-I2C converter you mentioned in the comments explains the protocol to use over the serial link: You send a sequence of bytes, and then optional receive a sequence of bytes as an answer. The command sequence looks like

<command-byte> <address> <register (0-2 bytes)> <data byte count (0-1 bytes)> <write data>

And the webpage for the SRF 02 explains how the registers of the sensor chip look like: 6 registers you can read, one 1 command register you can write.

So, for example, to read the version, you need to read 01 byte from register 00, the default chip address is E0, the LSB is the R/W bit, so instead you use E1 as address, and the required command for the USB-I2C adapter is 55. So the full sequence you'd send over serial is 55 E1 00 01, and then you'd read one byte as answer.

You can do that from the command line:

$ printf '\x55\xE1\x00\x01' > /dev/ttyUSB0
$ hexdump -n 1 -e '"%02x \n"' < /dev/ttyUSB0

Or you can open /dev/ttyUSB0 in your favorite language, and then just read and write bytes using the commands your language provides.

3
  • Hi Dirkt, thanks for super helpful + understandable + extensive answer!!! I read back through the docs and was able to create different command for the stuff I wanted to to. HOWEVER When I run the above commands (or the quick implementation I made in python) hexdump hangs indefinitely and doesn't output anything. This is the same when I read the device in Python. Why do you think this is happening?
    – Slidon
    Jan 29, 2017 at 20:38
  • I don't know. I don't have the device in front of me and can't experiment, and I just rephrased the info on the web the way I understood it. Possibly I made a mistake somewhere. Possibly baud rate or other settings are wrong (check stty). Possibly the sensor is not in I2C, but in serial mode, so you need a different protocol. Possibly you don't have the exact USB-I2C converter that's described on the page. Etc. pp.
    – dirkt
    Jan 30, 2017 at 5:34
  • Ok I have a go at the stuff you mentioned, thx anyway
    – Slidon
    Jan 30, 2017 at 14:43
2

There are two i2c kernel modules:

i2c-bcm2708 

and

i2c-dev

Add both to /etc/modules, and the restart.

4
  • When I try to add i2c-bcm2708 I get the following error: modprobe: FATAL: Module i2c-bcm2708 not found.
    – Slidon
    Jan 28, 2017 at 18:07
  • @Slidon Blacklist the i2c-bcm2708 doesn't help ?
    – GAD3R
    Jan 28, 2017 at 21:45
  • sorry I don't really understand. Do you mean check that it isn't blacklisted? I have done that already
    – Slidon
    Jan 28, 2017 at 21:54
  • I guess probably depends of kernel version. In my case: /lib/modules/3.10.32+/kernel/drivers/i2c/busses/i2c-bcm2708.ko does exist Feb 1, 2017 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .