Hello.
I have been trying to build a HOTAS setup with this library, but I am stuck on wierd issue.
I have three devices, a stick with Arduino micro, a throttle with Arduino pro mini and pedals with Arduino pro mini. The pedals and throttle are connected to the Arduino micro by I2C and my code recognises what devices are connected by quering the I2C bus and sets the USB joystics accordingly. I have also set up internal serial debugging, that can be accessed by pressing two buttons on the stick when plugin it in the computer. Everything works great at the debug mode and all axis and buttons are working as they should, but if I connect the stick, with pedals connected, to my computer I get USB device not recognized error. If I connect the joysticks to my computer in debug mode and then flash the code to the Arduino micro all three joysticks show up in control panel, but nothing on the throttle is responsive, but the pedals work. If I connect just the throttle to the stick it works as it should. Also if I go to the debug mode and flash the code with only pedals connected, everything works in the control panel, but if I disconnect and reconnect the joystick, I get the USB device not recognized error again. I am really lost with this one. I am thiking it has to be some kind of software issue, because everything is working fine in serial debug mode.
Things I have tried
Adding delay before and/or after the I2C query.
Forcing the detected devices to full HOTAS and skipping the I2C query completely. I was thinking that the query would take too long and windows would time out the USB recognition.
Using the unmodified library. I modified the library so that it does not create the joystics that are not found in the I2C query. Either option does not change the behaviour.
I used a digispark board (AtTiny88) for the pedals. Same behaviour.
I have tried different USB ports and different computers. USB 2 and USB 3 in laptop and desktop, no change in behaviour.
Technical Details
Arduino micro, 2 x Arduino pro mini
IDE = PlatformIO on VSCode
OS = Windows 10 (19043.1889)
HP ZBook 15 G2 and a desktop computer.
Joystick library version 2.1.0 and 2.1.1
#ifndef INPUTS_H_
#define INPUTS_H_
#include <Arduino.h>
#include "i2c.h"
/*
Button bit order
//Throttle
buttons[0] bit 0 hatbtn0
buttons[0] bit 1 hatbtn1
buttons[0] bit 2 pushbtn0
buttons[0] bit 3 pushbtn1
buttons[0] bit 4 pushbtn2
buttons[0] bit 5 pushbtn3
buttons[0] bit 6 Switch0
buttons[0] bit 7 Switch1
buttons[1] bit 0 Switch2
buttons[1] bit 1 Switch3
//Stick
buttons[1] bit 2 Trigger
buttons[1] bit 3 Stickbtn0
buttons[1] bit 4 Stickbtn1
buttons[1] bit 5 Stickbtn2
*/
class inputs
{
private:
//Analogs
int Stick_X;
int Stick_Y;
int Mouse_X;
int Mouse_Y;
int Throttle;
int Rudder;
int Brake_R;
int Brake_L;
int Encoder;
//HAT
int HAT;
//Buttons
uint8_t Buttons[2];
//Functions
int resolveHat(int HatY, int HatX);
public:
inputs();
//Functions
void getInputData(uint8_t devices);
int getStick_X(void)
{
return Stick_X;
};
int getStick_Y(void)
{
return Stick_Y;
};
int getMouse_X(void)
{
return Mouse_X;
};
int getMouse_Y(void)
{
return Mouse_Y;
};
int getThrottle(void)
{
return Throttle;
};
int getRudder(void)
{
return Rudder;
};
int getBrake_R(void)
{
return Brake_R;
};
int getBrake_L(void)
{
return Brake_L;
};
int getEncoder(void)
{
return Encoder;
};
int getHat(void)
{
return HAT;
};
uint8_t getButtons1(void)
{
return Buttons[0];
}
uint8_t getButtons2(void)
{
return Buttons[1];
}
};
#endif
i2c.cpp
#include "i2c.h"
void i2c::init(void)
{
Wire.begin();
}
int i2c::detectDevices(void)
{
int8_t error;
uint8_t Throttle = 0;
uint8_t Pedals = 0;
//uint8_t connectedDevices[3] = {0,0,0};
//bool deviceFound = false;
//Find Throttle
#ifdef DEBUG_SERIAL
Serial.print("Quering device 0x");
Serial.print(THROTTLE);
Serial.print("\n");
#endif
Wire.beginTransmission(THROTTLE);
error = Wire.endTransmission();
if (error == 0)
{
#ifdef DEBUG_SERIAL
Serial.print("I2C device found at address 0x");
Serial.print(THROTTLE);
Serial.print("\n");
#endif
Throttle = 1;
}
else if (error == 4)
{
#ifdef DEBUG_SERIAL
Serial.print("Unknown error at address 0x");
Serial.print(THROTTLE);
Serial.print("\n");
#endif
return -1;
}
else
{
#ifdef DEBUG_SERIAL
Serial.print("No device found at address 0x");
Serial.print(THROTTLE);
Serial.print("\n");
#endif
}
//Find pedals
#ifdef DEBUG_SERIAL
Serial.print("Quering device 0x");
Serial.print(PEDALS);
Serial.print("\n");
#endif
Wire.beginTransmission(PEDALS);
error = Wire.endTransmission();
if (error == 0)
{
#ifdef DEBUG_SERIAL
Serial.print("I2C device found at address 0x");
Serial.print(PEDALS);
Serial.print("\n");
#endif
Pedals = 1;
}
else if (error == 4)
{
#ifdef DEBUG_SERIAL
Serial.print("Unknown error at address 0x");
Serial.print(PEDALS);
Serial.print("\n");
#endif
return -2;
}
else
{
#ifdef DEBUG_SERIAL
Serial.print("No device found at address 0x");
Serial.print(PEDALS);
Serial.print("\n");
#endif
}
if(Throttle == 1 && Pedals == 1)
{
#ifdef DEBUG_SERIAL
Serial.print("Set Full HOTAS \n");
#endif
return 1;
}
else if(Throttle == 1 && Pedals == 0)
{
#ifdef DEBUG_SERIAL
Serial.print("Set Throttle only \n");
#endif
return 2;
}
else if(Throttle == 0 && Pedals == 1)
{
#ifdef DEBUG_SERIAL
Serial.print("Set Pedals only \n");
#endif
return 3;
}
else
{
return 0;
}
}
int i2c::getDeviceData(int address, int len, uint8_t *data)
{
int c = 0;
Wire.requestFrom(address, len);
while (Wire.available())
{ // peripheral may send less than requested
data[c] = Wire.read(); // receive a byte as character
c++;
}
return c;
}
i2c.h
#ifndef I2C_H_
#define I2C_H_
#include <Arduino.h>
#include <Wire.h>
#include "config.h"
class i2c
{
public:
void init(void);
int detectDevices(void);
int getDeviceData(int address, int len, uint8_t *data);
};
#endif
I did not add the Arduino pro mini code for the throttle, because this post is way too long already and the code is besically the same as the pedals code. It just polls constantly the ADC's and button pins and responds on the I2C request interrupt by the master (Arduino micro).
I can add the code if some one sees it necessary, but because everything works fine with the throttle by it self and in the serial debug mode, I don't think the code for the throttle is relevant for this issue.
Also I don't think it's wiring or hardware issue eihter, because everything works in serial debug mode just fine and consistently. I also have tried different hardware for the pedals with no luck. I am also ruling out power issue, because the bedals don't work with the stick and they have only three 10k potentiometers as the throttle has also three 10k pontentiometers, 4 LED's 10 swithces and a rotary encoder, so it should draw way more power than the pedals and it works with the stick. I am also using UGreen 2A USB cables for the cables between the devices and the shielded USB signal lines for the I2C wires.
I don't know anymore what to try and to do to get this working.
Please help me.
Description of Issue
Hello. I have been trying to build a HOTAS setup with this library, but I am stuck on wierd issue. I have three devices, a stick with Arduino micro, a throttle with Arduino pro mini and pedals with Arduino pro mini. The pedals and throttle are connected to the Arduino micro by I2C and my code recognises what devices are connected by quering the I2C bus and sets the USB joystics accordingly. I have also set up internal serial debugging, that can be accessed by pressing two buttons on the stick when plugin it in the computer. Everything works great at the debug mode and all axis and buttons are working as they should, but if I connect the stick, with pedals connected, to my computer I get USB device not recognized error. If I connect the joysticks to my computer in debug mode and then flash the code to the Arduino micro all three joysticks show up in control panel, but nothing on the throttle is responsive, but the pedals work. If I connect just the throttle to the stick it works as it should. Also if I go to the debug mode and flash the code with only pedals connected, everything works in the control panel, but if I disconnect and reconnect the joystick, I get the USB device not recognized error again. I am really lost with this one. I am thiking it has to be some kind of software issue, because everything is working fine in serial debug mode.
Things I have tried
Adding delay before and/or after the I2C query. Forcing the detected devices to full HOTAS and skipping the I2C query completely. I was thinking that the query would take too long and windows would time out the USB recognition. Using the unmodified library. I modified the library so that it does not create the joystics that are not found in the I2C query. Either option does not change the behaviour. I used a digispark board (AtTiny88) for the pedals. Same behaviour. I have tried different USB ports and different computers. USB 2 and USB 3 in laptop and desktop, no change in behaviour.
Technical Details
Arduino micro, 2 x Arduino pro mini IDE = PlatformIO on VSCode OS = Windows 10 (19043.1889) HP ZBook 15 G2 and a desktop computer. Joystick library version 2.1.0 and 2.1.1
main.cpp
inputs.cpp
inputs.h
i2c.cpp
i2c.h
main.cpp of the pedals
Additional context
I did not add the Arduino pro mini code for the throttle, because this post is way too long already and the code is besically the same as the pedals code. It just polls constantly the ADC's and button pins and responds on the I2C request interrupt by the master (Arduino micro). I can add the code if some one sees it necessary, but because everything works fine with the throttle by it self and in the serial debug mode, I don't think the code for the throttle is relevant for this issue.
Also I don't think it's wiring or hardware issue eihter, because everything works in serial debug mode just fine and consistently. I also have tried different hardware for the pedals with no luck. I am also ruling out power issue, because the bedals don't work with the stick and they have only three 10k potentiometers as the throttle has also three 10k pontentiometers, 4 LED's 10 swithces and a rotary encoder, so it should draw way more power than the pedals and it works with the stick. I am also using UGreen 2A USB cables for the cables between the devices and the shielded USB signal lines for the I2C wires.
I don't know anymore what to try and to do to get this working. Please help me.