MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.07k stars 403 forks source link

With two boards, only the first will be recognized #183

Open snooops opened 3 years ago

snooops commented 3 years ago

Description of Issue

If connect two boards with different sketches, but bot uses the arduino joystick library, only the first one which is attached to the pc will work as gamecontroller. The second one will produce a windows error if you go into the settings. Something like: The Gamecontroller isn't attached correctly. PLease check if its attached proper.

Technical Details

Sketch File that Reproduces Issue

// USB 5 AXIS Controller 
// Use with Arduino Leonardo or ProMicro.
// Install Joystick library

// AMSTUDIO 2018
// YT https://www.youtube.com/channel/UCQS1ZB3BVSrBo3tCs7PyfxQ
// Wiring + Setup https://youtu.be/iKIrbF6GnZ0
// Copyright _ Non Commerical_ Not for Resale https://creativecommons.org/licenses/by-nc-nd/4.0/ 

#include <Joystick.h>

Joystick_ Joystick(0x04,JOYSTICK_TYPE_GAMEPAD,
  0, 0,                  // Button Count, Hat Switch Count
  false, false, true,     // X and Y, but no Z Axis
  false, false, false,   // No Rx, Ry, or Rz
  false, true,          // No rudder or throttle
  false, true, false);  // No accelerator, brake, or steering

int throttle = 0;
int brake = 0;
int clutch = 0;

const bool initAutoSendState = true; 

void setup()
{
      Joystick.begin();
  }

void loop(){
  throttle = analogRead(A0);
  throttle = map(throttle,1023,0,255,0);
  Joystick.setThrottle(throttle);

  brake = analogRead(A1);
  brake = map(brake,0,1023,0,255);
  Joystick.setBrake(brake);

  clutch = analogRead(A2);
  clutch = map(clutch,1023,0,255,0);
  Joystick.setZAxis(clutch);

delay (50);
}

//AMSTUDIO Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
Rav3nX commented 3 years ago

Read the documentation.

uint8_t hidReportId - Default: 0x03 - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use 0x01 or 0x02 as they are used by the built-in Arduino Keyboard and Mouse libraries.

In the beginning of the sketch this ID must be set if you intend to run multiple devices.