Joystick analog value too high

Status
Not open for further replies.

IntrepidChuck

New member
Hello, Newbie here. I'm working on a game controller and am having some issues with the joystick values reading high. Both X and Y axis are reading about 866-878 at resting state. Max goes to 1023, while min stops at 166. It happens for both axis, individually. Not sure if I did some wiring wrong or am missing some code to set the resting values.

Using the Teensy LC with the Phoneix PS2 Joystick Module.

Diagram.png

Any assistance is greatly appreciated. Thank you. :D

Code:
const int numButtons = 13;  // 16 for Teensy, 32 for Teensy++
  
void setup() {
  Joystick.useManualSend(true);
  for (int i=0; i<numButtons; i++) {
    pinMode(i, INPUT_PULLUP);
  }
}
byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;

void loop() {
  // read analog inputs and set X-Y position
  Joystick.X(analogRead(A5));
  Joystick.Y(analogRead(A6));

for (int i=0; i<numButtons; i++) {
    if (digitalRead(i)) {
      // when a pin reads high, the button is not pressed
      // the pullup resistor creates the "on" signal
      allButtons[i] = 0;
    } else {
      // when a pin reads low, the button is connecting to ground.
      allButtons[i] = 1;
    }
    Joystick.button(i + 1, allButtons[i]);
  }
  
  // Because setup configured the Joystick manual send,
  // the computer does not see any of the changes yet.
  // This send_now() transmits everything all at once.
  Joystick.send_now();
  
  // check to see if any button changed since last time
  boolean anyChange = false;
  for (int i=0; i<numButtons; i++) {
    if (allButtons[i] != prevButtons[i]) anyChange = true;
    prevButtons[i] = allButtons[i];
  }
  delay(50);
}
 
Last edited:
Try connecting the module's '5V' pin to the 3.3V pin on the Teensy LC instead - this should bring the 'resting' reading much closer to 511, the 'minimum' figure will very likely reduce but it should already be capable of a zero reading even using 5V on a 3.3V ADC. Makes me suspicious of the pots in the module.

The seller of the module specifies 5V but the maximum you can read on Teensy LC is 3.3V - without being able to find the circuit diagram for the module I am willing to assume that it is just a pair of pots and a momentary switch; this means that it does not actually have a specific voltage it particularly needs to be supplied.
 
Try connecting the module's '5V' pin to the 3.3V pin on the Teensy LC instead - this should bring the 'resting' reading much closer to 511, the 'minimum' figure will very likely reduce but it should already be capable of a zero reading even using 5V on a 3.3V ADC. Makes me suspicious of the pots in the module.
Thanks for the quick reply. That is my fear is that there is something wrong with the joystick not being able to short completely to zero. I'll try the 3.3V line when I have the chance.

The seller of the module specifies 5V but the maximum you can read on Teensy LC is 3.3V - without being able to find the circuit diagram for the module I am willing to assume that it is just a pair of pots and a momentary switch; this means that it does not actually have a specific voltage it particularly needs to be supplied.
I never knew the max that can be read is 3.3V. Thanks for the info.
 
I just resoldered it to the 3.3V and it seems to be reading much better. Thanks for the assistance!

Now the only issue left is the joystick clearance from my shoddy woodworking. :rolleyes:
 
Status
Not open for further replies.
Back
Top