I am doing a line following robot based on opencv. I have my onboard computer(an old pandaboard) running opencv. It will calculate the offset from the required path and communicate it to the arduino via USB. Then it will do PID optimisation on the data, and adjust the speed of the left and right motors.

To my dismay the communication part is not working, and I've tried hard for a day to fix it with no result. Here is the relavent code running on the pandaboard:


        r = libusb_bulk_transfer(dev_handle, 131, recieve, 1, &actual, 0);
        int a;

//make write

        cout<<"Data to send->"<<imgvalue<<"<-"<<endl; //just to see the data we want to write : abcd
        cout<<"Writing Data..."<<endl;
        r = libusb_bulk_transfer(dev_handle, (4 | LIBUSB_ENDPOINT_OUT), send, 2, &actual, 0); //my device's out endpoint was 2, found with trial- the device had 2 endpoints: 2 and 129
        if(r == 0 && actual == 2) //we wrote the 4 bytes successfully
            cout<<"Writing Successful!"<<endl;
            cout<<"Write Error"<<endl;


where imgvalue is the data to be send. This is the code running on the Arduino:

void loop()
    Input_tmp = Serial.read();
    Input_tmp = Input_tmp | (Serial.read() << 8);

// adjust the motor speed


What happens when I run is that it will pause at the libusb read operation as the timeout is zero(infinity). At this point I've tried resetting the arduino, but this doesn't help. So how do I make my program respond to this start byte send my the Arduino? Where did I go wrong?

  • $\begingroup$ As a follow up to my answer/question, I guess I would ask to see your code where you initialize and configure the USB connection. $\endgroup$ – Chuck Jun 3 '15 at 8:25

Did you initialize libusb?

From the Sourceforge documentation:

int libusb_init ( libusb_context ** context )

Initialize libusb.

This function must be called before calling any other libusb function.

Seems like a trivial thing to ask but I didn't see it in your code, but I also don't see anything blatantly wrong with your code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.