Library Inclusion Issue

I am trying to use my Logitech Extreme 3D joystick with a Keyes USB host shield and Mega board. I downloaded a library in order to do this from here (USBJoystick: Arduino USB Interface to USB joystick/game pad). I open the example file to make sure everything was dandy and tried to compile it. I got a message saying, "compilation terminated. exit status 1 error compiling."

I then opened a new document and included the library (went to sketch/include library/ USBJoystick) and this compilation here:

![](http://Image and video hosting by TinyPic)

/and got a likewise response. I have not had this issue with including a library before. and would like help.

Do you know of any better library to do this with? I know there are alot out there for USB joysticks with shields and Arduino.

I get these compiler warnings but otherwise it compiles OK:

/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp: In member function 'void USBJoystick::setButtonNewValueCallback(void (*)(uint8_t, uint8_t))':
/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp:237:26: warning: invalid conversion from 'void (*)(uint8_t, uint8_t) {aka void (*)(unsigned char, unsigned char)}' to 'void (*)(uint8_t, boolean) {aka void (*)(unsigned char, bool)}' [-fpermissive]
     _button_new_value_cb = cb;
                          ^
/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp: In member function 'void USBJoystick::setButtonValueDidChangeCallback(void (*)(uint8_t, uint8_t))':
/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp:249:33: warning: invalid conversion from 'void (*)(uint8_t, uint8_t) {aka void (*)(unsigned char, unsigned char)}' to 'void (*)(uint8_t, boolean) {aka void (*)(unsigned char, bool)}' [-fpermissive]
     _button_value_did_change_cb = cb;
                                 ^

Sketch uses 5,676 bytes (17%) of program storage space. Maximum is 32,256 bytes.
Global variables use 447 bytes (21%) of dynamic memory, leaving 1,601 bytes for local variables. Maximum is 2,048 bytes.

If you get errors instead of warnings you should copy and paste the messages here so we have some hope of helping. Your image is not appearing.

It appears my image didn't attach. Here is an alternative link from tiny pic.

johnwasser:
I get these compiler warnings but otherwise it compiles OK:

/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp: In member function 'void USBJoystick::setButtonNewValueCallback(void (*)(uint8_t, uint8_t))':

/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp:237:26: warning: invalid conversion from 'void ()(uint8_t, uint8_t) {aka void ()(unsigned char, unsigned char)}' to 'void ()(uint8_t, boolean) {aka void ()(unsigned char, bool)}' [-fpermissive]
_button_new_value_cb = cb;
^
/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp: In member function 'void USBJoystick::setButtonValueDidChangeCallback(void ()(uint8_t, uint8_t))':
/Users/john/Documents/Arduino/libraries/USBJoystick/USBJoystick.cpp:249:33: warning: invalid conversion from 'void (
)(uint8_t, uint8_t) {aka void ()(unsigned char, unsigned char)}' to 'void ()(uint8_t, boolean) {aka void (*)(unsigned char, bool)}' [-fpermissive]
_button_value_did_change_cb = cb;
^

Sketch uses 5,676 bytes (17%) of program storage space. Maximum is 32,256 bytes.
Global variables use 447 bytes (21%) of dynamic memory, leaving 1,601 bytes for local variables. Maximum is 2,048 bytes.




If you get errors instead of warnings you should copy and paste the messages here so we have some hope of helping. Your image is not appearing.

I typed out the error verbatim so there isn't any chance I got a different error message.

Please copy the text of the error message - your picture only shows the very bottom of the error message, the part that's the same for any compile error. You need to show us the entire output. You can click the copy error messages button to copy all the text of the error messages to the clipboard, and paste it into the forum.

Be sure to enclose it in code tags so it's easy for people to read (use the </> button in top left).

In file included from C:\Users\troyc\Desktop\sketch_nov19a\sketch_nov19a.ino:1:0:

C:\Users\troyc\Documents\Arduino\libraries\USBJoystick/USBJoystick.h:97:32: fatal error: Max3421e_constants.h: No such file or directory

 #include "Max3421e_constants.h"

                                ^

compilation terminated.

exit status 1
Error compiling.

Thank-you, I did not know what was up there was included. Here I though tit was past error messages.

You forgot to read the instructions:

