todbot / LinkM

BlinkM controller / programmer and general USB-to-I2C adapter
http://linkm.thingm.com/
14 stars 6 forks source link

troubling timing issue? #5

Open lobsteroh opened 8 years ago

lobsteroh commented 8 years ago

oh no, i am running into communication errors with any repeated i2c reads. I get the same with 4 different kinds of i2c chips, and even the BlinkMs. the following example code

        int addr = 9;
        int counter = 0;
        while (counter<100) {
            System.out.println(counter + ": ");
            linkm.getVersion(addr);
            //Thread.sleep(500);
            counter++;
        }

runs for a few times then throws IOException

Error sending message: usb_control_msg(DeviceRequestTO): the device is not responding
error reading data: Communication error with device
java.io.IOException: Communication error with device
at thingm.linkm.LinkM.command(Native Method)
at thingm.linkm.LinkM.commandi2c(LinkM.java:502)

if I make the Thread sleep, successful completions go up. A sleep of 500ms is needed to have this task start to run somewhat reliably. Don't have the option of reading only every half second. Any idea on how to fix it? - happens in my hands on MacOSX 10.11.4, LinkM, BlinkM, Java (build 1.8.0_77-b03), Eclipse

lobsteroh commented 8 years ago

update ... reporting on various suggestions on how to fix ...

add 100nF capacitor between VCC and ground - does not change failure

lobsteroh commented 8 years ago

is libusb-legacy the issue, can i switch to libusb?

todbot commented 8 years ago

Hi, libusb-0.1 (which is what libusb-legacy is pretending to be) is what's needed for the current LinkM library. libusb-1.0 has an entirely different API.

I'm not sure what's requiring you to wait ~500msec. I've been looking into it and it does seem like a driver issue, but I've not found anything telling yet.

lobsteroh commented 8 years ago

hi tod, thanks a stack, in playing with this, the faults look really random. even if i issue the read commands at full speed i sometimes get 15 reads until it fails. it almost looks like something not being ready to communicate between linkm and PC, rather than on the serial output end of the linkm. can you confirm that your setup is running into the same issue, or is my system screwing things up. let me know if i can be of help in testing, troubleshooting or developing. be well,

lobsteroh commented 8 years ago

ok, looks like a usb3 vs usb2 issue. When i plug the LinkM into a usb2 hub, and that into the usb3 port on my mac, then the linkm starts to play a lot nicer.

stonehippo commented 3 months ago

I know this ancient thread, but just dropping in to add a data that this seems to be an issue with some USB3+ ports. When I had the linkm connected to the USB-C port on my Macbook Air (USB3.1), it reported I2C comms issues. Plugging it into a USB2 hub and things work great.

Can probably close this one, if you're so inclined, @todbot.