Hey guys!
I'm completely new to this board, and don't know much about Arduino boards. So please bear with me.
I recently purchased a game controller, it's a shifter for a truck sim game. Inside of the shifter is to hall effect sensors that act as toggles. These are wired to the the Pro Micro ATmega32U4 5V/16MHz.
The issue I'm encountering is, one of the buttons on the shifter work correctly, but when I activate the other button, the Arduino board powers off completely, the LED indicators on the board turn off, and is no longer recognized by the PC. As soon as I release the button, the Arduino board turns back on again.
I have it plugged into a newer custom PC that only has USB 3.1 gen1 and USB 3.1 gen2 ports on it. But I have never encountered an issue with any other USB devices. So I assumed that it must be a wiring issue. I decided to test it on my wife's cheap laptop though, and oddly enough, it worked perfectly. In both the USB 3.0/3.1 port, and the 2.0 port.
So I'm left wondering if it's some sort of weird compatibility issue. But I couldn't find anything that sounded close to what I'm experiencing after multiple hours of looking around the internet.
Many people have bought these shifters, and no one has reported an issue like I'm experiencing. It's so odd that it works on the laptop, but not on my PC.
The seller has been extremely helpful, and sent replacements for everything, but the issue persisted. He sent me the exact board type, the code he's loading into the boards, and a brief description of how he is wiring them, so that I can hopefully provide enough details that someone can spot the issue. If there's any further details you might need, please let me know.
Thank you in advance for any help, it's very appreciated!
KOOKYE Pro Micro ATmega32U4 5V/16MHz
The hall sensors have 3 legs.
- Is positive
- Is negative
- Is switch
On the arduino the power for
- Is on vcc
- Is ground
- Is going to pins 7&8 for buttons
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
4, 0, // Button Count, Hat Switch Count
false, false, false, // No X, Y and Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering
unsigned long refrehRate = 15; // The refresh Rate between sonsor chekking in ms.
// lower value means faster refresh.
// reversebutton state inverts the signal processing (signal means no button is pressed
// no signal means button is pressed).
int reverseButtonState[4] = {false, true, false, false};
// if debug is true, the device will send the button information to the serial port
// can be viewed with the serial monitor in arduino IDE.
bool debugMode = false;
String debugMessage = "";
const int pinToButtonMap = 6; // Constant that maps the phyical pin to the joystick button. a value of 0 for example
// Means button 0 is wired to PIN 9, button 1 to PIN 10, etc.
int lastButtonState[4] = {0,0,0,0};
void setup() {
if(debugMode)
{
Serial.begin(9600);
}
// Initialize Button Pins
pinMode(pinToButtonMap, INPUT_PULLUP);
pinMode(pinToButtonMap + 1, INPUT_PULLUP);
pinMode(pinToButtonMap + 2, INPUT_PULLUP);
pinMode(pinToButtonMap + 3, INPUT_PULLUP);
Joystick.begin();
}
void loop() {
// Read pin values
for (int index = 0; index < 4; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (reverseButtonState[index])
{
currentButtonState = !currentButtonState;
}
if(debugMode)
{
debugMessage = "";
debugMessage = "BtnNr.:" + (String)index;
debugMessage = debugMessage + " State: ";
debugMessage = debugMessage + (String)currentButtonState;
debugMessage = debugMessage + "\r\n";
Serial.print(debugMessage);
}
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(refrehRate);
}