1
\$\begingroup\$

I am trying to receive commands on a third-party Arduino-Uno-compatible board from an Xbox 360 controller via an M5Stack USB module but in my Arduino program I am not able to establish a connection from which to receive commands from the controller.

To be clear, I am talking about reading commands from an Xbox controller using an Arduino, not emulating an Xbox controller using an Arduino.

I'm reposting from the Arduino StackExchange because I got past a first hurdle since that post. (The problem I resolved was using the SS pin on the USB module.)

Hardware

  • A Bluno Nano. (An Arduino-Uno-compatible board in a Nano-like form factor with program uploading and serial communication via a matching Bluetooth USB dongle. However, I am using a wired USB connection to my PC instead.) The board is recognized as an Uno by the Arduino IDE. The same board has worked as expected for other projects.

  • An M5Stack USB module (with a MAX3421E chip), which is primarily meant to be compatible with an M5Stack microcontroller module. Either way, the USB module can communicate successfully using SPI.

  • A wireless Xbox 360 controller, but I connected it to the USB module using a USB cable that plugs in to the controller with a seemingly proprietary connector. Should be in working order. I assume that the USB connection is not just for power but for data too because the USB cable's proprietary connector with the Xbox controller has a sort of 'cuff' around it that seems to very intentionally block the "Connect" button on the back of the controller from being pressed; the USB cable appears to preclude a wireless connection by design.

I am not using an Xbox 360 wireless receiver to connect to the Xbox controller, nor do I want to connect to it wirelessly.

Wiring

  • I connected the GND (#1/3/5), +5V (#28, VBUS), SCLK (#11, GPIO18), MISO (#9, GPIO19), MOSI (#7, GPIO23), and SS (#20, GPIO5) pins of the USB module to the corresponding pins of the Bluno Nano: GND, +5V, SCK (D13), MISO (D12), MOSI (D11), and SS (D10).

USB module schematic

Attempts

  • Unplugging and re-plugging the Bluno Nano's USB cable with my PC.

  • Pressing the Bluno Nano's reset button.

  • Unplugging and re-plugging the Xbox controller's USB cable with the USB module, or vice versa (that is, starting with it unplugged).

  • Pressing or holding the center "X" button or other buttons on the controller, presumably to turn it on or hopefully enter some kind of connection-setup mode, maybe.

  • Managing to press the "Connect" button at the back of the controller, even while plugged in through USB.

  • Using a wired USB mouse instead of the Xbox controller. This works.

  • Trying various combinations of the above in different orders.

I have ensured that the Xbox controller is receiving power because the center "X" button lights up upon being pressed.

Software

  • Arduino IDE 2.0 on Windows 11

  • USB_Host_Shield_2.0 version 1.6.2 (latest) installed through the Arduino library manager. Note that this library seems to be primarily designed for a particular USB host shield, but I see it being used with other USB host shields, including in my USB module's documentation, and it works with my shield for receiving commands from a wired USB mouse using the example sketch at USB_Host_Shield_2.0/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino. There is a library for Xbox 360 within the USB Host Shield 2.0 library which works with a USB controller or a wireless controller, with example sketches for each:

  • USB_Host_Shield_2.0/examples/Xbox/XBOXUSB/XBOXUSB.ino

  • USB_Host_Shield_2.0/examples/Xbox/XBOXRECV/XBOXRECV.ino

I am trying both of these example sketches with some modifications in attempt to make either work. Both upload successfully without errors.

The problem is that Xbox.Xbox360Connected or Xbox.XboxReceiverConnected is false and that no commands are received.

In the Arduino IDE Serial Monitor, I set the baud rate to 115200 to match that specified in either example sketch.

Expected behavior

To be printed in the Serial Monitor (<...> is how I indicate my comments):

XBOX USB Library Started  <This works; `Usb.Init()` returns 0 for success.>
<Then I expect Xbox controller commands upon controls/buttons being pressed, e.g., "LeftHatX: ...">

Attempts

  • The USB Host Shield 2.0 documentation says about use with an Xbox 360 controller: "To use it via USB use the XBOXUSB library or to use it wirelessly use the XBOXRECV library. Note that a Wireless controller can NOT be used via USB!". It is unclear to me if my wired USB connection to my wireless controller calls for the XBOXUSB or XBOXRECV library, so I tried both libraries (tried both accompanying example sketches) to no avail.

  • I tried using an older version of the USB Host Shield 2.0 library.

  • I tried specifying the following in the library's settings.h, with no apparent change in output.

    /* Set this to 1 to activate serial debugging */
    #define ENABLE_UHS_DEBUGGING 1
    
  • I tried setting the following in XBOXUSB.cpp and XBOXRECV.cpp, with no apparent change in output.

    #define EXTRADEBUG // Uncomment to get even more debugging data
    #define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
    
  • I tried removing Usb.Task() in loop() to no avail.

  • I tried removing/ignoring the Xbox.Xbox360Connected and Xbox.XboxReceiverConnected checks before the code attempts to receive commands from the controller (i.e., using Xbox.getButtonPress(LT)). This was unsuccessful.

  • In the case of the XBOXRECV.ino example, I tried using only the first of up to 4 controllers that can connect to the same Xbox 360 wireless receiver (which I am not using). For example, instead of the following lines of code from XBOXRECV.ino, I tried using only i = 0 instead of the for-loop (or not even indexing with i at all).

    void loop() {
      Usb.Task();
      if (Xbox.XboxReceiverConnected) {
        for (uint8_t i = 0; i < 4; i++) {
          if (Xbox.Xbox360Connected[i]) {
            if (Xbox.getButtonPress(LT, i) || Xbox.getButtonPress(RT, i)) {
    ...
    

    Making that change to the above lines of code was unsuccessful.


I suspect that I'm missing something simple and obvious, or that my setup can't work for some reason.

Thank you very much for your help!

\$\endgroup\$
3
  • \$\begingroup\$ If you plug your 360 controller into a PC using that same USB cable, does your PC recognize that anything has been plugged in? \$\endgroup\$
    – brhans
    Dec 23, 2022 at 21:31
  • \$\begingroup\$ The controller appears as "Xbox 360 Wireless Controller via Play & Charge Kit" under "Xbox 360 Peripherals" in the Device Manager. Less importantly, upon plugin the "X" button flashes quickly, then more slowly. Also, the light on the USB cable's proprietary connector to the controller flashes green, turns off, then stays red. This light being red does't happen with the USB module. \$\endgroup\$ Dec 23, 2022 at 21:45
  • \$\begingroup\$ Turns out, "Play & Charge Kit" refers to the controller's removable rechargeable battery and the USB cable. According to this, "The play and charge kit only carries power. It does not carry the data required to connect a controller to a PC." I suppose that answers my question. I don't know why the USB cable stops the controller's "Connect" functionality from being used... \$\endgroup\$ Dec 23, 2022 at 21:55

1 Answer 1

1
\$\begingroup\$

I discovered that, upon plugging the USB cable into my PC rather than the USB module, the controller appears as "Xbox 360 Wireless Controller via Play & Charge Kit" under "Xbox 360 Peripherals" in the Device Manager.

Turns out, "Play & Charge Kit" refers to the controller's removable rechargeable battery and the USB cable.

According to this, "The play and charge kit only carries power. It does not carry the data required to connect a controller to a PC."

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.