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.06k stars 403 forks source link

Rduino nano 33IoT error #284

Closed cutePsych0 closed 4 months ago

cutePsych0 commented 4 months ago

Description of Issue

i tried to do a test file by myself with just 2 buttons to test if it is working with a Arduino nano 33IoT

Technical Details

Sketch File that Reproduces Issue


// USB Joystick with hall effect sensors
// NOTE: This sketch file is for use with Arduino Leonardo and
//       Arduino Micro only.
//------------------------------------------------------------

//change these to define which pins your hall effect sensors or potentiometers are connected.
//to change button connections, scroll down to loop()
#define X_PIN A1
#define Y_PIN A0
#define R_PIN A3
#define T_PIN A2
//change these to change trim and limits. Calibrating your joystick in Windows achieves the same thing
#define X_MIN 0
#define X_MAX 1023
#define X_TRIM 0
#define X_INVERT 1
//to invert an axis, change 1 to -1
#define Y_MIN 0
#define Y_MAX 1023
#define Y_TRIM 0
#define Y_INVERT 1

#define R_MIN 0
#define R_MAX 1023
#define R_TRIM 0
#define R_INVERT 1

#define T_MIN 0
#define T_MAX 1023
#define T_TRIM 0
#define T_INVERT 1

#include <Joystick.h>

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

void setup() {
  // Initialize Button Pins
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);

  // Initialize Joystick Library
  Joystick.begin(false); //false = dont send automatically. We will sendState() at the end of the loop
  Joystick.setXAxisRange(-512, 512);
  Joystick.setYAxisRange(-512, 512);
  Joystick.setRudderRange(-512, 512);
  Joystick.setThrottleRange(-512, 512);
}

void loop() {
  //read buttons. Change pins and button numbers here, if you want to have different number connected to different pin
  Joystick.setButton(0, !digitalRead(2)); //pin 2 LOW means button 0 PRESSED
  Joystick.setButton(1, !digitalRead(3)); //etc.
  //Joystick.setButton(2, !digitalRead(5)); // build as much buttons as defined on "Joystick_ Joystick" like above
  //Joystick.setButton(1, !digitalRead(3)); //arduino input on btn. 3 means aktivate btn. 1 in HID

  //read analog axes and maps them 
  int value = map(analogRead(X_PIN) + X_TRIM , X_MIN, X_MAX, -512, 512) * X_INVERT; //means: read value from "x_pin" defined at the beginning, its pin A1 on the board. + includeing the trim and min/max and invert value.
  Joystick.setXAxis(value);
  value = map(analogRead(Y_PIN) + Y_TRIM , Y_MIN, Y_MAX, -512, 512) *Y_INVERT;
  Joystick.setYAxis(value);
  value = map(analogRead(R_PIN) + R_TRIM , R_MIN, R_MAX, -512, 512) * R_INVERT;
  Joystick.setRudder(value);
  value = map(analogRead(T_PIN) + T_TRIM , T_MIN, T_MAX, -512, 512) * T_INVERT;
  Joystick.setThrottle(value);

  Joystick.sendState();
  delay(10);
}

Wiring Details

using a breakboard pinned GND beside D2, to two simple 6x6x3.1 switches. pinned one on D2 and one on D3 but the issue was while trying to write the sketch to my arduino.

Additional context

i added the Joystick.h to my ide via "add .ZIP Libary" i tried to rebuild a joystick similar to Akaki Kuumeri on youtube.

https://www.youtube.com/watch?v=YAbi_AqF7aQ&list=PLdStXpG701Ry58JuoveyxG2pqgKkEQJHr&index=25 this was my example fle to try to understand how it is working. but it seems like something happens with the Jostick.h libary. it throws arror: In file included from C:\Users\natal\Documents\Arduino\libraries\Joystick\src/Joystick.h:24:0, from D:\Arduino IDE projekts and saves\joystick_learning\joystick_learning.ino:35: C:\Users\natal\Documents\Arduino\libraries\Joystick\src/DynamicHID/DynamicHID.h:37:12: fatal error: PluggableUSB.h: No such file or directory

include "PluggableUSB.h"

        ^~~~~~~~~~~~~~~~

compilation terminated. exit status 1

Compilation error: exit status 1

cutePsych0 commented 4 months ago

nvm i found the previous issue from another dude. i read your answer. i guess i will simply but a micro or other arduino for it