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

Xbox 360 receiver added to the USB Host Library

December 29th, 2012 Leave a comment Go to comments

You asked for it and here it is.
I finally got the time to implement support for Wireless Xbox 360 controllers to the USB Host Library. This is done via a Xbox 360 Wireless receiver that is normally intended for Windows computers.

The source code can be found at github: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp
There is an example as well: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXRECV/XBOXRECV.ino.

The receiver supports up to four controllers internally, so it was fairly easy to implement it.

Actually I havn’t tested the library with more than one controller, but if somebody out there could confirm if it’s working or not, with more than one controller, I would really appreciate it!
Thanks to Tim, multiple controllers is now confirmed to work!

If you need to use more than four controllers you will need to connect a second receiver via a USB hub which is also supported by the library.
Simply add the following to the start of your Arduino sketch:

USBHub  Hub1(&Usb);
USBHub  Hub2(&Usb);

Note that you might need to add more instances depending on how many chips there is inside your USB hub.

You will also need to create another instance of the XBOXRECV class like so:

USB Usb;
XBOXRECV Xbox1(&Usb);
XBOXRECV Xbox2(&Usb);

For more information regarding the protocol see the following pages: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo and https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL.

Categories: Arduino, TKJ Electronics, USB Tags:
  1. Tim
    January 2nd, 2013 at 21:13 | #1

    Thanks for the nice work putting this library together – it works perfectly with one controller, but when I add a second one I get serial output corruption and hanging.

    Happy to help diagnose the problem where I can, but I don’t have an official Xbox usb receiver, and I am using the Sparkfun USB shield – so someone with official versions might have more luck.
    I tried using both controllers attached to my PC and it works fine, so it does ordinarily cope with it.

  2. January 2nd, 2013 at 21:15 | #2

    @Tim
    First of all thanks for your feedback. Could you please uncomment EXTRADEBUG (https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L20) and send me the serial output? Then I will see if I can’t spot the problem.
    I don’t think the fact that you are using the Sparkfun shield is a problem, as you can use it with one controller. Please also connect a external powersupply to your Arduino as it might be power related (see this reply: http://blog.tkjelectronics.dk/2012/07/xbox-360-controller-support-added-to-the-usb-host-library/#comment-59256).

  3. Tim
    January 2nd, 2013 at 21:35 | #3

    Here’s the output:

    Xbox Wireless Receiver Library Started
    XBOXRECV Init
    Addr: 01
    Xbox Wireless Receiver Connected
    Bytes Received: 29
    A
    Bytes Received: 29
    Bytes Received: 29
    Bytes Received: 29
    Bytes Received: 29
    B
    Bytes Received: 29
    Bytes Received: 29
    Bytes Received: 29


    the A and B output are correctly showing when I pressed A and B buttons.
    So After the last line is where I turned on the second controller – which subsequently causes everything to freeze. The first controller becomes unresponsive and the LEDs stay in the same state, and the second controller just flashes away as if it is unable to connect.

    Any ideas?

  4. January 2nd, 2013 at 21:37 | #4

    @Tim
    Hmm, could you uncomment this line too: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L21 and then the output again?

  5. Tim
    January 2nd, 2013 at 21:39 | #5

    Xbox Wireless Receiver Library Started
    XBOXRECV Init
    Addr: 01
    Xbox Wireless Receiver Connected
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 10 00 00 37 00 F3 04 57 F2 C5 FF 00 00 00 00 00 00 00 00 00 00 00
    A
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 37 00 F3 04 57 F2 C5 FF 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 20 00 00 37 00 F3 04 57 F2 C5 FF 00 00 00 00 00 00 00 00 00 00 00
    B
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 37 00 F3 04 57 F2 C5 FF 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


    same actions as before

  6. Tim
    January 2nd, 2013 at 21:44 | #6

    I did perform a USB_Desc info dump on the wireless controller, it’s a bit long though, should I post it or email it to you?

  7. January 2nd, 2013 at 21:45 | #7

    @Tim
    What I think is weird is that you never receive the 0x08 report: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L302-L326
    You can just send it to my email: kristianl@tkjelectronics.dk

  8. January 2nd, 2013 at 21:50 | #8

    @Tim
    Thanks for your email. I will have to investigate this further. I might have to borrow a second controller…
    Could use perhaps try to increase this delay: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXRECV/XBOXRECV.ino#L109 to 10?

  9. Tim
    January 2nd, 2013 at 21:52 | #9

    This is what I get when I start the feed with no controllers switched on, and then turn them on after the line “Xbox Wireless Receiver Connected” is received:

    Xbox Wireless Receiver Library Started
    XBOXRECV Init
    Addr: 01
    Xbox Wireless Receiver Connected
    Bytes Received: 2
    Controller 0: connected
    Controller 0: 08 80
    Bytes Received: 29
    Controller 0: 00 0F 00 F0 F0 CC 42 AF 3C 60 AC 24 FB 50 00 05 13 E7 20 1D 30 03 40 01 50 01 FF FF FF
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 81 F0 C9 FF CA FF FD 13 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 20 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 40 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 F8 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 81 F0 C9 FF CA FF 9C 12 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 13 A2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 13 A2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


    I wonder if the message is being missed or dropped somewhere?

  10. January 2nd, 2013 at 21:55 | #10

    @Tim
    Try to remove this check: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L284 and this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L358 from nBytes to EP_MAXPKTSIZE.
    This should make it print the output it receives no matter if there are any errors.

  11. Tim
    January 2nd, 2013 at 21:56 | #11

    > Could use perhaps try to increase this delay:
    I tried increasing the delay to 10, and then removing the delay entirely, same results.

  12. Tim
    January 2nd, 2013 at 22:04 | #12

    So, there’s a lot more output this time! It still freezes when I turn the second controller on, I’ve truncated the repeated parts:
    (the first line appears to be random junk, not sure if this is just the Serial connection starting up)

    “µé`/”Ã?ÿ
    Xbox Wireless Receiver Library Started
    XBOXRECV Init
    Addr: 01
    Xbox Wireless Receiver Connected
    Bytes Received: 0
    Controller 0:
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 0
    Controller 0:
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:

    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 2
    Controller 0: connected
    Controller 0: 08 80
    Bytes Received: 0
    Controller 1: connected
    Controller 1:
    Bytes Received: 0
    Controller 2: connected
    Controller 2:
    Bytes Received: 0
    Controller 3: connected
    Controller 3:
    Bytes Received: 29
    Controller 0: 00 0F 00 F0 F0 CC 42 AF 3C 60 AC 24 FB 50 00 05 13 A7 20 1D 30 03 40 01 50 01 FF FF FF
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 29
    Controller 0: 00 00 00 20 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0

    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 29
    Controller 0: 00 00 00 13 A2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:

    (Then I switched on the second controller)

    Bytes Received: 0
    Controller 2:
    Bytes Received: 0
    Controller 3:
    Bytes Received: 0
    Controller 0:
    Bytes Received: 0
    Controller 1:
    Bytes Received: 0
    Controller 2:
    Bytes Re


    and it’s frozen.

  13. January 2nd, 2013 at 22:19 | #13

    @Tim
    I can’t see what’s wrong. I will get another controller and see if I can fix it! I really appreciate your feedback.
    Do you got a Wired Xbox controller as well, could you perhaps test something for me?

  14. Tim
    January 2nd, 2013 at 22:24 | #14

    I don’t have a wired one, sorry.

    I did just get something interesting though – by adding a delay(10) at line 289, I can delay the process long enough for the Serial to print its buffer before it freezes, and I actually get a couple of packets from controller 2.
    If i leave the controllers alone, it freezes instantly – but if i bash button A on Controller1, then press B on Controller2, I sometimes get a brief message from Controller2 before it freezes:

    Xbox Wireless Receiver Library Started
    XBOXRECV Init
    Addr: 01
    Xbox Wireless Receiver Connected
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 10 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    A
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 10 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    A
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 10 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 1: 00 01 00 F0 00 13 00 20 00 00 1E FF F7 10 DE 05 F6 03 00 00 00 00 00 00 00 00 00 00 00
    A
    B
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 1: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 01 00 F0 00 13 00 00 00 00 E9 01 F6 07 D9 FC 48 05 00 00 00 00 00 00 00 00 00 00 00
    Bytes Received: 29
    Controller 0: 00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

  15. January 2nd, 2013 at 22:39 | #15

    @Tim
    Thanks once again. I just realized that I forgot a delay(1) here: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L282 as you can’t poll the endpoints that fast.
    I just pushed it to github: https://github.com/felis/USB_Host_Shield_2.0/commit/4fa973d441aae1dc8558c2274b7c5c688b929875

  16. Tim
    January 2nd, 2013 at 22:44 | #16

    Ok, so I added that, and it didn’t really affect it – so I changed it to delay(10) and it’s better, I got about 3 seconds of 2 working controllers, but then it still freezes.

  17. Tim
    January 2nd, 2013 at 22:57 | #18

    nope, nothing works if I change those.
    Instead I tried changing #L167 to 0x81, but it still breaks – with the added bonus of occasional “Error sending Xbox message” messages.

  18. January 2nd, 2013 at 23:01 | #19

    @Tim
    Okay. I just wanted to make sure that I did not have done something stupid.
    I will look more into this is the coming days. I will let you know when I got it working.
    Just one more thing. Do you have a external powersupply connected to the Arduino?

  19. January 2nd, 2013 at 23:04 | #20

    @Tim
    Could you try this on a Mega as well, it might be because you are running out of memory!

  20. Tim
    January 2nd, 2013 at 23:13 | #21

    I have external power connected.
    I don’t have a mega – the only chips I have at the moment are 168’s – I hope to have a 328 in a few days.

  21. January 2nd, 2013 at 23:28 | #22

    @Tim
    That’s properly the problem. You are likely running out of ram.
    Try to include the MemoryFree library: https://github.com/sudar/MemoryFree and tell the output of available ram when you run the sketch.
    There is more information here: http://playground.arduino.cc/Code/AvailableMemory

  22. January 2nd, 2013 at 23:49 | #23

    @Tim
    I did it myself. It’s using 816 of ram at startup, so you are most likely running out of ram.

  23. Tim
    January 3rd, 2013 at 18:52 | #24

    So my Arduino 328 Uno arrived and I’ve plumbed it in, but I get the same problem – one controller is fine, two kills it.

    I had another look at the specs sheet and the Uno has 2Kb of SRAM versus the 1Kb in the Diecimila which I was using before.

    Freemem is reported at a constant 1312 bytes, from boot to crash.

  24. Tim
    January 3rd, 2013 at 19:32 | #25

    I’ve traced the hang down to a function in usbhost.h, line 101:
    void MAX3421e::regWr( uint8_t reg, uint8_t data )


    not sure where to go next.

  25. Tim
    January 3rd, 2013 at 19:59 | #26

    Ok, ignore the previous comment – the program is stopping because an assert is failing at (approx) line 252 in Usb.cpp:
    assert(pktsize <= nbytes);
    because nbytes is zero.

  26. Tim
    January 3rd, 2013 at 20:09 | #27

    Fixed it 🙂

    Changed in XBOXRECV.cpp (approx) line 267:
    if (!bPollEnable)
    return 0;
    uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
    for(uint8_t i=0;i<4;i++) {

    –to–
    if (!bPollEnable)
    return 0;
    for(uint8_t i=0;i<4;i++) {
    uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;

  27. January 3rd, 2013 at 20:19 | #28

    @Tim
    Awesome. Thanks man!
    I just pushed it to Github: https://github.com/felis/USB_Host_Shield_2.0/commit/47d1a6b8b69a1a7e6a6e6055a038e61feb6d9a8f please confirm it’s working now! 🙂

  28. Tim
    January 3rd, 2013 at 20:27 | #29

    Glad I could help, that all works pretty well, but I’ve got a new bug for you 🙂

    Sometimes the controllers are getting each other’s commands – if I use the keypad on one controller, it sometimes changes the lights on the other controller.

    Similarly, sometimes pressing the trigger on one controller starts the vibration motor on the other controller.

  29. January 3rd, 2013 at 20:40 | #30

    @Tim
    Okay. I will look into it when I get my hands on a second controller.

  30. Tim
    January 3rd, 2013 at 20:43 | #31

    Ok, now that I’ve refreshed the code I can’t reproduce the problem. So for now I’ll assume that this one was a gremlin in my code 🙂

    Thanks for your help with this, was good fun figuring out how this stuff works.

    Out of interest, are you going to try to put any more functionality into these files, like reading controller battery level, and powering off the controller?

  31. January 3rd, 2013 at 20:50 | #32

    @Tim
    The problem is that the guy I borrowed the wireless controller from can’t find his charging cable so I’m actually just powering it off 3.3V from the Arduino, so I didn’t look into it.
    But as you can see on this page: http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo he suspects it’s the byte after 0x13 in the 0x00 report to be the battery level. Maybe you could simply make it output this value for a couple of hours or so and see if it decreased like it should?

    To power the device off try to send these commands: https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L609-L610 and see if it works.

  32. Rubén González
    January 8th, 2013 at 23:41 | #33

    Hi.

    I can use your Library with Arduino Nano?

    Thanks.

  33. January 8th, 2013 at 23:54 | #34

    @Rubén González
    Yes as long as it is the ATmega328 version.

  34. Rubén González
    January 9th, 2013 at 00:24 | #35

    Ok, so I will to buy a USBHost http://www.gravitech.us/usadforarna.html for start with my project. I hope work bacause it work with MAX3421E like USB Host Shield 2.0 for Arduino in http://www.circuitsathome.com/products-page/arduino-shields. is correct?

    Sorry for absurd questions but I’m a newbie in the electronic world.

    Thank you for this great work.

  35. January 9th, 2013 at 00:33 | #36

    @Rubén González
    It’s not directly compatible as the pinout is not the same.
    But it will work if you change this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Usb.h#L61 to:

    typedef MAX3421e<P8, P2>        MAX3421E;

    You can just cut the GPX connection as it’s not used by ver. 2 of the code.

  36. Rubén González
    January 9th, 2013 at 22:41 | #37

    Ok, I can see, thank you very much.

  37. January 10th, 2013 at 11:13 | #38

    @Rubén González
    See the updated reply. WordPress removed some of the code.

  38. Adam
    May 4th, 2013 at 00:34 | #39

    This is probably simple, but I can’t get the wireless xbox controller to init unless I open the serial window. Then it drops connection the second I close it. I’m looking to impliment a wireless application of the xBox controller without a PC. I tryied turning debug off and it doesn’t seem to help. Any advise would be extreamly helpful.

  39. Adam
    May 4th, 2013 at 00:59 | #40

    I was just able to figure it out, it was a problem with the arduino autoreset and having the max reset pin tied to an IO.

  40. May 4th, 2013 at 17:54 | #41

    @Adam
    Good to hear you solved the issue. Fell free to contact me again if you need any more help 🙂

  41. Carl Davey
    May 8th, 2013 at 14:39 | #42

    what a fantastic library!
    Does anyone know if the Xbox receiver will work ok on the 3.3v Vbus supplied by the mini host shield.

  42. May 10th, 2013 at 17:08 | #43

    @Carl Davey
    No I have tried it, but if you have 5V available then it’s no problem to connect 5V to the VBUS line anyway 🙂

  43. Leo
    November 20th, 2013 at 13:04 | #44

    Amazing code, worked perfectly with the little UNO. Now about to try controlling our tractor with it! Nothing like proving some code with a vehicle that weighs a couple tons! Thanks 🙂

  44. November 20th, 2013 at 13:06 | #45

    @Leo
    Haha your comment made my day 😀 I would love to see a video of it!

  45. Pavel
    January 1st, 2014 at 20:11 | #46

    Hi, I would like to ask if the shield works with unofficial xbox wireless receivers like this one http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=260927335309. Thank you very much.

  46. January 1st, 2014 at 22:59 | #47

    @Pavel
    Yes it does. I use an unofficial receiver from eBay as well. And I haven’t had any problems with it.

  47. Pavel
    January 2nd, 2014 at 18:08 | #48

    @Lauszus
    Perfect, thank you very much.

  48. Matheus Eduardo
    March 2nd, 2014 at 22:51 | #49

    Hey, i was wondering, if to use this library, i just need to plug the usb connector from xbox 360 wireless receiver in the usb plug on the usb host shield. Is this the correct procedure to get the library working? just plug the receiver on the usb host shield?, thanks, it would be cool if you post some basic tutorial of the schematics and required pins to fully work the mod. Thanks

  49. March 3rd, 2014 at 02:54 | #50

    @Matheus Eduardo
    Yes that is all you will have to do. Schematic of what? You simply plug it into the USB Host port and run the example.

    Note that more information can be found in the readme: https://github.com/felis/USB_Host_Shield_2.0#xbox-360-library.

  50. Jon
    March 22nd, 2014 at 03:44 | #51

    Thanks so much for your work on this. I’m just getting into the Arduino scene and I’m looking to eventually control an RC car with a wireless Xbox 360 controller. Your example sketch looks like a great place to start. However, I’m having a bit of trouble.

    After soldering the headers onto the usb host shield, inserting the shield onto the Arduino and plugging the Arduino into the computer, the power light on the shield lights up which I assume means that the shield is receiving power. When I connect the wireless receiver into the usb port on the shield the light on the receiver also lights up. So far so good.

    However, when I try to link the controller to the receiver it doesn’t work. I know that there’s not a problem with either of these two as they successfully link when the receiver is connected via a usb port on the computer. Is it possible that the shield hasn’t been soldered correctly? Do all the pins have to be soldered correctly for the power light to light up, or just the relevant pins? Also, both the controller and the receiver are also third-party. In a previous comment you mentioned that the receiver can be unofficial, but what about the controller?

    Thank you very much for any help and I apologise if any of my questions sounded stupid!

  51. March 28th, 2014 at 01:04 | #52

    @Jon
    Have you remembered to solder the ICSP header as well?
    Also please enable debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging, so we can see what is going on.

    The controller can be unofficial as well 😉

    No need to apologize! I’m just happy that people find my code useful!

  52. April 28th, 2014 at 15:39 | #53

    Hi.

    Thank you very much for that great Library!

    I found a little mistake for more than one controller in the setLedOn function. The controller-parameter was missing so the first received the Lamp of all. I fixed it but I don’t know how to publish:

    void XBOXRECV::setLedOn(LEDEnum led, uint8_t controller) {
    if(led == OFF)
    setLedRaw(0, controller);
    else if(led != ALL) // All LEDs can’t be on a the same time
    setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4, controller);

    Thank you a lot.

    Bye,
    Torsten

  53. April 28th, 2014 at 21:02 | #54
  54. alex
    August 29th, 2014 at 20:59 | #55

    Hey how can I move 2 motors with L1 and L2?

  55. alex
    August 29th, 2014 at 21:07 | #56

    @alex
    i mean L2 and R2

  56. September 9th, 2014 at 00:07 | #57

    @alex
    It depends on how you have your motors setup, but you could do something like this:

    analogWrite(pwmPin1, Xbox.getButtonPress(L2));
    analogWrite(pwmPin2, Xbox.getButtonPress(R2));
  57. Vinnie Marco
    September 30th, 2014 at 20:00 | #58

    I have been using this library for awhile now and it works pretty great. I have a wireless controller hooked up to an electric wheelchair. I have great control of it, until the controller disconnects. Where in the example in the Arduino IDE could I write 4 signals to LOW when the controller is disconnected and to HIGH only when it is connected? I have played around with an LED to demonstrate this, and it works, but when the controller is connected, my HIGH signals are only 0.6 volts. Once I remove the code that writes the 4 lines to LOW upon disconnect, my HIGH lines return to 5volts.

    Can anyone point me in the right direction?

  58. October 1st, 2014 at 01:10 | #59

    @Vinnie Marco
    Can you post your code somewhere like http://pastebin.com/ or https://gist.github.com/?

    To be honest it sounds like a problem with your code and not the library itself.

  59. Vinnie Marco
    October 1st, 2014 at 04:23 | #60

    I have pasted the code in this link. I am interested to find out where my mistake is!

    http://pastebin.com/sXxL8DJF

    @Lauszus

  60. October 2nd, 2014 at 01:01 | #61

    @Vinnie Marco
    I know what is wrong!

    The problem is that you are setting ControllerConnected low if any one of the Xbox.Xbox360Connected is false. You need to make sure that all of them are false before setting ControllerConnected low.

  61. Vinnie Marco
    October 2nd, 2014 at 02:21 | #62

    Thank you! I understand, however, I am having an issue trying to write this out. How should I structure this statement? With the existing else? With an if? Or an else if? What argument shall I test?

    How far off is the following code?

    if (Xbox.Xbox360Connected == false) {
            digitalWrite(enable1, LOW);
            digitalWrite(enable2, LOW);
            digitalWrite(enable3, LOW);    //these lines need to be written to LOW when the controller is not connected
            digitalWrite(enable4, LOW);

            digitalWrite(ControllerConnected, LOW);
    }//end else for when controller is not connected
  62. Vinnie Marco
    October 2nd, 2014 at 03:59 | #63

    Ahhhhhhh, after days of trying everything I could think of, I finally have it working. It only took since my last comment to figure it out! Thanks so much!!!

     if (!(Xbox.Xbox360Connected[0]) || (Xbox.Xbox360Connected[1]) ||(Xbox.Xbox360Connected[2]) || (Xbox.Xbox360Connected[3]) || (Xbox.Xbox360Connected[4]) == false) {
            digitalWrite(enable1, LOW);
            digitalWrite(enable2, LOW);
            digitalWrite(enable3, LOW);
            digitalWrite(enable4, LOW);

            digitalWrite(ControllerConnected, LOW);

            analogWrite(PWMPin2, 0);
            analogWrite(PWMPin, 0);
        //left trigger

            analogWrite(PWMPin4, 0);
            analogWrite(PWMPin3, 0);

    }//end else for when controller is not connected
  63. October 4th, 2014 at 08:44 | #64

    @Vinnie Marco
    No that is not the way to do it.

    Replace the first line with this:

    if (!Xbox.Xbox360Connected[0] && !Xbox.Xbox360Connected[1] && !Xbox.Xbox360Connected[2] && !Xbox.Xbox360Connected[3]) {

    What it does is that it makes sure that ALL of them are false!

  64. March 14th, 2015 at 17:10 | #65

    Help!
    My xbox receiver or any other usb peripheral wont be recognized by the shield. I ran the qc sketch and it hangs at “waiting for device…”

    any thoughts?

  65. March 15th, 2015 at 00:10 | #66

    @Abad Rosa
    Please try to connect an external power supply.

  66. Sam W
    March 17th, 2015 at 23:44 | #67

    Hi,
    I have the SainSmart USB Host Shield connected to my Uno and when I run the XBOXRECV example, the light on the receiver does not turn on and it does not seem to be recognized. It is a genuine MS receiver. I have also tried a “knock-off” receiver to no avail. The program compiles and uploads just fine. When I open the Serial Monitor, it says “Xbox Wireless Receiver Library Started” but then nothing else happens. I cannot sync my controller with the receiver or anything.

    Also, some of the other example sketches included with the library do not compile. I see lots of “‘prog_char’ was not declared in this scope” in the compile errors. Not sure how to fix this.

  67. March 18th, 2015 at 00:23 | #68

    @Sam W
    Please try to connect an external power supply to your Arduino. Also please consider buying the official shield in the future in order to support the developers of the hardware and library.

    Please also enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging, so I can see what is going on.

    What example are you referring to, please send a link.

  68. Sam W
    March 18th, 2015 at 01:32 | #69

    @Lauszus
    I’m considering buying the official shield since I’ll need another one soon, and I’m sure the QC is a bit better.

    USB debugging is enabled already, but I don’t see any extra output in the Serial Monitor. I’ve also tried an external power source (9V, 2.5A wall wart) which didn’t help.

    Here’s the example code I’m using:
    https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXRECV/XBOXRECV.ino

    Other devices seem to work fine when plugged into the USB Host shield, however. I tried a standard USB keyboard and it worked fine using this example:
    https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino

    Here is the output of board_qc when using either of my wireless receivers:
    http://pastebin.com/AH7sjmh4

    It gets stuck at “Waiting for device…”

    When running board_qc on my USB keyboard, everything passes as expected (not suck at “Waiting for device…”).

  69. March 19th, 2015 at 23:35 | #70

    @Sam W
    It sounds like a problem with the wireless receiver. Does it work under Windows?

  70. ArduinoinNE
    March 20th, 2015 at 04:12 | #71

    I’m having the same exact problem as Sam W above… I have the actual Microsoft wireless receiver. The green indicator light comes on when I plug it directly into my computer, but not when I use my SainSmart USB Host Shield. Again, the same as Sam W… the keyboard example noted above works just fine.

    I’m so frustrated…I was really looking forward to using this with my Arduino RC Car I built!

    Please let me know if you can help Sam and I. Thank you!

  71. March 20th, 2015 at 11:43 | #72
  72. ArduinoinNE
    March 21st, 2015 at 04:35 | #73

    Lauszus – first off, thank you for the quick response and for putting together such an extensive library!

    I ran the sketch mentioned above on my Arduino Uno with my SainSmart USB Host Shield twice and got the following output on the serial monitor:

    ———————————————————————————————————-

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
    GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
    Test failed. Value written: 00 Value read: FF
    Press any key to continue…
    GPIO test passed.
    PLL test. 100 chip resets will be performed
    Resetting oscillator

    Reset number 0 Time to stabilize – 495 cycles

    Reset number 1 Time to stabilize – 495 cycles

    Reset number 2 Time to stabilize – 496 cycles

    Reset number 3 Time to stabilize – 495 cycles

    Reset number 4 Time to stabilize – 496 cycles

    Reset number 5 Time to stabilize – 495 cycles

    Reset number 6 Time to stabilize – 496 cycles

    Reset number 7 Time to stabilize – 495 cycles

    Reset number 8 Time to stabilize – 496 cycles

    Reset number 9 Time to stabilize – 496 cycles

    Reset number 10 Time to stabilize – 496 cycles

    Reset number 11 Time to stabilize – 495 cycles

    Reset number 12 Time to stabilize – 495 cycles

    Reset number 13 Time to stabilize – 494 cycles

    Reset number 14 Time to stabilize – 495 cycles

    Reset number 15 Time to stabilize – 494 cycles

    Reset number 16 Time to stabilize – 494 cycles

    Reset number 17 Time to stabilize – 495 cycles

    Reset number 18 Time to stabilize – 494 cycles

    Reset number 19 Time to stabilize – 494 cycles

    Reset number 20 Time to stabilize – 494 cycles

    Reset number 21 Time to stabilize – 494 cycles

    Reset number 22 Time to stabilize – 496 cycles

    Reset number 23 Time to stabilize – 495 cycles

    Reset number 24 Time to stabilize – 496 cycles

    Reset number 25 Time to stabilize – 496 cycles

    Reset number 26 Time to stabilize – 496 cycles

    Reset number 27 Time to stabilize – 494 cycles

    Reset number 28 Time to stabilize – 494 cycles

    Reset number 29 Time to stabilize – 494 cycles

    Reset number 30 Time to stabilize – 494 cycles

    Reset number 31 Time to stabilize – 494 cycles

    Reset number 32 Time to stabilize – 495 cycles

    Reset number 33 Time to stabilize – 494 cycles

    Reset number 34 Time to stabilize – 494 cycles

    Reset number 35 Time to stabilize – 494 cycles

    Reset number 36 Time to stabilize – 495 cycles

    Reset number 37 Time to stabilize – 495 cycles

    Reset number 38 Time to stabilize – 495 cycles

    Reset number 39 Time to stabilize – 495 cycles

    Reset number 40 Time to stabilize – 495 cycles

    Reset number 41 Time to stabilize – 495 cycles

    Reset number 42 Time to stabilize – 494 cycles

    Reset number 43 Time to stabilize – 494 cycles

    Reset number 44 Time to stabilize – 495 cycles

    Reset number 45 Time to stabilize – 494 cycles

    Reset number 46 Time to stabilize – 494 cycles

    Reset number 47 Time to stabilize – 494 cycles

    Reset number 48 Time to stabilize – 494 cycles

    Reset number 49 Time to stabilize – 494 cycles

    Reset number 50 Time to stabilize – 494 cycles

    Reset number 51 Time to stabilize – 495 cycles

    Reset number 52 Time to stabilize – 495 cycles

    Reset number 53 Time to stabilize – 496 cycles

    Reset number 54 Time to stabilize – 496 cycles

    Reset number 55 Time to stabilize – 495 cycles

    Reset number 56 Time to stabilize – 494 cycles

    Reset number 57 Time to stabilize – 494 cycles

    Reset number 58 Time to stabilize – 494 cycles

    Reset number 59 Time to stabilize – 494 cycles

    Reset number 60 Time to stabilize – 494 cycles

    Reset number 61 Time to stabilize – 494 cycles

    Reset number 62 Time to stabilize – 494 cycles

    Reset number 63 Time to stabilize – 494 cycles

    Reset number 64 Time to stabilize – 495 cycles

    Reset number 65 Time to stabilize – 494 cycles

    Reset number 66 Time to stabilize – 495 cycles

    Reset number 67 Time to stabilize – 496 cycles

    Reset number 68 Time to stabilize – 496 cycles

    Reset number 69 Time to stabilize – 496 cycles

    Reset number 70 Time to stabilize – 495 cycles

    Reset number 71 Time to stabilize – 494 cycles

    Reset number 72 Time to stabilize – 494 cycles

    Reset number 73 Time to stabilize – 494 cycles

    Reset number 74 Time to stabilize – 494 cycles

    Reset number 75 Time to stabilize – 494 cycles

    Reset number 76 Time to stabilize – 494 cycles

    Reset number 77 Time to stabilize – 494 cycles

    Reset number 78 Time to stabilize – 494 cycles

    Reset number 79 Time to stabilize – 494 cycles

    Reset number 80 Time to stabilize – 494 cycles

    Reset number 81 Time to stabilize – 496 cycles

    Reset number 82 Time to stabilize – 495 cycles

    Reset number 83 Time to stabilize – 495 cycles

    Reset number 84 Time to stabilize – 495 cycles

    Reset number 85 Time to stabilize – 495 cycles

    Reset number 86 Time to stabilize – 495 cycles

    Reset number 87 Time to stabilize – 495 cycles

    Reset number 88 Time to stabilize – 494 cycles

    Reset number 89 Time to stabilize – 494 cycles

    Reset number 90 Time to stabilize – 494 cycles

    Reset number 91 Time to stabilize – 495 cycles

    Reset number 92 Time to stabilize – 494 cycles

    Reset number 93 Time to stabilize – 494 cycles

    Reset number 94 Time to stabilize – 494 cycles

    Reset number 95 Time to stabilize – 494 cycles

    Reset number 96 Time to stabilize – 495 cycles

    Reset number 97 Time to stabilize – 495 cycles

    Reset number 98 Time to stabilize – 495 cycles

    Reset number 99 Time to stabilize – 496 cycles

    Checking USB device communication.

    Waiting for device…

  73. ArduinoinNE
    March 21st, 2015 at 05:29 | #74

    Lauszus, one other quick note… I just tested the inside of USB connection on the USB Host Shield and it was at 3.3 volts. I tried to give the USB port on the USB host shield 5 volts by using a jumper wire from a known 5 volt location on the shield to the power pin of the USB port. However, that still did not cause the wireless receiver indicator light to turn on.

    I realize this is probably not the best test. Do you think I need to cut the 3.3 volt trace to the USB port power and jump the wire from 5 volts to the power pin of the USB port?

  74. March 21st, 2015 at 12:29 | #75

    @ArduinoinNE
    Ahh that must be why it is not working. Yes please reconfigure the VBUS jumper, so the 5V jumper is closed and 3.3V is open. Please see: https://www.circuitsathome.com/wp/wp-content/uploads/2011/02/uhs20s_pin_layout.jpg. It should be the same on your shield.

  75. ArduinoinNE
    March 23rd, 2015 at 04:50 | #76

    Lauszus, before I alter my USB Host Shield… I have a couple of questions first. Here’s a little background first.

    So, I tried connecting the Wireless Xbox Receiver via a USB wire that I modified. I basically just gave the Wireless Xbox Receiver 5 volts and ground (the red and black wires). The Wireless Xbox Receiver did turn on, but would not connect to my Xbox controller, even though it will connect when plugged directly into my PC. I verified the voltage was correct with my multi-meter.

    I also tried manually jumping 5 volts to the VBUS on my USB Host Shield. I uploaded the “XBOXRECV” example sketch, and the Wireless Xbox Receiver did actually turn on. I verified the voltage was correct (around 4.9 volts) with my multi-meter.

    However, in both situations above, I was NOT able to connect my Xbox360 controller to the Wireless Xbox Receiver. Before I cut the 3.3 volt trace to the VBUS, I thought I would verify that I need to actually cut the 3.3 volt trace to the VBUS.

    This leads me to my 2 main questions:
    1. Does having both the 5 volt and 3.3 volt power connected to the VBUS, cause the Wireless Xbox Receiver NOT to connect?
    2. Does the Wireless Xbox Receiver need to receive some sort of signal in order to connect to the Xbox 360 controller?

    Thank you for your help!

  76. March 23rd, 2015 at 12:04 | #77

    @ArduinoinNE
    When you did that test. Did you remember to have a common ground?

    So what you are saying is that you can’t get it working with your PC, either?

    You differently need to cut the 3.3V jumper. You can not connect both of them to 5V or you will potentially fry both the shield and your Arduino.

    You should run the example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXRECV/XBOXRECV.ino with debugging enabled and the following line uncommented: https://github.com/felis/USB_Host_Shield_2.0/blob/master/XBOXRECV.cpp#L22. If it does not even detect that you plug in the receiver to the shield, then I would say to try a different shield, as it is clearly buggy.

  77. ArduinoinNE
    March 24th, 2015 at 03:53 | #78

    Lauszus, sorry for the confusion.

    Yes, the Wireless Xbox Receiver does work properly when connected directly to the USB port on my PC. My Xbox 360 controller connects without any issues.

    Thanks for the clarification on the jumper. I will cut the trace and enable the debugging mode.

    I should have time to work on this tomorrow night… hopefully. I will let you know if this works!

  78. March 24th, 2015 at 16:04 | #79

    @ArduinoinNE
    Okay great 😉

  79. Daniel
    April 2nd, 2015 at 17:59 | #80

    I am having a similar problem with my USB Host Shield.
    My Reciever works perfectly when connected to my PC but it will not register when connected to the USB Host Shield.

    I tried running the USB Host Shield Test program that you posted above and I just got trash on the serial monitor

    0?ð?ZÛÓZRåÿÿÿÿÿÿÿÿÿ?!_¤Û°ÎPè]×

    or if i type anything in the command line, I get

    0?ð?ZÛÓZRåÿÿÿÿÿÿÿÿÿ?!_¤Û°ÎPè]×4?ZQ”Ëw}?Kð/æa,I?8Ï Z
    ?5¼ÍCZ¾²xX ‘¢?ú¾??X88?»N??SZ®¸x?4?°&3Ú¾²X:t¢°ëI;ÊÌÉ4aºx¶½MCZ¾°xX ‘?Ȭ,?¾S??X88??»?N??QZ®ºx?4´ÍÃÚ¾²X:t¢0ëiÊÌÉ4aºx´½MSZ®°xX?’?ÈP,?¾??X88??¿?N??®ºx¶ñ’?Qohð4?I?`?Ù¾Qr???08?F?9]q¬?¸H?Z?’?Ȭ,?¾??/88??¿?N??®»x¶ñN4¢èT?¶SO À??E¿?0?ÉQaºx´??ISZ®²x? ‘?ÈP,?¾?Ë/8??¿?N??6¬ºx??4¼ÍCZ¾²??-?þ,Ú

    I’m wondering if this means that the USB Host Shield was not made properly or if I am doing something wrong.

  80. April 2nd, 2015 at 23:09 | #81

    @Daniel
    You need to set the baud rate to 115200 in the serial monitor. Look in the bottom right.

  81. ArduinoinNE
    April 4th, 2015 at 21:08 | #82

    @Lauszus
    I cut the trace and just ran a jumper from the 5v hole to the VBUS hole and it didn’t work, even though it was measuring around 4.96 volts. The Wireless Xbox Receiver will turn on and blink green. I turn the controller on and press the connect key on the controller… and then the Wireless Xbox Receiver turns off. The shield appears to be defective. I’m totally frustrated… I really wanted this to work!

    Do you have a specific USB Host shield you would recommend?

  82. April 5th, 2015 at 00:11 | #83

    @ArduinoinNE
    Yes, the official one. You can buy it directly from me: http://shop.tkjelectronics.dk/ or from the following website: http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino.

  83. ArduinoinNE
    April 9th, 2015 at 02:06 | #84

    @Kristian Lauszus
    I just got the official Arduino USB Host Shield in and everything is working! NICE job on writing the library Sir! Very cool!

    For some reason the controller will start vibrating after a while and I have to hold the L & R Triggers, the L1 & R1 bumpers and push both the L & R sticks forward to get it to stop. I’m not why it does that… any ideas why the controller starts vibrating? The battery level is at “3.”

  84. April 9th, 2015 at 12:45 | #85

    @ArduinoinNE
    The example turns on the rumble when L2 or R2 is pressed. Please see: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Xbox/XBOXRECV/XBOXRECV.ino#L40.

  85. Sam W
    April 12th, 2015 at 22:28 | #86

    @Lauszus
    I managed to get my shield working with my 360 receiver. Per your instructions to @ArduinoinNE I cut the 3.3V VBUS jumper and jumped the 5V power select and I was able to get 5V out to the USB port. My receiver is now working perfectly. Thanks to both of you for helping me resolve this!

  86. April 14th, 2015 at 15:18 | #87

    @Sam W
    You are welcome 🙂 Glad to hear you got it working!

  87. Ivan
    April 23rd, 2015 at 02:11 | #88

    Hola, soy de argentina asique talvez no entiendas esto, si no lo entiendes te lo traducire:
    Para empezar, me encanto tu aporte, me es muy util, busco controlar un cuadricoptero con el control del xbox 360… Me surge el problema de que necesito utilizar los pines PWM y solo puedo utilizar los pines 3,5y6 de mi Arduino UNO, debido a que los pines 11,10y 9 me los deja como valores de tension fijos de salida que no puedo sacar, y si los intento sacar el arduino se tilda y no me reconoce mas el joystick… ¿El problema se debe al programa XBOXRECV.ino o se debera a mi USB Host Shield, el cual es USB Host Shield 2.0 “Arduino meets Android”?

    Desde ya, muchas gracias!!

  88. Jacob
    April 23rd, 2015 at 19:25 | #89

    @Lauszus

    I have the arduino usb shield but it doesn’t have the GPOUT and GPIN pins. How can I get this thing to work correctly or will I need to get one that does have them. Here is what I have… http://store.arduino.cc/product/A000004 any help would be great.

    Thanks

  89. April 27th, 2015 at 23:48 | #90

    @Ivan
    Pin 10 and 9 and be rerouted: https://github.com/felis/USB_Host_Shield_2.0#interface-modifications, but 13, 12 and 11 can not, as they are used for SPI on the Uno.

    @Jacob
    You will have to get the official shield which have those pins broken out. You can buy it from our webshop: http://shop.tkjelectronics.dk/product_info.php?products_id=43 or https://www.circuitsathome.com/products-page/arduino-shields.

  90. Aqmal
    May 4th, 2015 at 16:56 | #91

    I’m working on a project to turn on and off an led my clicking a button from xbox 360 controller. I want to make it toggle button, not hold. Anybody help me to code????

  91. May 4th, 2015 at 20:02 | #92

    @Aqmal
    I have replied to you at the Github issue: https://github.com/felis/USB_Host_Shield_2.0/issues/149.

  92. May 21st, 2015 at 10:46 | #93

    Thank you for your work.
    I want to know how to use servo with xbox360 controller(wired) +arduino usb host shieid
    I did your XBOXUSB exemple file succesfully with arduino IDE 1.6.4 version.

    But I can’t let the servo move by RightHat X .
    Would you please give me simple servo control example code?

  93. Shlomo
    May 22nd, 2015 at 09:49 | #94

    Thank you very much for making this library. Now R/C projects look impressive and professional.
    I appreciate if someone could help with the following issue:
    I have Arduino pro mini with its dedicated host shield connected to wireless XBOX receiver.
    Everything works great only if the receiver was already paired right before on my PC.
    The XBOX receiver is not original and refuses to pair if attached to the USB host shield.
    So on the PC I force windows to use the original Microsoft driver for the receiver as it apears as unknown device when attached.
    So on the PC I pair the receiver with the controller, then unplug it from the PC and immediately connect it to the USB shield.
    From now on as long as I don’t turn off the power everything works fine with the Arduino.
    If Arduino power is turned off then I have to repeat the whole process again.
    My question is:
    How can I make a change in the library to configure the compatible wireless receiver although it doesn’t identify itself as genuine one? (it is the only device I intend to connect with this modified library).
    I tried to enable debug for XBOXRECV but nothing is printed.
    I also tried to put Serial.print(“test”) in the init function and nothing is printed.
    So I guess that already inside the USB task the device is unknown and XBOXRECV functions have never called. But maybe I missing something here.
    Thank you for you kind help.

  94. Shlomo
    May 22nd, 2015 at 13:47 | #95

    I also tried to fool the vid, pid, class and subclass according to info I found (*) but it didn’t help either:
    udd->idVendor = 0x045e; // microsoft
    udd->idProduct = 0x0719; // wireless receiver
    udd->bDeviceClass = 255;
    udd->bDeviceSubClass = 255;

    * http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo

  95. June 7th, 2015 at 15:11 | #96

    @Kim
    You should simply servo library: http://www.arduino.cc/en/Reference/Servo and then the map function to mat the readings from the joystick to values for the servo: http://www.arduino.cc/en/Reference/Map.

    @Shlomo
    I have never had that problem. I can both pair and connect with the Xbox receiver without any issues.

    You can not change the PID or VID on the controller. You should enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging and then copy & paste the output when you plug in the receiver.

  96. Igor Figueiredo
    November 4th, 2015 at 03:09 | #97

    Hi! Thanks for this awesome library. That’s help me a lot! I have just one ask, does it have some function that, when the connection with the xbox controller is lost, I can use to launch another code. I need to implement a safe mode to my project. Sorry for this awful English haha. I really need to work on this.

  97. November 5th, 2015 at 15:11 | #98
  98. Igor Figueiredo
    November 11th, 2015 at 22:33 | #99

    Hi Lauszus thanks for the help. but i wrote a code using millis function like you said and it didn´t work well. i just need a code or function that tell to my sketch when the controller connection is lost to put low all output pins that i used. there is another way to do it or just using millis?

  99. November 12th, 2015 at 20:16 | #100

    @Igor Figueiredo
    You can simply use that function to figure out how long time it was since a input report was received. You could just use that to set all output pins to low if it gets above a certain threshold.

  100. Vishal Pusadkar
    February 4th, 2017 at 13:34 | #101

    I want to connect my Xbox 360 wired controller to the arduino how do i connect it

  101. Chris
    March 26th, 2017 at 07:14 | #103

    Hi. Thank you for your efforts on developing this library. I’m using it on a robot project to control servos. Works great for the standard servos, on an Arduino Uno.

    But I’m having some trouble doing a basic digitalWrite to set a pin to LOW…its for a small laser…just want to set it to LOW at first, then switch it on, digitalWrite(laserPin,HIGH) when the ‘B’ button on the Xbox360 controller is pressed.

    The laser & code works fine when I don’t use the XBOXRECV code….

    Any thoughts or suggestions? I’m also having trouble activating the RoboClaw motor controller that I’m using to drive some motors.

    Thanks again,

    Chris

  1. January 2nd, 2013 at 22:38 | #1
  2. February 17th, 2013 at 15:32 | #2