Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gamepad input doesn't register in any game #420

Open
biologyscience opened this issue Jun 15, 2023 · 0 comments
Open

Gamepad input doesn't register in any game #420

biologyscience opened this issue Jun 15, 2023 · 0 comments

Comments

@biologyscience
Copy link

biologyscience commented Jun 15, 2023

I am trying to make a controller similar to an PS4 controller and use it in some games which I play.

My setup is pretty simple, in a Arduino UNO with a potentiometer:

  • 5V (Power) - Vcc
  • A0 (Analog In) - Out
  • Ground (Power) - GND
Vcc, Output, GND refers to pins in a potentiometer

What my code does is as I rotate the potentiometer, the IO MCU reads the analog value and sends it to the USB MCU via the HID Bridge and updates the gamepad's x axis. This actually works exactly as I expected, by confirming with HoodLoader2 16u2 game controller properties in the control panel, Input viewer in Joystick Gremlin, gamepad-tester, gamepadviewer.

But the problem is, these inputs are not being recognized by any game in my PC. I have no idea why. Should I enable something so that I can get this working, or am I missing something ?
Please let me know if someone has a solution for this. I have pasted my code below for reference.


Sketch uploaded to USB MCU

#include <HID-Project.h>
#include <HID-Settings.h>

#define MIN16BIT -32768.0
#define MAX16BIT 32767.0

void setup()
{
    Serial.begin(9600);
    Serial1.begin(9600);

    Gamepad.begin();
}

void loop()
{
    int base100 = Serial1.read();

    Serial.print(base100); // to display data received from IO MCU

    float num = (base100 - 50.0) / 50.0;

    int axis = 0;

    if (num > 0) axis = num * MAX16BIT;

    if (num < 0) axis = num * -1 * MIN16BIT;

    Gamepad.xAxis(axis);

    Gamepad.write();
}

Sketch uploaded to IO MCU

#define ANALOGMAX 1023.0

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    float dec = (analogRead(A0) / ANALOGMAX);

    int base100 = dec * 100;

    Serial.write(base100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant