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

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

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

    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

  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

    @alex
    i mean L2 and R2

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

    @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));
Comment pages
1 2 3791
  1. January 2nd, 2013 at 22:38 | #1
  2. February 17th, 2013 at 15:32 | #2