i am trying to read the values of the positions of a joystick module using this code:
int x;
int y;
void setup(){
Serial.begin(9600);
}
void loop(){
x=map(analogRead(0),0,1023,0,100);
y=map(analogRead(1),0,1023,0,100);
if ( x < 50 ) Serial.print("back ");
else if( x == 50 ) Serial.print("equal ");
else Serial.print("forward ");
if ( y < 50 ) Serial.print("left ");
else if( y == 50 ) Serial.print("equal ");
else Serial.print("right ");
Serial.println();
delay(25);
}
but its not giving the right values. Its always giving 'forward right' or 'back left' and never changing. Ive tested the joystick module on a working arduino uno and it works perfectly with it. Ive also used this nano's digital pins and they work fine, too. So now im at loss as to where the problem is.
If you read several ADС channels in a row, their values begin to influence each other.
For accurate measurements, you need to add a delay between channels switching or read each channel twice and discard the first result.
The magnitude of that effect depends, in this case, on the resistance of the pot. If they're 10k or less, I would expect minimal 'charge transfer' from one input to the next.
The better fix, if it is charge transfer, is to just read each input twice.
However, it's a red herring, as the described problem doesn't fit the normal charge transfer effects, which would be 'noise'. @ac-rafi It sounds to me like you're reading a digital, not an analog, for some reason. You're either getting 0, or full ADC counts.
also can there be something wrong with the ref pin on the board guys? ive soldered the pins myself and maybe i made a mistake? It looks fine but how do i check it properly? i just know that the ref pin has some impact on adc values. But i dont know how it works
im using the built in usb cable of the board to power it. Ive connected the gnd and 5v pins of the joystick to the board's gnd and 5v and the Vx pin of the module to A0 of the board. im using jumber wires(F2F) for connecting them
i think ive found the problem. I soldered this nano myself and i mightve displaced these capacitors(i dont know for sure) from the tx, rx and L pins. Does anybody know what these are and how might these affect this?