Requires:
SparkFun USB Host Shield
USB_Host_Shield library. Install this in your libraries folder with a command like:
git clone git://github.com/felis/USB_Host_Shield.git

The problem is you didn't install the USB_Host_Shield library. If you are not using git or don't want to clone the repository you can do this to install the USB_Host_Shield library:

It appears we have made some progress- ( If anything educating me :slight_smile: ). Here are the updated errors.

Here is my code

#include <ch9.h>
#include <Max3421e.h>
#include <Max3421e_constants.h>
#include <Max_LCD.h>
#include <Usb.h>

#include <USBJoystick.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

:; and here is my error message

Arduino: 1.6.6 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\troyc\Documents\Arduino\libraries\USBJoystick\USBJoystick.cpp: In member function 'void USBJoystick::setButtonNewValueCallback(void (*)(uint8_t, uint8_t))':

C:\Users\troyc\Documents\Arduino\libraries\USBJoystick\USBJoystick.cpp:237:26: error: invalid conversion from 'void (*)(uint8_t, uint8_t) {aka void (*)(unsigned char, unsigned char)}' to 'void (*)(uint8_t, boolean) {aka void (*)(unsigned char, bool)}' [-fpermissive]

     _button_new_value_cb = cb;

                          ^

C:\Users\troyc\Documents\Arduino\libraries\USBJoystick\USBJoystick.cpp: In member function 'void USBJoystick::setButtonValueDidChangeCallback(void (*)(uint8_t, uint8_t))':

C:\Users\troyc\Documents\Arduino\libraries\USBJoystick\USBJoystick.cpp:249:33: error: invalid conversion from 'void (*)(uint8_t, uint8_t) {aka void (*)(unsigned char, unsigned char)}' to 'void (*)(uint8_t, boolean) {aka void (*)(unsigned char, bool)}' [-fpermissive]

     _button_value_did_change_cb = cb;

                                 ^

exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

You can probably solve your issue by updating your Arduino IDE to 1.6.12. The version of Arduino AVR Boards included with that IDE version has changed that error to a warning so it does compile but I haven't tested to check if it actually works. Even if it does work these errors indicate the author of the library isn't writing very good code. All those warnings could easily be fixed with just a little bit of effort. I could give you instructions for fixing the code in the library but that's kind of a hassle since you need to redo the modifications anytime you update to a new version of the library. So give it a try as is. I think it will work fine after the IDE update. Arduino IDE 1.6.6 was a terrible version so you're better off updating either way.

Success!!I got this code to work (it is the sample from the joystick library with the inclusion of the shield libraries)::

#include <ch9.h>
#include <Max3421e.h>
#include <Max3421e_constants.h>
#include <Max_LCD.h>
#include <Usb.h>

// usbjoystick_test
// This sketch demonstrates simple use of the USBJoystick library
// It intialises the library, establishes callbacks for when inputs change
// and prints out details whenever an input changes and a callback is called.
//
// USB Host Shield uses an interrupt line, but does not establish an interrupt callback
// Note special requirements in documentation if you are using an older version of the USB Host Shield and a newer
// version of the USB_Host_Shield library.
// Note special requirements to configure the WiShield librray to support the UDP application.
// mikem@airspayce.com

#include <Usb.h>
#include <USBJoystick.h>

// Our singleton joystick
USBJoystick joy;

// Here we define some callbacks thgat will be called when a stick, button
// or hat switch changes. You can also have a callback called for every polled value, if you prefer.
// Alternatively, you can use the *Value() data accessory to asynchronously get the last read value
// for the sticks, buttons and hats.

// stick will be one of USBJOYSTICK_STICK_*
void stickValueDidChangeCallback(uint8_t stick, uint8_t value)
{
  Serial.print("stickValueDidChangeCallback: ");
  Serial.print(stick, DEC);
  Serial.print(": ");
  Serial.print(value, DEC);
  Serial.println("");
}
// button will be one of USBJOYSTICK_BUTTON_*
void buttonValueDidChangeCallback(uint8_t button, uint8_t value)
{
  Serial.print("buttonValueDidChangeCallback: ");
  Serial.print(button, DEC);
  Serial.print(": ");
  Serial.print(value, DEC);
  Serial.println("");
}
// hat will be one of USBJOYSTICK_HAT_*
// value will be one of USBJOYSTICK_HAT_POS_*
void hatValueDidChangeCallback(uint8_t hat, uint8_t value)
{
  Serial.print("hatValueDidChangeCallback: ");
  Serial.print(hat, DEC);
  Serial.print(": ");
  Serial.print(value, DEC);
  Serial.println("");
  if ( hat == 0 && value == 1) {
    Serial.print("TRIGGER OFF!!!!");
  }
}

