Joycon Joystick

hi guys im having problems with trying to get a joycon "joystick" to work with a esp32, i got a normal joystick working perfectly, but now im trying to get this to work, i brought some hall effect joycon joysticks, i tested them in a joycon and they work perfect, the axis mapping is off and for the life of me i cant get it working %100 can you look in my code see if you guys can see anything that sticks out?

#include <BleGamepad.h>
#include <WiFi.h>
#include <WebServer.h>
#include <FS.h>
#include <SPIFFS.h>

// --- Pins Configuration ---
constexpr int JOYSTICK_X_PIN = 34;
constexpr int JOYSTICK_Y_PIN = 35;
constexpr int BUTTON_PIN = 32;

// --- BLE Gamepad ---
BleGamepad bleGamepad("Custom BLE Gamepad", "Your Name", 100);

// --- Axis Range ---
constexpr int GAMEPAD_MIN = -127;
constexpr int GAMEPAD_MAX = 127;

// --- Deadzone ---
constexpr int JOYSTICK_DEADZONE = 10;  // Threshold for ignoring small movements

// --- Wi-Fi Credentials ---
const char* WIFI_SSID = "---------";
const char* WIFI_PASSWORD = "---------------;

// --- Web Server ---
WebServer server(80);

// --- Axis Mapping Function ---
int mapJoystickValue(int value) {
    int deadzoneAdjusted = abs(value) < JOYSTICK_DEADZONE ? 0 : value;
    return map(deadzoneAdjusted, -4095, 4095, GAMEPAD_MIN, GAMEPAD_MAX);
}

// --- Initialization Sequence ---
void initializeBluetooth() {
    // Emulates Joy-Con initialization handshake
    Serial.println("Initializing BLE for Joy-Con emulation...");
    delay(100); // Optional timing adjustments for proper handshake
}

// --- Setup ---
void setup() {
    Serial.begin(115200);

    if (!SPIFFS.begin(true)) {
        Serial.println("Failed to initialize SPIFFS.");
        return;
    }

    bleGamepad.begin();
    initializeBluetooth();

    pinMode(BUTTON_PIN, INPUT_PULLUP);

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("\nWi-Fi connected!");

    server.begin();
}

// --- Loop ---
void loop() {
    // Read joystick values
    int xRaw = analogRead(JOYSTICK_X_PIN);
    int yRaw = analogRead(JOYSTICK_Y_PIN);

    // Map joystick values
    int xMapped = mapJoystickValue(xRaw);
    int yMapped = mapJoystickValue(yRaw);

    // Debugging output
    Serial.print("X Mapped: ");
    Serial.println(xMapped);
    Serial.print("Y Mapped: ");
    Serial.println(yMapped);

    // Update gamepad axes
    bleGamepad.setAxes(xMapped, yMapped);

    // Handle button state
    if (digitalRead(BUTTON_PIN) == LOW) {
        bleGamepad.press(BUTTON_1);
    } else {
        bleGamepad.release(BUTTON_1);
    }

    bleGamepad.sendReport();
    server.handleClient();
}

Do "joycons" communicate via BLE or classic BlueTooth?

Joy-Con controllers for the Nintendo Switch primarily use Bluetooth Low Energy (BLE) for communication.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.