ArduinoJoystickLibrary and multiple gamepad
-
Hello everyone,
I use the library ArduinoJoystickLibrary to create 4 gamepads.
In Windows, I see one controller with the four distincts gamepad, but in Recalbox, only the first is working, anyone have an idea about how I can have the 3 others working ?thanks in advance
https://github.com/MHeironimus/ArduinoJoystickLibrary
The Arduino code
#include <Wire.h> #include <Joystick.h> #define JOYSTICK_COUNT 4 Joystick_ Joystick[JOYSTICK_COUNT] = { Joystick_(0x03, JOYSTICK_TYPE_GAMEPAD, 14, 0, true, true, false, false, false, false, false, false, false, false, false), Joystick_(0x04, JOYSTICK_TYPE_GAMEPAD, 14, 0, true, true, false, false, false, false, false, false, false, false, false), Joystick_(0x05, JOYSTICK_TYPE_GAMEPAD, 14, 0, true, true, false, false, false, false, false, false, false, false, false), Joystick_(0x06, JOYSTICK_TYPE_GAMEPAD, 14, 0, true, true, false, false, false, false, false, false, false, false, false) }; // 8 bytes of data that we get from the controller struct { // bits: 0, 0, 0, start, y, x, b, a unsigned char data1; // bits: 1, L, R, Z, Dup, Ddown, Dright, Dleft unsigned char data2; char stick_x; char stick_y; } N64_status_1; struct { // bits: 0, 0, 0, start, y, x, b, a unsigned char data1; // bits: 1, L, R, Z, Dup, Ddown, Dright, Dleft unsigned char data2; char stick_x; char stick_y; } N64_status_2; struct { // bits: 0, 0, 0, start, y, x, b, a unsigned char data1; // bits: 1, L, R, Z, Dup, Ddown, Dright, Dleft unsigned char data2; char stick_x; char stick_y; } N64_status_3; struct { // bits: 0, 0, 0, start, y, x, b, a unsigned char data1; // bits: 1, L, R, Z, Dup, Ddown, Dright, Dleft unsigned char data2; char stick_x; char stick_y; } N64_status_4; void setup() { Wire.begin(); Serial.begin(115200); for (int index = 0; index < JOYSTICK_COUNT; index++) { Joystick[index].setXAxisRange(-80, 80); Joystick[index].setYAxisRange(-80, 80); Joystick[index].begin(); } } void loop() { Wire.requestFrom(8, 4); // request 4 bytes from peripheral device #8 while (Wire.available()) { // peripheral may send less than requested N64_status_1.data1 = Wire.read(); // receive a byte as character N64_status_1.data2 = Wire.read(); N64_status_1.stick_x = Wire.read(); N64_status_1.stick_y = Wire.read(); } Joystick[0].setXAxis(N64_status_1.stick_x); Joystick[0].setYAxis(N64_status_1.stick_y); Joystick[0].setButton(0, N64_status_1.data1 & 128 ? 1:0);//A Joystick[0].setButton(1, N64_status_1.data1 & 64 ? 1:0);//B Joystick[0].setButton(2, N64_status_1.data1 & 32 ? 1:0);//Z Joystick[0].setButton(3, N64_status_1.data1 & 16 ? 1:0);//start Joystick[0].setButton(4, N64_status_1.data1 & 0x08 ? 1:0);//Dup Joystick[0].setButton(5, N64_status_1.data1 & 0x04 ? 1:0);//Ddown Joystick[0].setButton(6, N64_status_1.data1 & 0x02 ? 1:0);//Dleft Joystick[0].setButton(7, N64_status_1.data1 & 0x01 ? 1:0);//Dright Joystick[0].setButton(8, N64_status_1.data2 & 32 ? 1:0);//L Joystick[0].setButton(9, N64_status_1.data2 & 16 ? 1:0);//R Joystick[0].setButton(10, N64_status_1.data2 & 0x08 ? 1:0);//Cup Joystick[0].setButton(11, N64_status_1.data2 & 0x04 ? 1:0);//Cdown Joystick[0].setButton(12, N64_status_1.data2 & 0x02 ? 1:0);//Cleft Joystick[0].setButton(13, N64_status_1.data2 & 0x01 ? 1:0);//Cright Joystick[0].sendState(); Wire.requestFrom(16, 4); // request 4 bytes from peripheral device #16 while (Wire.available()) { // peripheral may send less than requested N64_status_2.data1 = Wire.read(); // receive a byte as character N64_status_2.data2 = Wire.read(); N64_status_2.stick_x = Wire.read(); N64_status_2.stick_y = Wire.read(); } Joystick[1].setXAxis(N64_status_2.stick_x); Joystick[1].setYAxis(N64_status_2.stick_y); Joystick[1].setButton(0, N64_status_2.data1 & 128 ? 1:0);//A Joystick[1].setButton(1, N64_status_2.data1 & 64 ? 1:0);//B Joystick[1].setButton(2, N64_status_2.data1 & 32 ? 1:0);//Z Joystick[1].setButton(3, N64_status_2.data1 & 16 ? 1:0);//start Joystick[1].setButton(4, N64_status_2.data1 & 0x08 ? 1:0);//Dup Joystick[1].setButton(5, N64_status_2.data1 & 0x04 ? 1:0);//Ddown Joystick[1].setButton(6, N64_status_2.data1 & 0x02 ? 1:0);//Dleft Joystick[1].setButton(7, N64_status_2.data1 & 0x01 ? 1:0);//Dright Joystick[1].setButton(8, N64_status_2.data2 & 32 ? 1:0);//L Joystick[1].setButton(9, N64_status_2.data2 & 16 ? 1:0);//R Joystick[1].setButton(10, N64_status_2.data2 & 0x08 ? 1:0);//Cup Joystick[1].setButton(11, N64_status_2.data2 & 0x04 ? 1:0);//Cdown Joystick[1].setButton(12, N64_status_2.data2 & 0x02 ? 1:0);//Cleft Joystick[1].setButton(13, N64_status_2.data2 & 0x01 ? 1:0);//Cright Joystick[1].sendState(); Wire.requestFrom(32, 4); // request 4 bytes from peripheral device #32 while (Wire.available()) { // peripheral may send less than requested N64_status_3.data1 = Wire.read(); // receive a byte as character N64_status_3.data2 = Wire.read(); N64_status_3.stick_x = Wire.read(); N64_status_3.stick_y = Wire.read(); } Joystick[2].setXAxis(N64_status_3.stick_x); Joystick[2].setYAxis(N64_status_3.stick_y); Joystick[2].setButton(0, N64_status_3.data1 & 128 ? 1:0);//A Joystick[2].setButton(1, N64_status_3.data1 & 64 ? 1:0);//B Joystick[2].setButton(2, N64_status_3.data1 & 32 ? 1:0);//Z Joystick[2].setButton(3, N64_status_3.data1 & 16 ? 1:0);//start Joystick[2].setButton(4, N64_status_3.data1 & 0x08 ? 1:0);//Dup Joystick[2].setButton(5, N64_status_3.data1 & 0x04 ? 1:0);//Ddown Joystick[2].setButton(6, N64_status_3.data1 & 0x02 ? 1:0);//Dleft Joystick[2].setButton(7, N64_status_3.data1 & 0x01 ? 1:0);//Dright Joystick[2].setButton(8, N64_status_3.data2 & 32 ? 1:0);//L Joystick[2].setButton(9, N64_status_3.data2 & 16 ? 1:0);//R Joystick[2].setButton(10, N64_status_3.data2 & 0x08 ? 1:0);//Cup Joystick[2].setButton(11, N64_status_3.data2 & 0x04 ? 1:0);//Cdown Joystick[2].setButton(12, N64_status_3.data2 & 0x02 ? 1:0);//Cleft Joystick[2].setButton(13, N64_status_3.data2 & 0x01 ? 1:0);//Cright Joystick[2].sendState(); Wire.requestFrom(64, 4); // request 4 bytes from peripheral device #64 while (Wire.available()) { // peripheral may send less than requested N64_status_4.data1 = Wire.read(); // receive a byte as character N64_status_4.data2 = Wire.read(); N64_status_4.stick_x = Wire.read(); N64_status_4.stick_y = Wire.read(); } Joystick[3].setXAxis(N64_status_4.stick_x); Joystick[3].setYAxis(N64_status_4.stick_y); Joystick[3].setButton(0, N64_status_4.data1 & 128 ? 1:0);//A Joystick[3].setButton(1, N64_status_4.data1 & 64 ? 1:0);//B Joystick[3].setButton(2, N64_status_4.data1 & 32 ? 1:0);//Z Joystick[3].setButton(3, N64_status_4.data1 & 16 ? 1:0);//start Joystick[3].setButton(4, N64_status_4.data1 & 0x08 ? 1:0);//Dup Joystick[3].setButton(5, N64_status_4.data1 & 0x04 ? 1:0);//Ddown Joystick[3].setButton(6, N64_status_4.data1 & 0x02 ? 1:0);//Dleft Joystick[3].setButton(7, N64_status_4.data1 & 0x01 ? 1:0);//Dright Joystick[3].setButton(8, N64_status_4.data2 & 32 ? 1:0);//L Joystick[3].setButton(9, N64_status_4.data2 & 16 ? 1:0);//R Joystick[3].setButton(10, N64_status_4.data2 & 0x08 ? 1:0);//Cup Joystick[3].setButton(11, N64_status_4.data2 & 0x04 ? 1:0);//Cdown Joystick[3].setButton(12, N64_status_4.data2 & 0x02 ? 1:0);//Cleft Joystick[3].setButton(13, N64_status_4.data2 & 0x01 ? 1:0);//Cright Joystick[3].sendState(); delay(50); }
This is how it appear in windows :
One controllerwith 4 gamepads
I can receive the input of each gamepad
but in Recalbox only one appear "LLC ARDUINO MICRO"
If someone have an idea.... thanks in advance
-
I found the issue, need to add "usbhid.quirks=0x2341:0x8037:0x040" into the cmdline.txt file for an Arduino Micro
see wiki : https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/FAQ
-
@drj59 said in ArduinoJoystickLibrary and multiple gamepad:
I found the issue, need to add "usbhid.quirks=0x2341:0x8037:0x040" into the cmdline.txt file for an Arduino Micro
see wiki : https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/FAQ
Hi @drj59 i'm using the same library, with two arduino nano.
I have a strange issue moving on EmulationStation frontend, when I press a button or move joystic, every signle click is doubled.
In game does not happen, and this home made encoder, works fine.Have you got the same problem?