Interface with Xbox 360 joystick via USB Host

Hi everyone! I've been looking for a while and I can't find information about this in the forum or any other place. I would like to now if there is a way to connect via USB a Xbox 360 controller to the Arduino DUE, and to get the keypresses and all the information a computer would get from the joystick. As far as I know, out of the box Arduino Due IDE is able to interface with USB Keyboards or Mouses. I was wondering if is any way to have low level access to the USB protocol, or something already developed to interface with generic USB Hardware, or more specifically, the 360 controller. Thanks!

So I’ve actually been trying to tackle the same problem and have made some progress. I can connect to the XBOX controller and set LED commands, but I can’t receive the button/stick positions.

There’s an older topic from last year that got me started in the right direction (thanks to Rabinath’s post):

So I downloaded the USB Host shield drivers from:

And started porting the relevant pieces into the Due’s USB Host library. I’ve attached where I stand so far to this post. The files from WIP_XBOX_LIB_PORT.zip should be pasted into USBHost/src to test it out. If you have a comparison tool like Beyond Compare (or the humble diff), you can compare with the original library to see what I changed. It’s obviously a bit hackish right now, with the whole ‘add to another library’ thing, as well as wholesale replacement of existing debug macros with static serial statements, but functionally it should be untouched.

I’m digging into it to see what is going on. From what I can understand right now, I’m getting NAKs from the controller when I’m requesting data, but I have no idea why or how to fix it (yet). Obviously any assistance from the rest of the community is greatly appreciated.

I’ve also attached my debug sketch which is pretty much the host shield example code right now.

For reference, here’s some of the debug code from the USB Host library and the Xbox driver. If you want to enable debugging in the USB library itself (as opposed to just the Xbox controller portion) you need to uncomment the commented #define TRACE_USBHOST in Usb.h and comment the other one.

Not Connected...
Not Connected...
 + USB_ATTACHED_SUBSTATE_SETTLE
Not Connected...
 + USB_ATTACHED_SUBSTATE_RESET_DEVICE
Not Connected...
 + USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE
Not Connected...
Not Connected...
 + USB_ATTACHED_SUBSTATE_WAIT_SOF
Not Connected...
 + USB_STATE_CONFIGURING

XBOXUSB Init    => ctrlReq
     => SetAddress deviceEP=0 configued as hostPIPE=0 sending to address=0
     => dispatchPkt token=0 pipe=0 nak_limit=65535
    => ctrlData IN
     => dispatchPkt token=256 pipe=0 nak_limit=65535
     => dispatchPkt token=256 pipe=0 nak_limit=65535
     => dispatchPkt token=256 pipe=0 nak_limit=65535
     => dispatchPkt token=512 pipe=0 nak_limit=65535
   => USBHost::setAddr
    => ctrlReq
     => SetAddress deviceEP=0 configued as hostPIPE=0 sending to address=0
     => dispatchPkt token=0 pipe=0 nak_limit=0
     => dispatchPkt token=256 pipe=0 nak_limit=0

Addr: 1    => ctrlReq
     => SetAddress deviceEP=0 configued as hostPIPE=0 sending to address=1
     => dispatchPkt token=0 pipe=0 nak_limit=65535
     => dispatchPkt token=256 pipe=0 nak_limit=65535

Xbox 360 Controller Connected
    => ctrlReq
     => SetAddress deviceEP=0 configued as hostPIPE=0 sending to address=1
     => dispatchPkt token=0 pipe=0 nak_limit=65535
    => ctrlData OUT
     => dispatchPkt token=512 pipe=0 nak_limit=65535
     => dispatchPkt token=256 pipe=0 nak_limit=65535
USBHost::Configuring : found device class!
 + USB_STATE_RUNNING
    => ctrlReq
     => SetAddress deviceEP=0 configued as hostPIPE=0 sending to address=1
     => dispatchPkt token=0 pipe=0 nak_limit=65535
    => ctrlData OUT
     => dispatchPkt token=512 pipe=0 nak_limit=65535
     => dispatchPkt token=256 pipe=0 nak_limit=65535
     => SetAddress deviceEP=1 configued as hostPIPE=0 sending to address=1
     => dispatchPkt token=256 pipe=0 nak_limit=1

Code: 1
Report:
0 0 0 0 0 0 0 0 0 0 0 0 0 0

WIP_XBOX_LIB_PORT.zip (9.16 KB)

XboxTest.zip (898 Bytes)

Okay, so I figured it out. I also ported the general HID files which will allow generic direct input gamepad/joystick/wheel support. Just download the USB shield library and have a look at the corresponding example.

The missing piece was that I needed to call UHD_Pipe_Alloc somewhere after configuring the endpoints. I eventually found this by pouring through the differences in hidboot.h between the two versions of the library.

To use just add the attached files to the USBHost/src folder. If you want to port more pieces of the USB shield library, just compare my versions with the originals to get an idea of what I needed to do.

XBOX_USBHID_LIB_PORT.zip (14.4 KB)

Zerker: Okay, so I figured it out. I also ported the general HID files which will allow generic direct input gamepad/joystick/wheel support. Just download the USB shield library and have a look at the corresponding example.

The missing piece was that I needed to call UHD_Pipe_Alloc somewhere after configuring the endpoints. I eventually found this by pouring through the differences in hidboot.h between the two versions of the library.

To use just add the attached files to the USBHost/src folder. If you want to port more pieces of the USB shield library, just compare my versions with the originals to get an idea of what I needed to do.

Can you please help me connecting my logitech f710 gamepad and how to pair the gamepad with due via native port?