I'm new to Arduinos and I've been trying to get an input from a joystick. I've got it all wired up but the values are just not right one bit.
The switch is working fine, but the X and Y axis's are far from that. The centre of the x and y axis is usually around 770-810, which flickers around 1-2 numbers from the centre (to be expected). The problem is that it should be 512 and when I push it up to full positive axis (same for both axis) it will be around the 1023 (somewhat normal), but full negative is 0-3. I've been looking around the joystick for anything that I could use to calibrate the centre, but theres nothing.
I've tried 4 different sticks and they all have the same problem so the only other thing I could think of is the cables. I've also looked at calibration code from other users but I've had no success.
(writing from another user that I copied)
(basic code to read the values)
// Arduino pin numbers
const int SW_pin = 0; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output
const int Y_pin = A1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print(" | ");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print(" | ");
Serial.print("Y-axis: ");
Serial.print(analogRead(Y_pin));
Serial.println(" | ");
delay(200);
}
Any help is nice