'HID_PROTOCOL_KEYBOARD' was not declared in this scope

I have working on my project to connect barcode scanner to USB HOST SHIELD.
I use this https://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield/ as a tutorial.

But I got error message when compiled.

'HID_PROTOCOL_KEYBOARD' was not declared in this scope

and I use this library

Here's my code

/*
 
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield and HD44780-compatible LCD display
 
  The circuit:
 * LCD RS pin to digital pin 7
 * LCD Enable pin to digital pin 6
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
*/
 
#include <LiquidCrystal.h>
#include <avr/pgmspace.h>
 
//#include <avrpins.h>
//#include <max3421e.h>
//#include <usbhost.h>
//#include <usb_ch9.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
//#include <address.h>
#include <hidboot.h>
 
//#include <printhex.h>
//#include <message.h>
//#include <hexdump.h>
//#include <parsetools.h>
 
#define DISPLAY_WIDTH 16
 
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
 
USB     Usb;
USBHub     Hub(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
 
class KbdRptParser : public KeyboardReportParser
{
 
protected:
  virtual void OnKeyDown  (uint8_t mod, uint8_t key);
  virtual void OnKeyPressed(uint8_t key);
};
 
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)  
{
    uint8_t c = OemToAscii(mod, key);
 
    if (c)
        OnKeyPressed(c);
}
 
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)  
{
static uint32_t next_time = 0;      //watchdog
static uint8_t current_cursor = 0;  //tracks current cursor position  
 
    if( millis() > next_time ) {
      lcd.clear();
      current_cursor = 0;
      delay( 5 );  //LCD-specific 
      lcd.setCursor( 0,0 );
    }//if( millis() > next_time ...
 
    next_time = millis() + 200;  //reset watchdog
 
    if( current_cursor++ == ( DISPLAY_WIDTH + 1 )) {  //switch to second line if cursor outside the screen
      lcd.setCursor( 0,1 );
    }
 
    Serial.println( key );
    lcd.print( key );
};
 
KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    delay( 200 );
 
    Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
    // set up the LCD's number of columns and rows: 
    lcd.begin(DISPLAY_WIDTH, 2);
    lcd.clear();
    lcd.noAutoscroll();
    lcd.print("Ready");
    delay( 200 );
}
 
void loop()
{
  Usb.Task();
}

I really need help how to solve this problem.

Thank you very much

Why did you comment out the include of usbhost.h and usb_ch9.h? Those were not commented out in the code you pointed to. I suspect that is your problem.

johnwasser:
Why did you comment out the include of usbhost.h and usb_ch9.h? Those were not commented out in the code you pointed to. I suspect that is your problem.

hi johnwasser,
If I don't comment those 2, it will be error message like this

In file included from D:\Works\GUT\Arduino\barcode_scanner\barcode_scanner.ino:24:0:

D:\Works\GUT\Arduino\libraries\USB_Host_Shield_20/usbhost.h:21:2: error: #error "Never include usbhost.h directly; include Usb.h instead"

 #error "Never include usbhost.h directly; include Usb.h instead"

  ^

In file included from D:\Works\GUT\Arduino\barcode_scanner\barcode_scanner.ino:25:0:

D:\Works\GUT\Arduino\libraries\USB_Host_Shield_20/usb_ch9.h:19:2: error: #error "Never include usb_ch9.h directly; include Usb.h instead"

 #error "Never include usb_ch9.h directly; include Usb.h instead"

OK. That makes sense. It also means that the library has been changed significantly since the example you copied was written. Now you have to look for a more recent example to see how the library usage has changed. Maybe there is a new include file you are supposed to use or the name of HID_PROTOCOL_KEYBOARD was changed slightly to fit a new naming convention. Since the failing line is "HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);" I would look in hidboot.h to see if such things were defined in there.

johnwasser:
OK. That makes sense. It also means that the library has been changed significantly since the example you copied was written. Now you have to look for a more recent example to see how the library usage has changed. Maybe there is a new include file you are supposed to use or the name of HID_PROTOCOL_KEYBOARD was changed slightly to fit a new naming convention. Since the failing line is "HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);"I would look in hidboot.h to see if such things were defined in there.

Thank you very much johnwasser.
Problem Solved, You saved my day.

Hello, I'm with the same problem as you. How did you solve it?