Joystick buggy with ESP32
Hello. I uploaded a simple code to read joystick values to my ESP32 but the values aren’t reading the usual 0-1023 and instead are lying between 0-4095 with the values constantly fluctuating even when centered. I assume it has something to do with the hardware and connections messing with the signal but just in case I’ll show the code too



22 Replies
Materials:
breadboard
5V step up converter
ESP32
Standard arduino joystick
3.7V 1s LiPo battery
-----------------------------------------------------------------------
Battery 3.7V —> power rail 1
Battery GND —> gnd rail 1
Converter Vin—> power rail 1
Converter GND —> gnd rail 1
Converter Vout —> power rail 2
Converter GND —> gnd rail 2
Joystick 5V —> power rail 2
Joystick GND —> GND rail 2
Joystick VRX —> pin 32 on esp
Joystick VRY —> pin 33 on esp
ESP32 gnd—> gnd rail 2
(for the record this is not my code but one I found online to test the joystick)
proof of values fluctuating in centered state

I don't know hardly anything about esp32, but 1) I've heard that the ADC on them is less than perfect so there's going to be some noise, and 2) you can code in a dead zone in the middle so the jitter doesn't affect anything
an Uno has a 10 bit ADC (0-1023), an ESP has a 12 bit ADC (0-4096)
they also have different full scale ranges
Oh that’s on me but every YouTube video I’ve seen on it still went from 0-1023
But I see alright I’ll just program it to have a set value if 10 or less apart
Thank you guys
wait but if I hold it in the middle shouldnt it be 2048
why is it in 1900s
since esp has a 3.3v range you should power the joysticks with 3,3v
oooooooooooooooooooooooooooohhhhhhhhhhhhhhhh
it'll be somewhere around 2048 in the middle, depending on mechanical trim of the stick, and joystick values always bobble a count or two
well its fine in that case I suppose as long as the middle value is around halfway and not hundreds off
powering the joysticks with 5v might damage the esp as at one end the joystick outputs Vcc
oh right for the read gotcha
its still outputting the same after its been converted to 3.3V
does it go from about 0 to about 4096?
yeah
wwait i had it on 3.3V the whole time mb
those cheap joysticks probably don't but many joysticks have a mechanical trim adjustment
at 5V it goes crazy random
yes, you are overdriving a 3.3v pin
if it keeps up like this I guess ill find antoher one
1900 isn't that far off, you'll never find one that give a rock solid 2048 😉
i kind of patched it up with tape and called it a day using code lol
generally you do. in code create a "dead band" for the center, for example, if x > 2000 or x < 2100 call it centered
or whatever values your stick gives you
Yepp I gave it 50 on both ends to be “centered”
Thank you once again 👍
i don't recall if i shared this, probably could be done more efficiently but it works 😉 https://wokwi.com/projects/431574631222675457