[SOLVED] USBHostShield Arduino Mega Joystick - wrong IDE-Version

Hello :slight_smile:

I do have some trouble with the USBHIDJoystick library and need some help…

I get the following compiler failure:

In file included from hidjoystickrptparser.cpp:1:
hidjoystickrptparser.h:34: error: 'USBHID' has not been declared
hidjoystickrptparser.cpp:11: error: variable or field 'Parse' declared void
hidjoystickrptparser.cpp:11: error: 'USBHID' was not declared in this scope
hidjoystickrptparser.cpp:11: error: 'hid' was not declared in this scope
hidjoystickrptparser.cpp:11: error: expected primary-expression before 'bool'
hidjoystickrptparser.cpp:11: error: expected primary-expression before 'len'
hidjoystickrptparser.cpp:11: error: expected primary-expression before '*' token
hidjoystickrptparser.cpp:11: error: 'buf' was not declared in this scope

Here the .ino:

#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>

#include "hidjoystickrptparser.h"

USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);

void setup() {
#if !defined(__MIPSEL__)
        while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection

        if (Usb.Init() == -1)
                Serial.println("OSC did not start.");


        if (!Hid.SetReportParser(0, &Joy))
                ErrorMessage<uint8_t > (PSTR("SetReportParser"), 1);

void loop() {

Here the .h

#undef __USBHID_H__
#include <usbhid.h>
#include <hiduniversal.h>
#include <hidescriptorparser.h>

#include <inttypes.h>

struct GamePadEventData {
        uint8_t X, Y, Z1, Z2, Rz;

class JoystickEvents {
        virtual void OnGamePadChanged(const GamePadEventData *evt);
        virtual void OnHatSwitch(uint8_t hat);
        virtual void OnButtonUp(uint8_t but_id);
        virtual void OnButtonDn(uint8_t but_id);

#define RPT_GEMEPAD_LEN		5

class JoystickReportParser : public HIDReportParser {
        JoystickEvents *joyEvents;

        uint8_t oldPad[RPT_GEMEPAD_LEN];
        uint8_t oldHat;
        uint16_t oldButtons;

        JoystickReportParser(JoystickEvents *evt);

        virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);


I don’t understand, why the compiler is not able to find the USBHID.
Some got a solution?

Thanks :slight_smile:

is this the shield you are using?

which library did you pick?


sorry for late.

I use the Arduino USBHostShield IDE Version: 1.0.5-r2 Library from Kristian Lauszus and Andrew Kroll from github

The PS4 Sketch compiles.

Attached is a screenshot from the compilerfailure:

Try doing this

  • quit Arduino IDE

  • go to your file system and remove the USB_Host_Shield_2.0 library from your arduino libraries folder (assuming you added it automatically from the library manager, it seems not all files get installed).

  • go to the Revision 2.0 of USB Host Library for Arduino

  • click the download .zip

  • unzip the file on your desktop, you will get a directory called

  • rename it by removing the -master into just USB_Host_Shield_2.0

  • move that full directory into your arduino libraries folder

  • launch the IDE

  • go to examples and navigate to USBHIDJoystick as per picture below

and open that example. You will notice the sketch starts with

#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>


#include "hidjoystickrptparser.h"

which sounds very much like your code

you will find in the example folder (and associated to the sketch) the hidjoystickrptparser.h and hidjoystickrptparser.cpp that you could not find.

check compiling that example. if that compiles fine, then that’s what you probably need for your own code.

Thanks. I¬īll give it a try...

I'll call you right back.


Now I get the following failure:

C:\Users\...\Documents\Arduino\libraries\USB_Host_Shield_20\PS3BT.cpp: In member function 'float PS3BT::getAngle(AngleEnum)':
C:\Users\...\Documents\Arduino\libraries\USB_Host_Shield_20\PS3BT.cpp:107: error: 'atan2f' was not declared in this scope
C:\Users\...\Documents\Arduino\libraries\USB_Host_Shield_20\PS3BT.cpp:109: error: 'atan2f' was not declared in this scope

I included the math.h and arduino.h

in the hidjoystickrptparser.h

but the failure is still the same.

Do you have any idea what is wrong? What IDE-Version do you have?

I don't think you have to mess with hidjoystickrptparser.h nor hidjoystickrptparser.cpp, just make sure they are part of your project

Can you post your full code

I still do not have some code.

For now I only want to compile the examplesketch USBHIBJoystick.

Some else asked the same question but become no answer: https://www.circuitsathome.com/mcu/arduino/interfacing-ps3-controllers-via-usb

Are you opening it up from the examples?

can you make sure the 2 other files are also opened within the IDE??


it just compiles fine with my environment - no error at all...

that’s really strange…

what IDE-Version do you use?

Tomorrow I will download a newer version.

Thank you very much - I will report.

well yes that sounds very weird. Reinstall the IDE to ensure you have the latest libs, use the automated library update process to ensure you have everything up to date and download the library as suggest above and manually install (when I tried to install with the library tools I was missing usbhid.h.

Hello J-M-L,

I downloaded the 1.6.8 version and now it works fine.

I think the old version doesn¬īt work with the new libraries.

Thank you very much for your support and your time.

Can I close the Thread? Show it as resolved?

Its not mentioned in How to use this forum

Good news

I think you can just update the title of your post and add "SOLVED" in the text