ArduinoJoystickLibrary icon indicating copy to clipboard operation
ArduinoJoystickLibrary copied to clipboard

Analog shake trouble

Open sergiopoverony opened this issue 6 years ago • 13 comments

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 joypad_noise

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 joypad_noise

Additional context

Add any other context about the problem here.

sergiopoverony avatar May 23 '19 18:05 sergiopoverony

The software looks good. I guess it's a wiring issue. Can you show/tell us how you wired up the Joystick?

targodan avatar May 23 '19 19:05 targodan

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

sergiopoverony avatar May 23 '19 19:05 sergiopoverony

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 .

fernandohsilva avatar May 23 '19 19:05 fernandohsilva

If the joystick is not connected this shaking is normal. Then the analog pins are floating.

targodan avatar May 23 '19 19:05 targodan

Maybe library not found!

w/out library he not compeled

sergiopoverony avatar May 23 '19 19:05 sergiopoverony

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

sergiopoverony avatar May 23 '19 19:05 sergiopoverony

Can you please show us how you connected it? Maybe a schematic, or at least a photo?

targodan avatar May 23 '19 19:05 targodan

This hardy

image image

sergiopoverony avatar May 23 '19 19:05 sergiopoverony

Analog joypad diagram standarted as any analog. image

sergiopoverony avatar May 24 '19 06:05 sergiopoverony

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.

targodan avatar May 24 '19 07:05 targodan

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.

sergiopoverony avatar May 24 '19 07:05 sergiopoverony

IDK what need change. My Analog resistance 2Kom. Any other 10Kom maybe who know?>

sergiopoverony avatar May 25 '19 15:05 sergiopoverony

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;
}

byteborg avatar Oct 10 '20 17:10 byteborg