Win10 Detects MEGA2560 'Big Joystick', but not button presses or analog inputs

I am trying to build a joystick for use in flight simulators on a Windows10 64-bit PC, but I can’t get the joystick monitor to recognize my button presses or analog stick inputs.

This is my first Arduino project, and my first post in this forum.

I am using an Arduino Mega2560 R3 which gets re-flashed using FLIP with the big joystick hex, as demonstrated by Riclamer, who also did it with an Arduino mega 2560 (all references below). This allows windows to detect the device as a joystick through USB instead of a serial device.

The joystick will evetually feature 20+ Switches, and 5 Potentiometers (or Linear Hall sensors), so I’ve set up my submission for this forum with one of each so that it’s easier to debug, to learn.

Wiring Diagram

Reference Project

Github repository of original project - GitHub - RICLAMER/Arduino_Big_Joystik: Code to Arduino UNO and MEGA.
Youtube demonstration of original project - Build Arduino Big Joystik in MEGA. - YouTube
Big Joystick HEX - GitHub - RICLAMER/Arduino_Big_Joystik: Code to Arduino UNO and MEGA.

Elaboration of Process

I am using the above reference project as the basis of my own. I set my first attempt up exactly as demonstrated. I could get Windows to recognize the Arduino Mega as a joystick, but button presses did not illuminate the buttons on screen, and potentiometer rotations in the analog joystick monitor box never moved at all.

At that point I decided to flash back to the normal firmware, and compile the sketch again. I noticed that the compiler displayed the following errors.

Compiler Errors

C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino: In function 'loop':
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:110:18: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
           btn[bt]= digitalRead(bt+1);
           ~~~~~~~^~~~~~~~~~~~~~~~~~~
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:108:22: note: within this loop
   for(int bt = 1; bt < 13; bt ++)
                   ~~~^~~~
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:115:18: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
        if (btn[on] == LOW)
            ~~~~~~^
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:113:22: note: within this loop
    for(int on=01; on < 13; on++)
                   ~~~^~~~
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:115:18: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
        if (btn[on] == LOW)
                  ^
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:113:22: note: within this loop
    for(int on=01; on < 13; on++)
                      ^
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:110:18: warning: iteration 11 invokes undefined behavior [-Waggressive-loop-optimizations]
           btn[bt]= digitalRead(bt+1);
                  ^
C:\Users\Dan\Desktop\Arduino\Big Joystick\riclamer_big_joystik\riclamer_big_joystik.ino:108:22: note: within this loop
   for(int bt = 1; bt < 13; bt ++)
                      ^

I also decide to look at the serial monitor to see if there was anything going wrong. And I saw the serial monitor outputted complete gibberish.

Sample Serial Output

(note, code output was weird characters that could not be pasted into the forum post editor)


I do have the BAUD rate set to match what is specified in the sketch, (and have tried other baud rates, always being sure to update the monitor’s rate to match the sketch) and none of them have worked. Interacting with the switch, knob, and hall sensor seems to have somewhat repeatable effects on the gibberish, so it seems like the code COULD be valid, but something is definitely wrong there.

Modifications to original code

I have, after initial testing, modified the original code sample so axis definitions at the bottom could be easier to read (no longer a loop which i found confusing), and to include one hall sensor, (original sketch only demonstrated pots).

I have done my best to convert the mapping of the second analog input in the original code to use the min and max values reported by my hall effect sensor as I pass a magnet next to it.

My Step by Step of Producing the Problem

  • hook up the wiring as demonstrated.
  • load the sketch included below in this post, and load it onto arduino.
  • ERROR - Compiler shows errors, but loads sketch successfully.
  • PROBLEM - Serial monitor is gibberish/nonsense.
  • short the board pins (indicated in wiring diagram) to activate DFU mode, and re-flash with big joystick hex (link to github above), using FLIP to update the Atmel 16U2 chip.
  • Disconnect/reconnect USB.
  • Arduino is recognized as a joystick.
  • PROBLEM - Joystick setup does not recognize button presses.

Hardware in use:

Arduino Mega2560 - (Elegoo MEGA 2560 R3 Board ATmega2560 ATMEGA16U2)
Potentiometer - (10K Audio Taper Stereo (final project will be linear taper) )
Switches - SPST, Momentary
Miscellaneous - Breadboard, hookup wire, gator clips

Firmware in use:

Arduino-big-joystick.hex (for flashing as joystick (HID))
Arduino-usbserial-mega.hex (for development of arduino IDE sketch)

Arduino Sketch

Here is the code that I’m working with (attached):
(had to attach the sketch separately to be thorough, and meet the 9000 character count)

My Coding Proficiency: Some basic javascript, and high-school level computer programming in BASIC, and C.

I think that’s everything. I’m happy to provide any additional clarification if needed.
Thank you in advance for any assistance you can provide. If I can get this thing working, I look forward to sharing what I’ve learned with others!

riclamer_big_joystik.ino (4.12 KB)

Check if the unmodified code works for you and contact the author for assistance.

Serial Monitor is useful only with the original Serial USB protocol.

Thank you. The first thing I tried was the unmodified code. Button presses were not detected.

I thought serial monitor's unusual output might be a clue about the communications problem. Are you saying it is irrelevant, since after firmware is switched, it is no longer used?

Also I thought the compiling errors might be a clue as to why it isn't functioning correctly.

I will attempt to contact original author.

Eventually a different baudrate in Serial Monitor may yield better readable text.

riclamer_big_joystik.ino:110:18: warning: iteration 11 invokes undefined behavior
           btn[bt]= digitalRead(bt+1);

This is a warning that you are trying to use the 12th and 13th elements of an array that only has 11 elements. Check the size of your array.

WARNING: This syntax produces undefined results! "fulloff = fulloff++;"

Use "fulloff = fulloff + 1;" or "fulloff += 1;" or "fulloff++;"

Thank you both,

I made the following two changes:

uint8_t btn[12]; uint8_t btn[13];

fulloff = fulloff++; fulloff = fulloff + 1;

This cleared up the compile errors.

Serial monitor is still gibberish. I tried setting sketch and monitor to match these rates (9600, 19200, 38400, 57600). All gibberish.