Joystick Upgrade for RC car

Hello Forum,

UPDATE: My current problem right now is to do with choosing a good joystick module that has a smooth change in value.

For context, I am trying to make a RC car using a ESP32 module as a receiver. It has all the basic hardware you would find in a RC car: ESC, Brushless Motor, Battery etc. The real problem is with the joystick as I am currently using very cheap joysticks where the moment I change the values, my motor immediately jumps to the next speed without gradually changing (which I don't like, this will not only degrade the cars performance but also damage the motor probably).

Speaking of the change in value, this is what the serial plotter shows:

The change in value makes the motor really jittery and unreliable.

Another problem is that the motor suddenly stops at a certain point higher than halfway on my joystick. My reasoning is that the joystick actually outputs a value higher than 180 (either in voltage?) which makes the motor violently stop.

I am thinking of trying magnetic hall effect joysticks that I learned from https://www.youtube.com/watch?v=oAsrLxaAkY0&t=535s by Marius Heier. I searched it up on Amazon UK but there's a LOT of copies and I don't know which one to trust.

Or MAYBE I can try making my own like the one in https://www.youtube.com/watch?v=9__Z4KI6kXQ by KendinYap but that is very unlikely.

Or just a really good Joystick module that is very good at its job.

Anyway it is up to you guys with a lot more experience than me to help me decide on the perfect joysticks.

By the way, the current joystick I am using right now looks like this:

And the code:

#include <ESP32Servo.h>

Servo myMotor;

void setup() {
  // put your setup code here, to run once:
  pinMode(25, INPUT);
  Serial.begin(9600);
  myMotor.attach(14);

}

void loop() {
  // put your main code here, to run repeatedly:
  int data = analogRead(25)/22.75;
  myMotor.write(data);
  Serial.println(data);
}

Just for clarification: for "drifting" did you mean that the value reported is slowly changing over time - usually in 1 direction, or did you mean that the value is changing randomly (and possibly rapidly) higher and lower around a certain value?

You should move your post to a more suitable category - possibly sensors - as it is likely to get more helpful responses.

Also post a simple sketch that demonstrates the problem along with a schematic showing how you have connected the various parts together.

There is no perfect joystick, regardless if you use one with potentiometers or Hall effect sensors, there will always be some drift. Hall effects are less prone to drift but are not completely protected from it.

Your best bet would be to find one that you like and compensate for the drift if and when it happens.

Yes, I am aware that there are no "perfect" joysticks but then again, how do regular RC transmitter joysticks reliably send data without their vehicles spiraling out of control?

Regardless, all I am looking for is a good, does-the-job joysticks with very minimal issues. I will try your advice if nothing seems to work.

By drifting, yes the values change randomly around a certain value. Also I don't really believe it's necessary that I need to post the schematics and everything since all I need is a good joystick in general. I only added the context if maybe someone is able to relate the problem to my other hardware (which I think is unlikely).

Also thanks for the categorizing tip! Honestly, it's so hard to choose what topic my problem falls into to.

I would call that noise rather than drift. You could apply digital filtering to the signal once digitised or add electronic filtering to the wiper signal going to the ADC.

Hi @swapnil2011 ,

perhaps you could explain how you use the joystick to control the RC ...

Is it connected to a PC or Raspberry Pi and the data are sent to the ESP32 via WiFi or Bluetooth?

Usually there are two main principles for joysticks beside the hall sensors:

  • "digital" joysticks and
  • analog joysticks

The so-called digital joysticks use the same principle as gamepads. They use four or eight switches to determine the direction the joystick is moved to. The switches are read several times per second and variables representing the speed or position are incremented or decremented accordingly. Therefore they do not allow quick direct readings of e.g. speed or position. There is no jitter involved.

Analog joysticks are usually based in potentiometers and - if they support auto-centering- use a spring force to automatically return to a centered position. Depending on the measurement procedure and mechanical tolerances the data read may jitter. "Drift" would mean that the data move more or less in a certain direction over time. That's not typical for potentiometer reading but for gyros.

The data of potentiometer readings can be smoothed by averaging over a number of measurements and by reducing the resolution (if you do the reading in your own with an Arduino) or by utilizing the Win 11 joystick driver. That's why I asked...

A further question is how you handle the joystick data in your ESP32 application. You might have good chances to average and/or smooth the curve there.

You don't have to use them 1:1 but could create a look up table that converts equal input data distances to a less "aggressive" output result...

Joystick drift should be corrected by a "trim" (tab or knob). You could also write a "trim approximation" or use a better defined deadband with hysteresis.

1 Like

Thank you for replying, the joystick is connected directly wired up to a ESP32 using a breadboard so the data does not go through any fancy WiFi but directly to the microcontroller. By drift, I am kind of making a mental link to how joystick drift works in Nintendo Switch Joycons and how the game moves on it's own without any user input (I am no gamer by any means, I don't even own a Nintendo :sweat:). The data from the Joystick is read from the analog pin on the ESP32 and gets saved in a variable so I understand that I should be able to modify the data.

The next problem is that... I am kind of a newbie. I don't know how I can make a code that smooths out the data for me, I will try researching on how to do it. If you know any code that does please do share it.

By trim, do you mean physical parts ON the joystick that allows to do that? If so, my joystick lacks the capability. I am also a newbie on how to write algorithms but I will research on it.

Toy grade or hobby grade? It's a world of difference.

Can you specify by toy grade or hobby grade?

Yes.

So... digitally programming the trimming code?

Yes. Assuming the joystick give an analog input to a 10 bit ADC of the controller, X and Y at rest would be 511, but could range from 500 to 520 (or more... 460 to 560). That is the "deadband" and your program should not register those values as stick movement. That might be your drift/trim issue.

If you post your code (in code tags!) it would be helpful.

Code tags are created by clicking on the code button in in the editor's menu.

There are generally two simple means to smoothen jittering days:

  • Averaging over a number of measurements
  • Quantizing the data (reducing the resolution)

Averaging is done by summoning up a certain number of measurements and deviding the result by the number of measurements.

Quantizing can be done by mapping the data from e.g. values between 0 and 4095 to 0 .. 1023 (y = x/4), just to name a common method.

Be aware that the ESP32 lacks accuracy in certain areas of ADC.

There are quite a number of webpages regarding this topic, just as a reference

https://forum.arduino.cc/t/fixing-the-non-linear-adc-of-an-esp32/699190

.https://esp32.com/viewtopic.php?t=2881&start=30

https://www.esp32.com/viewtopic.php?t=19804

https://docs.espressif.com/projects/esp-idf/en/v4.4.3/esp32/api-reference/peripherals/adc.html

and many more.

The expressif page lists also a possibility to reduce noise by adding a capacitor...

I guess posting the code might be a helpful step. You have already the attention of skilled members :wink:

Die to the special time of the year I'm not sure that I can assist you in the next days but there are plenty of supportive people around here!

Good luck!

BTW: I would not put much effort in the non linear part of the ESP32 ADC curve but just cut off these data. It will only reduce the usable movements of the stick close to the left, right, forward or backward edges. Smooth and repeatable values around the center should be much more relevant...

So from my understanding, the ESP32 "lacks" in analog readability?

Searching "esp32 potentiometer" or "esp32 joystick" and the first links are by Espressif. not espressif. someone who got URLs wholesale.

Sorry for asking, I am rather a newbie in this field so would it be okay if you could specify what those values mean (where are we getting them from? what do they mean?)

I believe these help with the ADC right?