Home > Arduino, TKJ Electronics, USB > Xbox 360 controller support added to the USB Host Library

Xbox 360 controller support added to the USB Host Library

Update
A wireless Xbox 360 controller is now also supported via a Wireless receiver. For more information see the blog post.

Hi everyone. I just wanted to let you know, that I just added support for the Xbox 360 controller via USB to the USB Host Library. The code can as always be found at github: https://github.com/TKJElectronics/USB_Host_Shield_2.0.

Categories: Arduino, TKJ Electronics, USB Tags:
  1. matt whitehouse
    July 25th, 2012 at 04:23 | #1

    wouldn’t wireless work the same as usb, because the receiver is connected via usb and it has a button on it to connect to the controller
    just my two cents

  2. Lauszus
    July 25th, 2012 at 11:35 | #2

    @matt whitehouse
    No it doesn’t – the protocol is slightly different. See this page for more information: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo
    But it wouldn’t be that hard to implement it, as it’s nearly the same.

    Regards
    Lauszus

  3. matt whitehouse
    July 25th, 2012 at 23:32 | #3

    how hard is not that hard??? 🙂

  4. Lauszus
    July 25th, 2012 at 23:35 | #4

    @matt whitehouse
    If I had a wireless xbox receiver and a wireless xbox controller, then only a couple of hours to get everything up and running perfectly.
    The problem is that I don’t own a xbox 360. I just borrowed a friends wired xbox controller for one day, so I could write the library as many people ask if I would do it.
    But I don’t know anybody who got a wireless receiver and I don’t fell like buying one, as I will never use it as I don’t own a controller.

  5. matt whitehouse
    July 25th, 2012 at 23:43 | #5

    is there a portion of your header file that does handsaking if so i cant find it.

  6. Lauszus
    July 25th, 2012 at 23:50 | #6

    @matt whitehouse
    This is the part of the code that initialize the controller: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L38-194 and this is the part that does the actual handshaking: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L139-188

  7. Lauszus
    July 26th, 2012 at 16:45 | #7

    @matt whitehouse
    I have now a wireless receiver coming my way 🙂
    I will create a new post, when I have created the library.

  8. Mike Truitt
    August 13th, 2012 at 19:36 | #8

    Any updates on the wireless Xbox controller librarys?

  9. August 13th, 2012 at 22:16 | #9

    @Mike Truitt
    The receiver hasn’t arrived yet, but I will create the library as soon as it arrives!

  10. Dan F
    August 18th, 2012 at 01:45 | #10

    Currently this only works with official Microsoft usb wired xbox360 controllers (I tested it out). Is there any way that this could be updated to work with non-microsoft brand controllers. 80% of the non-microsoft brand controllers are mad by madcatz (this includes the gamestop and ebgames brand xbox360 controllers) so if the library was updated to work with madcatz brand controllers most off brand xbxo 360 controllers would work. I’d really appriciate it if this could be done.

  11. Dan F
    August 18th, 2012 at 02:03 | #11

    Sorry I stand corrected about the controller only working with official Microsoft controllers. Is there is any way that this could work with madcatz controllers as well. Its not working currently. Your code is pretty awesome by the way. Thanx

  12. August 18th, 2012 at 02:07 | #12

    @Dan F
    I is pretty easy, I only need the VID and PID of the device. What does it print when you plug in the controller?
    It should print “Unknown Device Connected” and then the VID and PID of the device (https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L205-208).

    Please send me the VID and PID and I will make the changes right away!

  13. Dan F
    August 19th, 2012 at 02:52 | #13

    The VID of the madcatz cotroller is 0x1BAD and PID is F016. Thanx for the help. Also I tried your code with a usb hub and when i plug in this hub (http://www.microcenter.com/single_product_results.phtml?product_id=0360458)

    i get the error

    “Unknown Device Connected – VID: 1A40 PID: 0101
    Xbox 360 Init Failed, error code: D1”

    The no buttons are detected

    What do I need to do to get the usb hub to work so that it can detect multiple controllers at a time?

  14. August 19th, 2012 at 23:56 | #14

    @Dan F
    Try to uncomment these lines: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L95-96 and tell me if it works. If it does I will add update the code at github.

    To get hubs working you simply need to add the following to your program: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/hub_demo/hub_demo.pde#L12 – you might need to add more than one, as there can be several hubs chips in one hub.

  15. September 14th, 2012 at 20:07 | #15

    Hi Lauszus, when I upload this sketch, the arduino reports over serial that the library has started. But when I plug in my Xbox 360 controller, nothing happens. If I plug in a bluetooth dongle it says “unknown device” connected.

    What could I be doing wrong? Many thanks.

  16. September 14th, 2012 at 20:14 | #16

    @Blair Kelly
    It might be a power issue. Try to connect a external power supply to the Arduino.
    Also are you using a official or a third-party controller?

  17. Eddy C
    September 14th, 2012 at 20:22 | #17

    Any updates for the wireless controller support?

  18. September 14th, 2012 at 20:28 | #18

    @Eddy C
    I’m starting to think that the receiver has been lost in the mail, since it hasn’t arrived yet, but the seller wilk not refund the money if it has been less than 40 days since shipping. But I will get my money back after those 40 days and then I will order another one at a different seller!

  19. September 14th, 2012 at 20:51 | #19

    @Lauszus
    Hey Lauszus, thanks for the extremely fast reply! I plugged in an external power supply and it worked right away and perfectly (rumbling, leds, everything). However, I get an intermittent problem: “OSC did not start.” I noticed a post somewhere that said the sparkfun shield does not work with this library, and that’s the shield I’m using. Will the full-sized board and mini variant from circuits at home do the trick? (shown here: http://www.circuitsathome.com/arduino_usb_host_shield_projects) Best regards,

    Blair

  20. September 14th, 2012 at 21:03 | #20

    @Blair Kelly
    The problem with the Sparkfun shield is that it has a external 5V regulator on the shield connected to VIN, so you need to power the Arduino from more than 5V, so you can’t not power it from USB if the device need a voltage level close to 5V. You could either modify the shield, so it get’s power directly from the Arduino’s 5V pin, or you could connect the Arduino to a external powersupply.

    See the schematic for more details: http://www.sparkfun.com/datasheets/DevTools/Arduino/USBHostShield-v13.pdf.
    You can compare it with the official shield: http://www.circuitsathome.com/wp/wp-content/uploads/2011/02/UHS_20.pdf.

    Furthermore the library doesn’t use the GPX pin from the MAX3421E, so you can actually just bend pin 8 on the shield so you can use pin 8 for other purposes. Also since the reset pin is connected to the Arduino reset pin on the official shield, you also got another pin there.

    You CAN use the Sparkfun shield, but I will always recommend the official shield, so you support the development and then you can also use the shield with other Arduinos than the Uno, Duemilanove etc. like the Leonardo, Mega etc. Also it is much easier to reroute the pins as the official one got solder jumpers.

  21. September 17th, 2012 at 00:46 | #21

    @Lauszus
    Thanks Lauszus for all the excellent information. I will be ordering some of the official boards and attempting to modify my sparkfun shield. Regarding the official boards, specifically the mini-variant: can it be used with the 5-volt arduino pro mini?

    Best regards, Blair.

  22. September 17th, 2012 at 00:53 | #22

    @Blair Kelly
    Your welcome.
    The mini-variant can only be used with the 3.3V version, as there is no logic converters on the shield.

  23. September 17th, 2012 at 22:19 | #23

    @Lauszus
    Will the 3.3 volt arduino with the mini-variant push the Xbox360 controller with all proper functionality, like rumbling?

  24. September 17th, 2012 at 23:27 | #24

    @Blair Kelly
    I can’t say for sure. You might need to connect 5V to VBUS on the mini-variant. It’s pretty easy – you only need to cut the solder jumper and then solder a wire from the small hole to a 5V source. See the following page: http://www.circuitsathome.com/usb-host-shield-hardware-manual at the “4. Power options” section.

  25. Mark D
    September 30th, 2012 at 21:11 | #25

    Will the USB host library run on the built in USB host in the Mega ADK? I tried the Xbox 360 controller on my Mega ADK using the Xbox 360 controller example sketch and got the error message “OSC did not start” and the controller is not working.

  26. September 30th, 2012 at 21:34 | #26

    @Mark D
    Yes it will. But it’s a feature that has to be enabled.
    You should uncomment the following line in the avrpins.h file of the library (line 25):

    #define BOARD_MEGA_ADK
  27. Mark D
    October 3rd, 2012 at 02:40 | #27

    @Thomas Jespersen
    Thomas thanks for your reply, that seems to have done the trick however I am using a MadCatz wired controller and it has a different VID and PID than the XBOX controller. Currently the controller is not recognized and I get a D1 error code.

    The VID is 1BAD and the PID is F016, what do I need to change to get the madcatz controller to work?

  28. Mark D
    October 3rd, 2012 at 02:58 | #28

    @Mark D
    Never mind, I figured it out, just needed to change the VID from the XBox one to the madcatz VID in the XBOXUSB.h library file. Everything works now.

  29. October 3rd, 2012 at 20:21 | #29

    @Mark D
    Thanks for your feedback.
    I have just added support for the Mad Catz controllers to the github: https://github.com/felis/USB_Host_Shield_2.0/commit/80e689a8b82c9458234facd8386bd146fe4e06f1. Please confirm it’s working 🙂

  30. Mark D
    October 5th, 2012 at 12:54 | #30

    @Lauszus

    Lauszus,

    Confirming your new code works with the Madcatz controller, thanks.

    Mark D

  31. October 5th, 2012 at 13:40 | #31

    @Mark D
    Thanks 🙂

  32. Gian Reale
    October 17th, 2012 at 03:42 | #32

    Do you need the wireless receiver to run the usb_desc??? Cuz i did that but really dont know what to do… xD

  33. October 17th, 2012 at 10:56 | #33

    @Gian Reale
    What do you mean? Are you talking about this example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.pde?
    It has nothing to do with Xbox what so ever. It’s only a sketch to test if the shield is working properly or not.

  34. Gian Reale
    October 17th, 2012 at 22:21 | #34

    hmmm, im sorry i though that would be usefull, actually im really new to this. I want to learn how to use the wireless receiver to comunnicate to xbox controller and then control dc motors, but i really dont know how to do this. I was diging out on many articles from circuits@home, but now i see that im not in the right way… xD

  35. October 17th, 2012 at 22:45 | #35

    @Gian Reale
    Okay 🙂 I will make the library someday. Before December I hope…

  36. Tim
    October 19th, 2012 at 07:51 | #36

    Hi, I was wondering if you could help me the setup the Arduino for using the github code.

    I’m fairly new to Arduinos and I’ve added the libraries Usb and XBOXUSB to the Arduino directory, but when I verify the xbox360 example code I get an error ‘class USB’ has no member named ‘Init’

    I’m not exactly sure if I’ve set up the libraries correctly or if I’m just missing something.
    Thanks

  37. October 19th, 2012 at 12:06 | #37

    @Tim
    Okay I will write the steps for you:

    1. In your Arduino sketch folder create a folder name “libraries” (see this link for more information: http://www.arduino.cc/en/Hacking/Libraries)
    2. Download the source code from Github: https://github.com/felis/USB_Host_Shield_2.0 by pressing the button labeled “ZIP”.
    3. Rename the folder to something like “USB_Host_Shield_20”, as the Arduino IDE doesn’t support dashes ‘-‘, dots ‘.’ etc.
    4. Move “USB_Host_Shield_20” into the library folder.
    5. Now open up the Arduino IDE and then go to File>Examples>USB_Host_Shield_20>XBOX360USB

    Hope that helps you out, if not just let me know and I will try my best to help you 🙂

  38. Tim
    October 20th, 2012 at 00:02 | #38

    @Lauszus
    Ahh thanks, it seems that my libraries were completely wrong 😛

    But now im getting this error: avrdude: stk500_getsync(): not in sync: resp=0x00
    I have my xbox360 controller plugged in when im uploading the XBOX360USB to my Arduino r3, have any idea what I’m doing wrong?

  39. October 20th, 2012 at 00:04 | #39

    @Tim
    That usually means that the Arduino is not responding, try a different USB port.

    It doesn’t matter if the Xbox360 is plugged in while you program the Arduino.

  40. Tim
    October 20th, 2012 at 00:13 | #40

    @Tim

    Don’t mind that post, I fixed it! I didn’t select the right COM port and had to unplug and re-plug my Arduino.

    Everything is working flawlessly, thanks!

  41. October 20th, 2012 at 00:14 | #41

    @Tim
    Okay good 🙂

  42. Tim
    October 20th, 2012 at 17:32 | #42

    @Lauszus
    Hey it’s me again,
    I’m working on a project with servos and was wondering how difficult it’d be to code the example so that the xbox joysticks control different servos.
    I was looking at the serial monitor while moving the joysticks and it scares me a bit about translating them into the bounds of a servo..

  43. October 21st, 2012 at 12:30 | #43

    @Tim
    It’s pretty easy, just used the map function: http://arduino.cc/en/Reference/Map and then just use the servo library: http://arduino.cc/en/Reference/Servo

  44. Tim
    October 22nd, 2012 at 03:15 | #44

    Awesome, I didn’t even know about that function, thanks!

  45. Jesse
    November 19th, 2012 at 12:06 | #45

    @Lauszus
    Hey, did you ever get the library working with wireless controller? If not, can you please help guide me in developing this, as I need it for a time-sensitive project. I have looked through the source code, there a couple of things I am unsure of.

    1) What is the purpose of XBOX_CONTROL_PIPE and why do you send data to this endpoint instead of XBOX_OUTPUT_PIPE.. what is the difference?

    2) Using USBLyzer with the wireless receiver it seems the first controller has an in endpoint 0x81 and out endpoint 0x01. Are these the endpoint addresses that I need to define for epInfo[ XBOX_INPUT_PIPE ].epAddr and epInfo[ XBOX_OUTPUT_PIPE].epAddr respectively?

    Thanks in advance for your help

    Jesse

  46. November 19th, 2012 at 17:46 | #46

    @Jesse
    No, the first one I bought never arrived, but I got my money back.
    So now I’m waiting for a new one to arrive.

    1.
    The reason I use control pipe, is because it’s requeired. Some devices use the control pipe for output data while others use the output pipe.
    For instance the PS3 controller and the Navigation controller also use the control pipe: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3USB.cpp#L419 while the Move controller use the output pipe: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3USB.cpp#L501.

    I’m not sure why hardware manufactures sometimes prefer one of them over the other.

    2.
    You can find all the information regarding the endpoints, protocol etc as these two links:
    http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo and https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L356.

    Best Regards
    Kristian Lauszus

  47. Kevin
    November 26th, 2012 at 06:00 | #47

    Hi I’m using the usb shield and arduino to use the xbox controller and everything works fine. But whenever I add in a screw shield in between, the controller just flashes and we get the error “OSC did not start”.
    This is the screw shield in question
    http://imall.iteadstudio.com/im120417013.html

    do you know whether or not we’d be able to use the screw shield, and make it work, or will we have to remove it from the chain completely?

  48. November 27th, 2012 at 12:39 | #48

    @Kevin
    Have you connected anything to pin 9, 10, 11, 12 or 13?
    All of these are used by the USB Host Shield on an Arduino Uno or similar.

  49. January 15th, 2013 at 08:58 | #49

    Hi Kristian, I’ve been playing with the circuits@home usb shield with the xbox360 controller connected. The circuits@home usb shield is mounted on an arduino mega 2560 with your library included and running the XBOX360USB example sketch.

    When I pull buttons L2 and R2, the controller vibrates; the intensity corresponds to how much the buttons are depressed. There are no errors. Not even if I pull and release the buttons very rapidly.

    I made a few modifications to the code and started sending data over xbee into the mega2560 through it’s first auxiliary serial port, (Serial1). The data is sent from an accelerometer attached to arduino uno. I use Xbox.setRumbleOn and the values I pass this function are always between 0 and 255. As I shake the accelerometer and data reaches the 2560 as I can see through the Serial monitor, I have observed that most of the time there’s a delay where the controller does nothing, and then a message will appear:

    “Xbox 360 Controller Connected”

    after that, the controller starts to vibrate. As I continue to shake the accelerometer, this message might appear many times. If in the same sketch I leave the code from your example that allows me to vibrate the controller using buttons L2 and R2, that functionality still works flawlessly – no appearance of “Xbox 360 Controller Connected”

    Is there anything obvious you can think of that might be causing this error? I’m a bit stumped.

    Best regards

    Blair

  50. January 15th, 2013 at 10:30 | #50

    @Blair Kelly
    Do you remember to run “Usb.Task();” once in a while, like so: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXUSB/XBOXUSB.ino#L21?

    If you don’t then it will never poll the input pipe: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L233 causing it to disconnect and then reconnect.

    Try to post your code somewhere (something like gist: https://gist.github.com/) and send me the link then I will have a look.

  51. January 16th, 2013 at 02:07 | #51

    @Lauszus
    Thanks Lauszus. Usb.Task(); gets run every time the loop starts. Actually, the loop starts and I run a function called serialListen (it listens for data comin in on the serial port, like acceleration info coming from the adxl from another UNO, via xbee). If an instruction comes in to rumble the controller, then scancontroller fires the delegate() function which will then fire the rumble. Then I run scancontroller(), a function that has at the top of it Usb.Task(); scancontroller checks the values of some of the sticks and buttons.

    My code is very rough and is on github. I just started this project, I hope you don’t mind too much a thicket of code.

    It can be seen here: https://github.com/blairkelly/stackedcontrol/blob/master/stackedcontrol.ino

    I was thinking I might try this with the ps3 controller later. See if it makes any difference.

    P.s. That sketch will also turn on and off rumble if you push the Xbox button. I have found this will also cause the problem of controller reset.

  52. January 16th, 2013 at 15:16 | #52

    @Blair Kelly
    I think I found your problem. You are calling this: https://github.com/blairkelly/stackedcontrol/blob/master/stackedcontrol.ino#L113 without checking if the Xbox controller is actually connected.

    Also try to add a 1ms delay in your loop: https://github.com/blairkelly/stackedcontrol/blob/master/stackedcontrol.ino#L312.

    Try to run Usb.Task() before you run serialListen(), as you are actually sending a command to the controller before you have run Usb.Task, as you execute scancontroller() after serialListen().

    I found that it’s never a good idea to send multiple commands to the controller without calling Usb.Task in between. The problem is that you are not polling the input endpoint at the same rate as you are sending data.

  53. January 16th, 2013 at 16:42 | #53

    @Lauszus
    I am astonished at how much you help everyone out. Thank you very much for taking the time to analyse my code. I will try your suggestions this evening and let you know how I make out.

  54. January 17th, 2013 at 06:59 | #54

    @Lauszus
    I’m a bit embarrassed to say I was starting to run out of ideas when I just happened to plug in an external power source to the Arduino Mega 2560. It started working properly. I had ruled-out that possibility because it was working just fine with your example sketch. Perhaps the adequate power supply keeps the processes and communications from tripping up. Anyway, I thank you again for the time and effort you put into this and I’m sorry it was such a silly little thing I should not have overlooked!

  55. January 17th, 2013 at 18:24 | #55

    @Blair Kelly
    No problem 🙂 Don’t hesitate to contact me again!

  56. Jerry
    April 14th, 2013 at 21:14 | #56

    Hi Lauszus,

    Thanks for all of the work you’ve put in getting the game controllers working with the USB Host Shield.

    I’ve been assigning the button presses to the digital I/O pins, and using the output to a relay board. Everything was working fine until I tried using the non-analog buttons. The comments in the XBOXRECV.h file starting at line 108 is a bit confusing and I’m not sure if what I’m trying to do is even possible.

    Whenever I try to getButtonPress for a non-analog button (L1, L2, X, Y, A, B), I get no outputs. getButtonClick works obviously, but I’d like for a constant output while the button is pressed down. Is this possible with these types of button?

    To clarify, I’ve been using an if/else function with digitalWrite to output low if the getButtonPress is true, else output high if the getButtonPress is false….using your example as a starting point. I’m new to all of this (you addind support for these controllers is really what brought me to the arduino), so if theres a better way of doing it, I’d appreciate it.

    Thanks!

  57. April 15th, 2013 at 17:38 | #57

    @Jerry
    It was caused by a bug in the getButtonPress in the function, but has now been fixed: https://github.com/felis/USB_Host_Shield_2.0/commit/78cb524bcf8e78b65205b0c2d80f73748a998712.
    Thanks for your feedback!

  58. Jerry
    April 15th, 2013 at 18:38 | #58

    @Lauszus

    Awesome! Thank you so much! Everything works perfectly now.

    So it was just an addition of a bool command? I admit I tried troubleshooting it myself before I posted, but the .cpp file is well beyond my comprehension at the moment. Thanks again!

  59. April 15th, 2013 at 18:40 | #59

    @Jerry
    Yes I only added a bool cast. The problem was that it’s was trying to return a uint32_t, but the function is only a uint8_t type, so the top 24 bits where actually thrown away.

  60. November 27th, 2013 at 09:20 | #60

    Hi, great job and thanks. We are using your library for controlling our robots ! We discovered two problems :
    – objects USB , XBOXUSB and XBOXRECV must be declared in global in the main file, otherwise, the usb.task reset the arduino.
    – the first time a button is pressed, it is not detected.

    Any idea or help ?

  61. November 27th, 2013 at 16:13 | #61

    @Sinclair
    Hmm that sounds strange. Are you checking if Usb is not null before calling Usb.Task()?

    Can you post your code somewhere, then I will have a look.

  62. Christoph
    April 9th, 2014 at 00:02 | #62

    Hi Kristian,

    thanks for your library and your hard work. It’s really great. Is it possible to use multiple wired xbox360 controllers if i connect them via an usb hub? Naively I would expect this works if I create multiple XBOXUSB objects. If this is not possible right now, could you give me a hint, how i could make this work?

  63. April 9th, 2014 at 00:06 | #63

    @Christoph
    Yes. Simply include the hub library and create the instance like so:

    #include <usbhub.h>

    USBHub Hub1(&Usb);

    After that just go crazy with those XBOXUSB instances 😉

    But please be aware that there might be several hub chips inside a usb hub, so if you need to connect a lot of devices you properly have to create another hub instance:

    USBHub Hub2(&Usb);
  64. taylor
    February 24th, 2015 at 15:36 | #64

    hi i am trying to make a rov submersible and i need help. I want to control it with a wired xbox controller but i have’int found any code that has output all i can find is code that uses a docgen but i would like to be able output pins on the arduino.

    can some one help?

  65. February 24th, 2015 at 19:32 | #65

    @taylor
    Have you seen the examples: https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/Xbox? You can just use digitalWrite to set a specific pin if a button is pressed etc.

  66. Ben
    June 10th, 2015 at 04:23 | #66

    I’m trying to use a Madkatz 4716 XBox 360 controller with the XBOXUSB example that comes with the USB Host library 2.0. The sketch uploads fine but it’s not detecting the controller (I get “XBOX USB Library Started” but nothing further in the terminal). I ran USB_Desc and saw that the PID (4716) and VID (0738) do not match the ones that correspond to Madcatz in XBOXUSB.h/XBOXUSB.cpp. Is it ok to try subbing those values into my copy of the library? This seems like the reason it’s not detecting. Thoughts?

  67. June 10th, 2015 at 09:26 | #67

    @Ben
    Yes you can just add the VID here: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.h, but please tell me if it works, so I can add it to the official repository.

  68. June 10th, 2015 at 09:26 | #68

    @Ben
    Btw you can enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging, so you can see what is going on.

  69. Ben
    June 10th, 2015 at 16:00 | #69

    @Kristian Lauszus
    I added the VID and PID to XBOXUSB.h and XBOXUSB.cpp and now, with debug enabled, I get these messages:

    XBOX USB Library Started
    XBOXUSB Init
    Addr: 01
    Xbox 360 Controller Connected

    However, at this point, it does not respond to pressing the controls. I also tried calling Xbox.setLedOn(LED1) to no effect.

  70. Ben
    June 10th, 2015 at 18:37 | #70

    This is so strange – I fiddled with various files but then ended up back where I started, programmed, and all of a sudden it was working. Then reprogrammed the exact same thing and it stopped working. As far as I know nothing got changed except the VID/PID stuff. Very frustrating.

    In other news, I acquired a wireless controller with a USB adapter which is also not able to be detected (the PID gets rejected as a wireless controller, and if I change the code not to reject it, it still doesn’t show what the buttons are doing).

  71. June 10th, 2015 at 21:48 | #71

    @Ben
    I am not sure what you might have done wrong, but please test the following pull request: https://github.com/felis/USB_Host_Shield_2.0/pull/157 and tell me if it works or not.

    If you post the VID and PID of the wireless receiver I will add support for that as well.

  72. Ben
    June 11th, 2015 at 22:14 | #72

    After looking at your pull request, It’s doing the same thing I was doing (creating a new VID/PID and modifying the checks in the two library files to allow those identifiers). As before, I get this:

    XBOX USB Library Started
    XBOXUSB Init
    Addr: 01
    Xbox 360 Controller Connected

    There must be some more subtle difference in this Madcatz controller, no?

  73. June 12th, 2015 at 01:37 | #73

    @Ben
    So basically nothing happens when you press any of the buttons. Please try to uncomment the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXUSB.cpp#L21 and tell me if the bytes printed change when you press any button, move the joysticks etc.

  74. Ben
    June 12th, 2015 at 14:58 | #74

    @Kristian Lauszus

    I should have mentioned that I tried this. I retried just because, and both times I got nothing but 00 00 00 00…….etc

  75. June 13th, 2015 at 19:57 | #75

    @Ben
    Could you try to the following example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.ino and post the output?

  76. Ben
    June 15th, 2015 at 20:32 | #76

    @Kristian Lauszus

    Here’s the output for the Madkatz controller:
    http://codeshare.io/cYMHz

    Here’s the same for the wireless Microsoft controller with the USB adapter:
    http://codeshare.io/A2oqH

  77. June 16th, 2015 at 16:46 | #77

    @Ben
    The Mad Catz controller report looks fine. The only thing I can come up with is that you could try to add a 10 ms delay in your loop i.e.:

    delay(10);

    Note that you can not use a wireless controller via USB. This is a hardware limitation and is nothing we can do about it. The usb cable for the wireless controller is only used for charging. That is why the report: http://codeshare.io/A2oqH shows no endpoints.

  78. Ben
    July 8th, 2015 at 21:41 | #78

    You may recall we talked about that Madkatz controller – I ended up just buying a wired Microsoft XBox 360 controller which has worked (more or less) fine.

    I have code written to scale a pair of PWM outputs (proportional valves for a bi-directional hydraulic cylinder) based on the left hat x-axis. It works, basically, but for some reason, after working correctly for a short time it locks up and holds the PWM value at the time of lockup indefinitely. Can you see anything in the code that might cause this?

    #include <XBOXUSB.h>

    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include <spi4teensy3.h>
    #include <SPI.h>
    #endif

    USB Usb;
    XBOXUSB Xbox(&Usb);
    int16_t LeftHatXPrev, LeftHatYPrev, RightHatXPrev, RightHatYPrev;
    int16_t LeftHatXCurr, LeftHatYCurr, RightHatXCurr, RightHatYCurr;
    int16_t AnalogHatZeroThresh;
    int16_t AnalogHatMoveThresh;

    void setup() {
      AnalogHatMoveThresh = 1000;
      AnalogHatZeroThresh = 5500;
      LeftHatXPrev = 0;
      LeftHatXCurr = 0;
      pinMode(13,OUTPUT);
      pinMode(12,OUTPUT);
      Serial.begin(115200);
    #if !defined(__MIPSEL__)
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    #endif
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnXBOX USB Library Started"));
    }

    void loop() {
      Usb.Task();
      if (Xbox.Xbox360Connected)
      {
        // **Left Hat X**
        // Make sure stick has moved AnalogHatMoveThresh before changing output

        LeftHatXCurr = Xbox.getAnalogHat(LeftHatX);
        if(((LeftHatXCurr > LeftHatXPrev) && (LeftHatXCurr - LeftHatXPrev > AnalogHatMoveThresh)) || ((LeftHatXCurr < LeftHatXPrev) && (LeftHatXPrev - LeftHatXCurr > AnalogHatMoveThresh)))
        {
          if(LeftHatXCurr > AnalogHatZeroThresh)
          {
            // Extend Secondary Arm
            analogWrite(5, floor((float)LeftHatXCurr/32768*255));
            analogWrite(4, 0);
          }
          else if (LeftHatXCurr < -AnalogHatZeroThresh)
          {
            // Retract Secondary Arm
            analogWrite(5, 0);
            analogWrite(4, floor((float)(-LeftHatXCurr)/32768*255));
          }
          else
          {
            analogWrite(5,0);
            analogWrite(4,0);
          }

          LeftHatXPrev = LeftHatXCurr;
        }
      }
      else
      {
        Serial.print("nNot connected");
      }
      delay(100);
    }
  79. Ben
    July 8th, 2015 at 21:43 | #79

    @Ben

    I forgot to mention that serial with debug and extra debug enabled does not yield anything useful. Reprogramming or resetting the arduino (a Mega 2560) “fixes” the problem. I’m currently driving LEDs, but when I had serial prints showing what I was writing and what values I was reading from the controller, it behaved in an equivalent way, freezing after a time.

  80. Ben
    July 10th, 2015 at 16:18 | #80

    @Ben

    A further update: the freezing eventually goes away most of the time. Based on my own fiddling with debug print statements I know that the program continues running and that the USB data is not getting updated.

  81. Ben
    July 10th, 2015 at 17:58 | #81

    @Kristian Lauszus if you see this, please ignore – I opened an issue on the github repo here: https://github.com/felis/USB_Host_Shield_2.0/issues/166

  82. July 11th, 2015 at 11:10 | #82

    @Ben
    I have responded at the Github issue: https://github.com/felis/USB_Host_Shield_2.0/issues/166.

  83. Akash Kalghatgi
    September 26th, 2015 at 07:29 | #83

    I’m trying to provide a vibration feedback to the rumbles, via the xbox controller, someone please help me code it into Arduino.
    I’ve already included XBOXRECV.h library and tried using the c# keyword “void SetVibration (PlayerIndex playerIndex, float leftMotor, float rightMotor )” and then used “Gamepad.SetVibration(PlayerIndex.One, 0.xf, 0.yf);” into loops, only to get the errors as follows:
    Arduino: 1.6.0 (Windows 8), Board: “Arduino Uno”

    xbox_code.ino:16:20: error: variable or field ‘SetVibration’ declared void
    xbox_code.ino:16:20: error: ‘PlayerIndex’ was not declared in this scope
    xbox_code.ino:16:45: error: expected primary-expression before ‘float’
    xbox_code.ino:16:62: error: expected primary-expression before ‘float’
    xbox_code.ino:49:20: error: variable or field ‘SetVibration’ declared void
    xbox_code.ino:49:20: error: ‘PlayerIndex’ was not declared in this scope
    xbox_code.ino:49:45: error: expected primary-expression before ‘float’
    xbox_code.ino:49:62: error: expected primary-expression before ‘float’
    Error compiling.

    This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.

    please help me asap!!!

  84. Akul
    May 14th, 2016 at 20:53 | #84

    how to connect xbox controller to reciever?

  85. Can Ivit
    October 8th, 2016 at 08:38 | #86

    Hi, I am trying to use usb host library with my arduino mega adk. I uploaded the xBoxUSB example to arduino board and plugged my xbox 360 controller to the usb port of my arduino mega adk. Problem is, there are weird symbols instead of normal letters in serial monitor. Any help?

  86. October 8th, 2016 at 09:37 | #87

    @Can Ivit
    Sounds like the baud rate of your serial terminal is not set correctly.
    Please see if it helps setting the baud rate to 115200?

  87. Kim Dae Woo
    March 25th, 2017 at 17:14 | #88

    HI,
    I am currently working on xobxusbhost2.0 + atmeag 2560 + Logitech Gamepad F310 (xbox 360).

    There was no problem until we run “usbdesc” program first.

    But there was a problem. Running “xobusb” will cause “Problem! DispatchPkt” error in usb.cpp.

    It will not proceed. What is the problem?

  1. December 12th, 2012 at 19:02 | #1