/esp-idf-analog-joystick

2-axis XY joystick using ESP-IDF

Primary LanguageCMIT LicenseMIT

esp-idf-analog-joystick

2-axis XY joystick using ESP-IDF.

I bought this 2-axis XY joystick module for $1 on AliExpress.
analog-joystick

So I used ESP-IDF to read the X and Y positions.
VRx and VRy are analog output pins.
ESP32 has two ADCs, ADC1 and ADC2.
This project uses ADC1.

web

Software requirements

ESP-IDF V5.0 or later.
ESP-IDF's ADC API has changed significantly since V5.0.

Hardware requirements

2-axis XY joystick.

Installation

git clone https://github.com/nopnop2002/esp-idf-analog-joystick
cd esp-idf-analog-joystick/pose
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Configuration

config-top config-app

WiFi Setting

Set the information of your access point. config-wifi

Device Setting

Set the information of gpio for analog input and degiatl input.
VRX and VRY are analog inputs and SW is a digital input.
config-device

Analog input gpio for ESP32 is GPIO32 ~ GPIO39. 12Bits width.
Analog input gpio for ESP32S2 is GPIO01 ~ GPIO10. 13Bits width.
Analog input gpio for ESP32S3 is GPIO01 ~ GPIO10. 12Bits width.
Analog input gpio for ESP32C2 is GPIO00 ~ GPIO04. 12Bits width.
Analog input gpio for ESP32C3 is GPIO00 ~ GPIO04. 12Bits width.
Analog input gpio for ESP32C6 is GPIO00 ~ GPIO06. 12Bits width.

Wireing

JOYSTICK ESP32 ESP32-S2/S3 ESP32-C2/C3/C6
GND -- GND GND GND
+5V -- 3.3V 3.3V 3.3V
VRx -- GPIO32 GPIO1 GPIO0 (*1)
VRy -- GPIO33 GPIO2 GPIO1 (*1)
SW -- GPIO15 GPIO3 GPIO2 (*2)

(*1)You can change it to any ADC1 using menuconfig.

(*2)You can change it to any GPIO using menuconfig.

Calibration

The first time you run this project, it will calibrate.
Follow the on-screen instructions to calibrate.

W (6886) STICK: Don't touch the joystick. Press Enter when you are ready.
W (44806) STICK: Tilt the joystick all the way to the top. Press Enter when you are ready.
W (50306) STICK: Tilt the joystick all the way to the buttom. Press Enter when you are ready.
W (55006) STICK: Tilt the joystick all the way to the left. Press Enter when you are ready.
W (59106) STICK: Tilt the joystick all the way to the right. Press Enter when you are ready.
I (63006) STICK: vrx_center=1663 vrx_low=0 vrx_low=3408
I (63006) STICK: vry_center=1614 vry_low=0 vry_low=3393
W (63006) STICK: Calibration Done. Press Enter when you are ready.

Calibration data is recorded in NVS.
If you want to initialize the calibration data, use the following command:
idf.py erase-flash

View X-Y positoion with built-in web server

ESP32 acts as a web server.
I used this component.
This component can communicate directly with the browser.
It's a great job.
Enter the following in the address bar of your web browser.

http:://{IP of ESP32}/
or
http://esp32.local/

web