ArduinoJoystickLibrary
                                
                                
                                
                                    ArduinoJoystickLibrary copied to clipboard
                            
                            
                            
                        Analog shake trouble
Description of Issue
After download sketch to Arduino Micro/Leonardo in gamepad test i see as analog poit noise (all shake) - analog joypad not connected, after connect analog joypad - the problem is not solved

Technical Details
- Arduino Micro
 - Windows 10
 - Arduino IDE Version 1.8.5 and 1.8.9
 
Sketch File that Reproduces Issue
#include <Joystick.h>
#include <Arduino.h>
#include <DynamicHID.h>
#define PINS 16
#define ENABLE_ANALOG1 true
int X1 = A0;
int Y1 = A1;
// Create Joystick
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, PINS, 0, 
  true, true, false, false, false, false, false, false, false, false, false);
class CButton {
  public:
  int pin = 0;
  int lastState = 0;
  
  CButton(int p) {
    pin = p;
  }
};
CButton Buttons[PINS] ={A2,A3,0,1,2,3,4,5,6,7,8,9,10,16,14,15};
void setup() {
  for(int i=0 ; i<PINS ;i++) {
    pinMode(Buttons[i].pin, INPUT_PULLUP);
  }
  Joystick.begin();
  if (ENABLE_ANALOG1) {
    Joystick.setXAxisRange(-512, 512);
    Joystick.setYAxisRange(-512, 512);
  }
}
void JButtonStates() {
  if (ENABLE_ANALOG1) {
    Joystick.setXAxis(analogRead(X1) - 512);
    Joystick.setYAxis(analogRead(Y1) - 512);
  }
  
  for (int i = 0; i < PINS; i++) {
    int currentState = !digitalRead(Buttons[i].pin);
    
    if (currentState != Buttons[i].lastState) {
      Joystick.setButton(i, currentState);
      Buttons[i].lastState = currentState;
    }
  }  
}
void loop() {
  JButtonStates();
  delay(50);
}
Wiring Details
analog point any time shaked and not work

Additional context
Add any other context about the problem here.
The software looks good. I guess it's a wiring issue. Can you show/tell us how you wired up the Joystick?
The software looks good. I guess it's a wiring issue. Can you show/tell us how you wired up the Joystick?
Joystick not conencted. i only download sketch
Maybe library not found!
Em qui, 23 de mai de 2019 às 16:09, SergioPoverony [email protected] escreveu:
The software looks good. I guess it's a wiring issue. Can you show/tell us how you wired up the Joystick? Joystick not conencted. i only download sketch
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MHeironimus/ArduinoJoystickLibrary/issues/116?email_source=notifications&email_token=ACYGQ7DFVAXFVHNVQGDBKV3PW3TYFA5CNFSM4HPJKITKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWDGL5I#issuecomment-495347189, or mute the thread https://github.com/notifications/unsubscribe-auth/ACYGQ7GHDPPMONYDQQPZO3TPW3TYFANCNFSM4HPJKITA .
If the joystick is not connected this shaking is normal. Then the analog pins are floating.
Maybe library not found!
w/out library he not compeled
If the joystick is not connected this shaking is normal. Then the analog pins are floating.
I connect this analog. Use correctly pins. Trouble not solved https://datasheet.lcsc.com/szlcsc/ALPS-Electric-RKJXY1000006_C219776.pdf
Can you please show us how you connected it? Maybe a schematic, or at least a photo?
This hardy

Analog joypad diagram standarted as any analog.

Sorry, as I was trying to reply yesterday, my internet died.
Well, that looks all right. I don't know what would cause the shaking then. Maybe a bad connection on the header. Or a broken joystick module.
Can you try to verify the joystick module is OK? Maybe using a multimeter or an oscilloscope.
Also I don't see any capacitor near the atmega. Maybe try to solder in a 10nF across Vcc and GND of the Atmega to rule out stability problems.
Sorry, as I was trying to reply yesterday, my internet died.
Well, that looks all right. I don't know what would cause the shaking then. Maybe a bad connection on the header. Or a broken joystick module.
Can you try to verify the joystick module is OK? Maybe using a multimeter or an oscilloscope.
Also I don't see any capacitor near the atmega. Maybe try to solder in a 10nF across Vcc and GND of the Atmega to rule out stability problems.
Joystick worker and contacts too. Tested with a multimeter. Tonight I will put a capacitor in for verification and I will write later.
IDK what need change. My Analog resistance 2Kom. Any other 10Kom maybe who know?>
Looks like your catching noise on the lines. You could interpolate the measurements, as I do in one of my projects:
// Measure analog pin and return tare-corrected value
int64_t measure(uint8_t pin, uint8_t interpol, int64_t tare) {
    int64_t val = 0;
    for (uint8_t i = 0; i < interpol; i++) {
        val += analogRead(pin);
    }
    return (val / interpol) - tare;
}