This is a work in progress. Trying to make a working arcade button to USB interface with the Nucleo F411RE.

Dependencies:   USBDevice mbed

This project was inspired by USB Joystick Device

The goal of this project is to build an simple interface that I will connect numerous Arcade buttons and joysticks to the Nucleo board, and the Nucleo will present itself as a USB Gamepad to Windows or Linux. The joysticks are Arcade joysticks that have four switches, up/down/left/right. It is not an analog joystick, just a set of switches. These will be connected to the Nucleo's pins configured as inputs.

The code will then continuously loop and test which buttons are closed, and transfer this data to the host via USBGamepad protocol.

Much thanks to Wim Huiskamp for his original project, documentation, and later reaching out to me to guide me to solving a last minute problem. Wim clued me into the fact that I needed a 1k5 pullup resistor between the 3v3 pin and the PA_12/D+ pin. Once I did this Windows detected the device as a Gamepad and registered it correctly! Yay!

Connecting USB cable to the board is as follows:

You will need a USB data cable (the one I used had a micro usb on one end and regular usb on the other). I cut off the micro USB end, and cut the insulation back about 30mm. This exposed four wires, Red, Black, White and Green. You will then either crimp some header connectors or solder directly to the Nucleo header pins as follows:

  • Green USB D+ to PA_12
  • White USB D- to PA_11
  • Red USB 5V to E5V (with jumper JP5 set to E5V)
  • Black USB GND to GND

As an extra debugging measure, you can connect both the ST/Link USB and the PA_12/11 USB to the Windows machine to run both at the same time, and you can see printf messages from within ST/Link.

We can verify the HID Vendor and Product IDs by looking at the Device Manager, and look for the HID Game Controller:


I used to register my own Vendor_ID and Product_ID

If you go to the USB Game Controller control panel widget, you will see the new entry for Arcade Gamepad:


And here we can see all 32 buttons:


On the Nucleo board you may have difficulties depending on the revision. The board I am using is an STM32F411RE Revision C03, which has resistors and solder joints (bottom) to allow the use of the Crystal on the STLink board for USB purposes. After programming via STLink, remove the USB cable from the STLink, the jumper must be set to E5V to power the board from the PC's usb port. Plug the new cable into the PC.

When you're ready to install it in the arcade cabinet, or project, just remember to setup the jumper JP5 to E5V and you only need the single USB connection to the host.

Here are some useful links that I used to grasp all the little things involved in this project:

--- a/main.cpp	Tue Dec 13 03:40:14 2016 +0000
+++ b/main.cpp	Tue Dec 13 04:13:37 2016 +0000
@@ -240,65 +240,6 @@
     int suspended_; 
-// ---------------------------------------------------------------------------
-// Simple binary (on/off) input debouncer.  Requires an input to be stable 
-// for a given interval before allowing an update.
-class Debouncer
-    Debouncer(bool initVal, float tmin)
-    {
-        t.start();
-        this->stable = this->prv = initVal;
-        this->tmin = tmin;
-    }
-    // Get the current stable value
-    bool val() const { return stable; }
-    // Apply a new sample.  This tells us the new raw reading from the
-    // input device.
-    void sampleIn(bool val)
-    {
-        // If the new raw reading is different from the previous
-        // raw reading, we've detected an edge - start the clock
-        // on the sample reader.
-        if (val != prv)
-        {
-            // we have an edge - reset the sample clock
-            t.reset();
-            // this is now the previous raw sample for nxt time
-            prv = val;
-        }
-        else if (val != stable)
-        {
-            // The new raw sample is the same as the last raw sample,
-            // and different from the stable value.  This means that
-            // the sample value has been the same for the time currently
-            // indicated by our timer.  If enough time has elapsed to
-            // consider the value stable, apply the new value.
-            if ( > tmin)
-                stable = val;
-        }
-    }
-    // current stable value
-    bool stable;
-    // last raw sample value
-    bool prv;
-    // elapsed time since last raw input change
-    Timer t;
-    // Minimum time interval for stability, in seconds.  Input readings 
-    // must be stable for this long before the stable value is updated.
-    float tmin;
 // ---------------------------------------------------------------------------
@@ -327,7 +268,7 @@
     // Create the joystick USB client.  
     MyUSBJoystick js(
     // last report timer - we use this to throttle reports, since VP
@@ -345,13 +286,7 @@
     // host requests
     for (;;)
-        // Look for an incoming report.  Process a few input reports in
-        // a row, but stop after a few so that a barrage of inputs won't
-        // starve our output event processing.  Also, pause briefly between
-        // reads; allowing reads to occur back-to-back seems to occasionally 
-        // stall the USB pipeline (for reasons unknown; I'd fix the underlying 
-        // problem if I knew what it was).
-        HID_REPORT report;
         // update the buttons
         uint32_t buttons = readButtons();
         uint16_t statusFlags;