1

How do I get the full range of motion from an analog joystick and the ESP32 WROOM32E using the Arduino IDE with esp-idf installed?

Using a 2 axis analog joystick, the 5v/3.3v pin, ground pin and the following code. I do not get the correct results printed out. I do get the correct range of values to print but when the Jstick is at 50% or greater it's distance away from center it will print out 50 or -50 when it should be closer to 25. I cannot use the full range of motion, I tried it with the 5v pin and did not have better results. I tried a second identical board, I swapped out my playstation style analog jsticks. Why does it do this? Is this a code problem?

int       test  = 0;
const int pinVar  = 33;

int read_jstick(int rxy) { int JXY = analogRead(rxy); //int JXYr = map(JXY,0,4095,-50,51);
return JXY; } void print_jstick(int pjs) { Serial.print("Joystick-X: "); Serial.println(pjs); } void setup() { Serial.begin(115200); pinMode(pinVar,OUTPUT); } void loop() { test = read_jstick(pinVar); print_jstick(test); }

Adding:

looking at the profile the joystick motion is like this: L _\ | / _ R

When the joystick is like this: | print val is: ~2500 at 5v and ~1800 at 3v

When the joystick is like this: _ on the L side the print val is 0 When the joystick is like this: _ on the R side the print val is 4095

Cool, but...

When the joystick is like this: \ at about 50% the range of motion, the value reads 0. It should be closer to 1200.

When the joystick is like this: between \ and | (0 and 50% range of motion) the print values will vary within the range of 0 and the middle value

I would like to be able to read the full range of motion on the joystick and receive a values incrementally over the entirety of that distance, how do I accomplish this? Example: I would like to move in let's say 10 incremental 'steps' with the joystick physically and the printout should be 1 through 10 and that would cover the movement from stationary to full extent of motion.

I have multiple of the same dev board, multiple of the same joystick, I have swapped cables and wires and I don't see how this could be a hardware problem so let's focus on coding unless it's perfect and should work exactly how I want it to because then that means for sure it's hardware and I just wasted a bunch of money buy multiple of everything and it's all broken. Sorry that I am frustrated here.

Update: I believe that a standard analog joystick module cannot be used with the ESP32 properly because the ESP32 cannot read the resistance of the joystick beyond 1.1v which means that it stops reading values in the middle of its range. You cannot get a scaling range of return from the joystick so it's basically a bad analog version of a digital left right up down inputter.

Prove me wrong please. If there is a way to read an analog pin higher than 1.1v or some other way so I could use the joystick for it's full range of motion on an ESP32 please let me know. All I can do is get a scaling range from stationary to a short move in 1 direction and when the stick is pushed passed 50% that direction it's all maxed out read value wise when it should be related to the position along length of travel.

Gil Sven
  • 167
  • 8

0 Answers0