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. Jon
    March 22nd, 2014 at 03:44 | #1

    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!

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

    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!

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


    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.


  4. April 28th, 2014 at 21:02 | #4
  5. alex
    August 29th, 2014 at 20:59 | #5

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

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

    i mean L2 and R2

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

    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));
  8. Vinnie Marco
    September 30th, 2014 at 20:00 | #8

    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?

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

    @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.

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

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



  11. October 2nd, 2014 at 01:01 | #11

    @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.

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

    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
  13. Vinnie Marco
    October 2nd, 2014 at 03:59 | #13

    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
  14. October 4th, 2014 at 08:44 | #14

    @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!

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