Hello everyone.
Here's a sketch of a gamepad for a Teensy LC. It works perfectly under Windows with the game controller; it's detected as a keyboard/mouse/joystick. When I connect this gamepad to a Raspberry Pi Zero with Retropie 4.8, when mapping the UP to SELECT keys, the 13 buttons are activated, but the analog stick isn't detected. When injecting the code, it was recommended to select USB TYPE: JOYSTICK, but this option doesn't exist, which is why I selected KEYBOARD/MOUSE/JOYSTICK.
After visiting a few forums, the problem stems from the USB selection in the Arduino IDE.
How can I get the JOYSTICK selection in the USB TYPE?
My Arduino IDE version 2.3.6 and Teensy 1.59.0
The sketch:
// ****************************************************************************
// Teensy LC Gamepad (1 stick analogique gauche + 13 boutons)
// ****************************************************************************
#include <Bounce.h>
// ---------------------------------------------------------------------------
// Declaration of buttons
// ---------------------------------------------------------------------------
const int buttonPins[] = {
0, // Up
1, // Down
2, // Left
3, // Right
4, // A
5, // B
6, // X
7, // Y
8, // L1
9, // L2
10, // R1
11, // R2
20, // Start
21 // Select
};
const int numButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);
Bounce *buttons[numButtons];
// Stick analogique gauche
const int an_L_x = A0;
const int an_L_y = A1;
void setup() {
// Initialisation des boutons
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins, INPUT_PULLUP);
buttons = new Bounce(buttonPins, 10);
}
// Axes analogiques
pinMode(an_L_x, INPUT);
pinMode(an_L_y, INPUT);
}
void loop() {
// --- Gestion des boutons ---
for (int i = 0; i < numButtons; i++) {
buttons->update();
if (buttons->fallingEdge()) {
Joystick.button(i + 1, 1);
}
if (buttons->risingEdge()) {
Joystick.button(i + 1, 0);
}
}
// --- Stick analogique gauche ---
int lx = analogRead(an_L_x);
int ly = analogRead(an_L_y);
Joystick.X(lx);
Joystick.Y(ly);
}
Here's a sketch of a gamepad for a Teensy LC. It works perfectly under Windows with the game controller; it's detected as a keyboard/mouse/joystick. When I connect this gamepad to a Raspberry Pi Zero with Retropie 4.8, when mapping the UP to SELECT keys, the 13 buttons are activated, but the analog stick isn't detected. When injecting the code, it was recommended to select USB TYPE: JOYSTICK, but this option doesn't exist, which is why I selected KEYBOARD/MOUSE/JOYSTICK.
After visiting a few forums, the problem stems from the USB selection in the Arduino IDE.
How can I get the JOYSTICK selection in the USB TYPE?
My Arduino IDE version 2.3.6 and Teensy 1.59.0
The sketch:
// ****************************************************************************
// Teensy LC Gamepad (1 stick analogique gauche + 13 boutons)
// ****************************************************************************
#include <Bounce.h>
// ---------------------------------------------------------------------------
// Declaration of buttons
// ---------------------------------------------------------------------------
const int buttonPins[] = {
0, // Up
1, // Down
2, // Left
3, // Right
4, // A
5, // B
6, // X
7, // Y
8, // L1
9, // L2
10, // R1
11, // R2
20, // Start
21 // Select
};
const int numButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);
Bounce *buttons[numButtons];
// Stick analogique gauche
const int an_L_x = A0;
const int an_L_y = A1;
void setup() {
// Initialisation des boutons
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins, INPUT_PULLUP);
buttons = new Bounce(buttonPins, 10);
}
// Axes analogiques
pinMode(an_L_x, INPUT);
pinMode(an_L_y, INPUT);
}
void loop() {
// --- Gestion des boutons ---
for (int i = 0; i < numButtons; i++) {
buttons->update();
if (buttons->fallingEdge()) {
Joystick.button(i + 1, 1);
}
if (buttons->risingEdge()) {
Joystick.button(i + 1, 0);
}
}
// --- Stick analogique gauche ---
int lx = analogRead(an_L_x);
int ly = analogRead(an_L_y);
Joystick.X(lx);
Joystick.Y(ly);
}