void setup()
{
  Serial.begin(9600);

  // Specify callbacks to call when inputs change
  joy.setStickValueDidChangeCallback(stickValueDidChangeCallback);
  joy.setButtonValueDidChangeCallback(buttonValueDidChangeCallback);
  joy.setHatValueDidChangeCallback(hatValueDidChangeCallback);
  joy.init();
}

void loop()
{
  joy.run();
}

There is no longer an issue with the including the library. I am still having a few issues:

(1)- There seems to be an issue with the library and my Logitech Extreme 3d pro joystick. I have a feeling the c++ program was written for another joystick. Here is a mapping of the buttons so you know what I am talking about.

![](Google?
hl=en&site=imghp&tbm=isch&source=hp&biw=1367&bih=674&q=logitech+extreme+3d+pro&oq=logitech+extr&gs_l=img.1.0.0l8j0i30k1l2.1283.4464.0.5885.15.11.1.3.3.0.180.1276.0j9.9.0....0...1ac.1.64.img..2.12.1161.LbOtHmRU_5E#imgdii=zaSm4p0ZuxBMTM%3A%3BzaSm4p0ZuxBMTM%3A%3BwgYAc7rKLzxWgM%3A&imgrc=zaSm4p0ZuxBMTM%3A)

-the trigger button (1) and thumb button (2) get marked as hat values.
-What I am calling the throttle gets marked as many different button values.
-Buttons 9, 10, & 11 don't leave a response.
-The other buttons get marked as different ones then Logitech claims they are (which is really a simple thing to solve)

(2)- Every few times I upload the code to the Mega, about 1/3 of the time, I get an error message and then try again without changing anything and it works. Here is said message::

Arduino: 1.6.11 (Windows Store 1.6.11.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

collect2.exe: error: ld returned 5 exit status

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This issue is more of a pothole than a road block but I would like to get this issue resolved.

The other thing I am open to suggestions for is the joystick is really sensitive and Serial.prints tons of stickvaluedidchangecallback. I have solved this by turning these serial.prints into comments but I wanted to know if there is a better way to make the stick values legible.

Troymako:
Success!!

Glad to hear, so I guess the IDE update did work.

Troymako:

Arduino: 1.6.11 (Windows Store 1.6.11.0)

Was 1.6.11 the latest version available from the Windows Store? I remember reading that the version was behind on there but would hope they had gotten that fixed by now since 1.6.12 was released 2 months ago. That's pretty weird they have a specific Windows Store version, makes no sense to me.

Troymako:

collect2.exe: error: ld returned 5 exit status

Usually that error is caused by using Windows XP but you are on Windows 10. Very strange, I haven't seen that before. You could try enabling verbose output during compilation(File > Preferences > Show verbose output on: > compilation(check)) to see if that will give you any clues. I'd recommend trying the standard IDE installation to see if it's something specific to the Windows Store version.

Troymako:
the joystick is really sensitive and Serial.prints tons of stickvaluedidchangecallback. I have solved this by turning these serial.prints into comments but I wanted to know if there is a better way to make the stick values legible.

It sounds like you only want them to print when there has been a significant change right? I'm not familiar with the library so I don't know if it has any kind of integrated mechanism for adjusting sensitivity but you can do it in the sketch like so:

const uint8_t printStickValueChangeThreshold = 10;  //you can adjust sensitivity by changing this value
const uint8_t stickCount = 2;  //I don't know how many sticks there are so change this to suit your hardware
uint8_t previousStickValue[stickCount];

void stickValueDidChangeCallback(uint8_t stick, uint8_t value)
{
  if (abs(value - previousStickValue[stick]) > printStickValueChangeThreshold)
  {
    previousStickValue[stick] = value;
    Serial.print("stickValueDidChangeCallback: ");
    Serial.print(stick, DEC);
    Serial.print(": ");
    Serial.print(value, DEC);
    Serial.println("");
  }
}