# Libusb and arduino communication not working

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:

while(1)
{

r = libusb_bulk_transfer(dev_handle, 131, recieve, 1, &actual, 0);
cout<<"r="<<r<<endl;
int a;
cin>>a;
imgvalue=krish.calc_offset();
send[0]=imgvalue&0xff;
send[1]=imgvalue>>8;

//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;
else
cout<<"Write Error"<<endl;

}


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

void loop()
{
Serial.write('s');
if(Serial.available()>0)
if(Serial.available()>0)
Input_tmp = Input_tmp | (Serial.read() << 8);
Input=Input_tmp;
myPID.Compute();

}


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?

• 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. Jun 3 '15 at 8:25