Hello Recalbox Community!
I'm in need of some assistance with a custom Arduino Leonardo game controller I've been working on. I've utilized the ArduinoGamepad library by gamelaster (found here: ArduinoGamepad Examples) to set up my controller. It's functioning perfectly when tested on the Windows gamepad settings—every button press and joystick movement is detected without any hiccups.
However, I've hit a snag with Recalbox on my Raspberry Pi 4B. While the system does recognize the controller as a Leonardo and allows me to use the joystick to navigate the Recalbox menu**, none of the buttons are being detected within the controller configuration menu.**
Has anyone experienced a similar issue, or can offer any insights into why this might be happening? Your help would be immensely appreciated to get my custom controller fully operational with Recalbox.
Thank you in advance!
- Here is my arduino code:**
/*
Select: button8
Start: button9
Hotkey: button9
L: button4 (Joystick L button)
R: button5 (Joystick R button)
X: button0
Y: button3
A: button1
B: button2
D-U: axis 1-
D-D: axis 1+
D-L: axis 0-
D-R: axis 0+
*/
#include <Gamepad.h>
//left joystick
int leftXcenter = 500;
int leftYcenter = 500;
double multiplierLX = 0.254;
double multiplierLY = 0.254;
//right joystick
int rightXcenter = 500;
int rightYcenter = 500;
double multiplierRX = 0.254;
double multiplierRY = 0.254;
Gamepad gp;
void setup() {
//Left joystick
pinMode(A0, INPUT);
pinMode(A1, INPUT);
//Right joystick
pinMode(A2, INPUT);
pinMode(A3, INPUT);
//Start, Select buttons
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
//ABXY
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
//LR
pinMode(8, INPUT_PULLUP); //Joystick L button
pinMode(9, INPUT_PULLUP);//Joystick R button
calibrate();
}
void loop() {
int lx, ly, rx, ry;
//left joystick
lx = analogRead(A0);
ly = analogRead(A1);
lx = floor((lx - leftXcenter) * multiplierLX);
ly = floor((ly - leftYcenter) * multiplierLY);
if(lx > 127) lx = 127;
if(ly > 127) ly = 127;
gp.setLeftXaxis(lx);
gp.setLeftYaxis(ly);
//right joystick
rx = analogRead(A2);
ry = analogRead(A3);
rx = floor((rx - rightXcenter) * multiplierRX);
ry = floor((ry - rightYcenter) * multiplierRY);
if(rx > 127) rx = 127;
if(ry > 127) ry = 127;
gp.setRightXaxis(rx);
gp.setRightYaxis(ry);
int select, start, a, b, x, y, l, r;
select = digitalRead(2);
start = digitalRead(3);
a = digitalRead(4);
b = digitalRead(5);
x = digitalRead(6);
y = digitalRead(7);
l = digitalRead(8);
r = digitalRead(9);
if(select == LOW)
gp.setButtonState(8, true);
else
gp.setButtonState(8, false);
if(start == LOW)
gp.setButtonState(9, true);
else
gp.setButtonState(9, false);
if(a == LOW)
gp.setButtonState(1, true);
else
gp.setButtonState(1, false);
if(b == LOW)
gp.setButtonState(2, true);
else
gp.setButtonState(2, false);
if(x == LOW)
gp.setButtonState(0, true);
else
gp.setButtonState(0, false);
if(y == LOW)
gp.setButtonState(3, true);
else
gp.setButtonState(3, false);
//L R button
if(l == LOW)
gp.setButtonState(4, false);
else
gp.setButtonState(4, true);
if(r == LOW)
gp.setButtonState(5, false);
else
gp.setButtonState(5, true);
delay(20);
}
void calibrate()
{
int lx, ly, rx, ry;
int i = 0;
while(i < 8)
{
lx = analogRead(A0);
ly = analogRead(A1);
bool validLX = lx > (leftXcenter - 100) && lx < (leftXcenter + 100);
bool validLY = ly > (leftYcenter - 100) && ly < (leftYcenter + 100);
rx = analogRead(A2);
ry = analogRead(A3);
bool validRX = rx > (rightXcenter - 100) && rx < (rightXcenter + 100);
bool validRY = ry > (rightYcenter - 100) && ry < (rightYcenter + 100);
if(validLX && validLY && validRX && validRY)
{
i++;
//nothing to do here!
}
else i = 0;
delay(20);
}
leftXcenter = lx;
leftYcenter = ly;
multiplierLX = (double)127 / (double)lx;
multiplierLY = (double)127 / (double)ly;
rightXcenter = rx;
rightYcenter = ry;
multiplierRX = (double)127 / (double)rx;
multiplierRY = (double)127 / (double)ry;
}
bolded text