USB host Shield Problem

Hello,
I want to make a project barcode scanning device, in which barcode scanner scans the barcode then sends it to mobile app.
The basic flow is as follows:
Barcode scanner → USB host sheld → Arduino Mega 2560 → Bluetooth module HC-05 → Mobile app.
I took the code from www.electroingenio.com
But there is some error which i can’t understand so plz help.

Code:

/* ****************************** www.electroingenio.com **********************************/

#include <hid.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <hiduniversal.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.h>

USB Usb;
USBHub Hub(&Usb); //I enable this line
String codeString;
char z;
int cont = 0;
String readString;

HIDUniversal Hid(&Usb); //Add this line so that the barcode scanner will be recognized, I use “Hid” below
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);

class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key); // Add this line to print character in ASCII
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

z=((char)key); // Read characters that arrive from serial port
codeString += z; //each character builds in a string
cont = cont+1;

if (char(key)== 19) { //verify the las digit of the scanner
codeString.remove(cont-1); //Remove the last digit
Serial.println(codeString); //Printing the complete code
codeString=""; // Clear string codestring
cont=0; // Reset the counter
}

}

KbdRptParser Prs;

void setup()
{
Serial.begin( 9600 );
Serial.println(“Start”);

if (Usb.Init() == -1) {
Serial.println(“OSC did not start.”);
}

Hid.SetReportParser(0, (HIDReportParser*)&Prs); //Here I change “Keyboard” for “Hid”
delay( 200 );
}

void loop()
{
Usb.Task();

}

Error:

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:165:2: error: ‘USBHost’ does not name a type

USBHost *pUsb; // USB class instance pointer

^

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:182:14: error: expected ‘)’ before ‘*’ token

HID(USBHost *pusb) : pUsb(pusb) {};

^

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:184:8: error: ‘USBHost’ does not name a type

const USBHost* GetUsb() { return pUsb; };

^

In file included from C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hiduniversal.h:21:0,

from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:5:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/usbhid.h:119:8: error: redefinition of ‘struct HidItemPrefix’

struct HidItemPrefix {

^

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:98:8: error: previous definition of ‘struct HidItemPrefix’

struct HidItemPrefix // Not used

^

In file included from C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hiduniversal.h:21:0,

from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:5:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/usbhid.h:125:8: error: redefinition of ‘struct MainItemIOFeature’

struct MainItemIOFeature {

^

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:131:8: error: previous definition of ‘struct MainItemIOFeature’

struct MainItemIOFeature // Not used

^

In file included from C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hiduniversal.h:21:0,

from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:5:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/usbhid.h:138:7: error: redefinition of ‘class HIDReportParser’

class HIDReportParser {

^

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:150:7: error: previous definition of ‘class HIDReportParser’

class HIDReportParser

^

BCS_ardu:62: error: cannot declare variable ‘Prs’ to be of abstract type ‘KbdRptParser’

KbdRptParser Prs;

^

C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:26:7: note: because the following virtual functions are pure within ‘KbdRptParser’:

class KbdRptParser : public KeyboardReportParser

^

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:153:15: note: virtual void HIDReportParser::Parse(HID*, bool, uint32_t, uint8_t*)

virtual void Parse(HID *hid, bool is_rpt_id, uint32_t len, uint8_t *buf) = 0;

^

In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:11:0:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hidboot.h: In instantiation of ‘uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() [with unsigned char BOOT_PROTOCOL = 1u; uint8_t = unsigned char]’:

C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:82:1: required from here

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hidboot.h:595:41: error: no matching function for call to ‘HIDReportParser::Parse(USBHID*, int, uint8_t, uint8_t [16])’

pRptParser->Parse((USBHID*)this, 0, (uint8_t)read, buf);

  • ^*
    C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hidboot.h:595:41: note: candidate is:
    In file included from C:\Users\d\Documents\Arduino\BCS_ardu\BCS_ardu.ino:4:0:
    C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:153:15: note: virtual void HIDReportParser::Parse(HID*, bool, uint32_t, uint8_t*)
    virtual void Parse(HID *hid, bool is_rpt_id, uint32_t len, uint8_t *buf) = 0;
  • ^*
    C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20/hid.h:153:15: note: no known conversion for argument 1 from ‘USBHID*’ to ‘HID*’
    exit status 1
    cannot declare variable ‘Prs’ to be of abstract type ‘KbdRptParser’

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

C:\Users\d\Documents\Arduino\libraries\USB_Host_Shield_20

You also need to tell us where you got that library.