USB Joystick Interface 12 Axes Arduino Leonardo Micro

Introduction: USB Joystick Interface 12 Axes Arduino Leonardo Micro

The instructable provides the code for the creation of a USB joystick interface for Windows by using one Arduino Leonardo or Micro board. After the code upload, the Arduino board will appear in the Windows OS as three joystick devices each having 4 axes. The total number of controllable axes is therefore 12. This instructable will not show how to upload code to the Arduino board or connect potentiometers since that has been extensively covered already.

Step 1: The Code

Here you can download the .ino file and the libraries.

https://github.com/rvolarich/joystick_32U4_12axes_leonardo_micro

Copy the folder "Joystick12ch32u4" to your Arduino libraries folder.

Step 2: Pins

The picture shows the pin/axis mapping.

IMPORTANT: The pinMode in the setup() function of the JOYSTICK_32U4_12CH.ino file must be changed from INPUT to INPUT_PULLUP for any ADC pin that is not on the known potential, i.e. does not have a potentiometer connected to it and is free-floating. Without doing so, the system will not work.

Step 3: Checking the System

After all the potentiometers have been connected and pinMode changed for any unused pins as described in the previous step, to check functionality, power up the board. After the power-up, there must be a 200 ms blink on the TX diode which lasts until any of the potentiometers moves. After the movement, the TX diode lights only while the potentiometers are rotated. Any light activity of the TX diode when potentiometers are not rotated is the sign of an error in the hardware connection.

TX diode shows when data is transmitted over a USB line. The initial state scan is sent every 200 ms hence the blink at the power-up. This is a good time to start the software that the board will control so it can pick up the initial potentiometer values. After the first rotation of any of the potentiometers, the traffic is allowed only when potentiometers are rotated.

Any deviation from the described behavior indicates a hardware malfunction and does not guarantee proper operation.

The constants, MARGIN_POS and MARGIN_NEG, defined in the 28th and 29th lines of the code set the margin for filtering unwanted ADC input voltage oscillations. By default, they are set to +-8 points. That means that any change of the ADC input voltage less than 8 digital points will be rejected. But it also means that any intentional change under 8 points will skip unnoticed. If you have a need to lower the margin you can do so here, but oscillations must be kept within the margins.

1 Person Made This Project!

Recommendations

  • Fiber Arts Challenge

    Fiber Arts Challenge
  • Sculpt & Carve Challenge

    Sculpt & Carve Challenge
  • Backyard Contest

    Backyard Contest

Comments