HELP ME TO CONNECT BARCODE SCANNER USB TO ARDUINO UNO

Hello guys, i have a problem here.

i want to connect barcode scanner usb (enibit BS90) to arduino uno using a usb host shield.
and i use this code.

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

    USB BAR CODE SCANNER USB HOST SHIELD TO DISPLAY BARCODE ON LCD
            ADAPTED USING OLEG MAZUROV ARDUINO CODE
 
  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 <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 <LiquidCrystal.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.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);                                          //I enable this line
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  
 
    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.print( (char)key );      //Add char to print correct number in ASCII
    lcd.print( (char)key );          //Add char to print correct number in ASCII
};
 
KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    delay( 200 );
 
    Hid.SetReportParser(0, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"
    // 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();
}

and the result is

if i scan 8994096215986 the result is 949258
if i scan 1 the result is 1
if i scan 1234567890 the result is 24680
if i scan ABCDEFGH the result is ABCDEFGH
if i scan abcdefgh the result is aceg

i use library "USB Host Shield Library 2.0 by Oleq Mazurov(circuits@home) etc version 1.1.0"

and my result from "USB_desc" code is

Start


01
--

Device descriptor: 
Descriptor Length:	12
Descriptor type:	01
USB version:		0200
Device class:		00
Device Subclass:	00
Device Protocol:	00
Max.packet size:	40
Vendor  ID:		1234
Product ID:		5678
Revision ID:		0200
Mfg.string index:	01
Prod.string index:	02
Serial number index:	03
Number of conf.:	01

Configuration descriptor:
Total length:		0029
Num.intf:		01
Conf.value:		01
Conf.string:		00
Attr.:			C0
Max.pwr:		32

Interface descriptor:
Intf.number:		00
Alt.:			00
Endpoints:		02
Intf. Class:		03
Intf. Subclass:		01
Intf. Protocol:		01
Intf.string:		00
Unknown descriptor:
Length:		09
Type:		21
Contents:	110100012241000705

Endpoint descriptor:
Endpoint address:	81
Attr.:			03
Max.pkt size:		0008
Polling interval:	01

Endpoint descriptor:
Endpoint address:	01
Attr.:			03
Max.pkt size:		0008
Polling interval:	20


Addr:1(0.0.1)

what should i do?

I don't know anything about your hardware, but a few comments anyway:

The results you show seem to be correct except for missing characters. Each time you scan 8994096215986 do you always get 949258, or does it vary?

Try running the test sketch for the USB board - examples/board_qc/board_qc.ino

Simplify your configuration to ensure that the problem is just the barcode reader: remove the LCD, remove all the LCD stuff from the sketch. When you get the reader working, then you can add the LCD back in.

arduarn:
I don't know anything about your hardware, but a few comments anyway:

The results you show seem to be correct except for missing characters. Each time you scan 8994096215986 do you always get 949258, or does it vary?

Try running the test sketch for the USB board - examples/board_qc/board_qc.ino

Simplify your configuration to ensure that the problem is just the barcode reader: remove the LCD, remove all the LCD stuff from the sketch. When you get the reader working, then you can add the LCD back in.

Each time i scan 8994096215986, the output in Serial monitor is 949258 or 8906196.

i running this code examples/board_qc/board_qc.ino, this code is for what?

my output in serial monitor is

Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K................ SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
Test failed. Value written: 00 Value read: FF 
Press any key to continue...
GPIO test passed.
PLL test. 100 chip resets will be performed
Resetting oscillator

Reset number 0 Time to stabilize - 291 cycles

Reset number 1 Time to stabilize - 291 cycles

Reset number 2 Time to stabilize - 291 cycles

Reset number 3 Time to stabilize - 291 cycles

Reset number 4 Time to stabilize - 291 cycles

Reset number 5 Time to stabilize - 291 cycles

Reset number 6 Time to stabilize - 291 cycles

Reset number 7 Time to stabilize - 291 cycles

Reset number 8 Time to stabilize - 291 cycles

Reset number 9 Time to stabilize - 291 cycles

Reset number 10 Time to stabilize - 291 cycles

Reset number 11 Time to stabilize - 291 cycles

Reset number 12 Time to stabilize - 291 cycles

Reset number 13 Time to stabilize - 291 cycles

Reset number 14 Time to stabilize - 291 cycles

Reset number 15 Time to stabilize - 292 cycles

Reset number 16 Time to stabilize - 292 cycles

Reset number 17 Time to stabilize - 292 cycles

Reset number 18 Time to stabilize - 291 cycles

Reset number 19 Time to stabilize - 292 cycles

Reset number 20 Time to stabilize - 291 cycles

Reset number 21 Time to stabilize - 291 cycles

Reset number 22 Time to stabilize - 291 cycles

Reset number 23 Time to stabilize - 291 cycles

Reset number 24 Time to stabilize - 291 cycles

Reset number 25 Time to stabilize - 291 cycles

Reset number 26 Time to stabilize - 291 cycles

Reset number 27 Time to stabilize - 291 cycles

Reset number 28 Time to stabilize - 291 cycles

Reset number 29 Time to stabilize - 291 cycles

Reset number 30 Time to stabilize - 292 cycles

Reset number 31 Time to stabilize - 292 cycles

Reset number 32 Time to stabilize - 292 cycles

Reset number 33 Time to stabilize - 292 cycles

Reset number 34 Time to stabilize - 291 cycles

Reset number 35 Time to stabilize - 291 cycles

Reset number 36 Time to stabilize - 291 cycles

Reset number 37 Time to stabilize - 291 cycles

Reset number 38 Time to stabilize - 291 cycles

Reset number 39 Time to stabilize - 291 cycles

Reset number 40 Time to stabilize - 291 cycles

Reset number 41 Time to stabilize - 291 cycles

Reset number 42 Time to stabilize - 291 cycles

Reset number 43 Time to stabilize - 291 cycles

Reset number 44 Time to stabilize - 291 cycles

Reset number 45 Time to stabilize - 291 cycles

Reset number 46 Time to stabilize - 292 cycles

Reset number 47 Time to stabilize - 292 cycles

Reset number 48 Time to stabilize - 292 cycles

Reset number 49 Time to stabilize - 291 cycles

Reset number 50 Time to stabilize - 291 cycles

Reset number 51 Time to stabilize - 291 cycles

Reset number 52 Time to stabilize - 291 cycles

Reset number 53 Time to stabilize - 291 cycles

Reset number 54 Time to stabilize - 291 cycles

Reset number 55 Time to stabilize - 291 cycles

Reset number 56 Time to stabilize - 291 cycles

Reset number 57 Time to stabilize - 291 cycles

Reset number 58 Time to stabilize - 291 cycles

Reset number 59 Time to stabilize - 291 cycles

Reset number 60 Time to stabilize - 292 cycles

Reset number 61 Time to stabilize - 292 cycles

Reset number 62 Time to stabilize - 292 cycles

Reset number 63 Time to stabilize - 292 cycles

Reset number 64 Time to stabilize - 291 cycles

Reset number 65 Time to stabilize - 291 cycles

Reset number 66 Time to stabilize - 291 cycles

Reset number 67 Time to stabilize - 291 cycles

Reset number 68 Time to stabilize - 291 cycles

Reset number 69 Time to stabilize - 291 cycles

Reset number 70 Time to stabilize - 291 cycles

Reset number 71 Time to stabilize - 291 cycles

Reset number 72 Time to stabilize - 291 cycles

Reset number 73 Time to stabilize - 291 cycles

Reset number 74 Time to stabilize - 291 cycles

Reset number 75 Time to stabilize - 291 cycles

Reset number 76 Time to stabilize - 292 cycles

Reset number 77 Time to stabilize - 292 cycles

Reset number 78 Time to stabilize - 292 cycles

Reset number 79 Time to stabilize - 291 cycles

Reset number 80 Time to stabilize - 291 cycles

Reset number 81 Time to stabilize - 291 cycles

Reset number 82 Time to stabilize - 291 cycles

Reset number 83 Time to stabilize - 291 cycles

Reset number 84 Time to stabilize - 291 cycles

Reset number 85 Time to stabilize - 291 cycles

Reset number 86 Time to stabilize - 291 cycles

Reset number 87 Time to stabilize - 291 cycles

Reset number 88 Time to stabilize - 291 cycles

Reset number 89 Time to stabilize - 291 cycles

Reset number 90 Time to stabilize - 292 cycles

Reset number 91 Time to stabilize - 292 cycles

Reset number 92 Time to stabilize - 292 cycles

Reset number 93 Time to stabilize - 292 cycles

Reset number 94 Time to stabilize - 291 cycles

Reset number 95 Time to stabilize - 291 cycles

Reset number 96 Time to stabilize - 291 cycles

Reset number 97 Time to stabilize - 291 cycles

Reset number 98 Time to stabilize - 291 cycles

Reset number 99 Time to stabilize - 291 cycles

Checking USB device communication.

Reset complete. Waiting for the first SOF...
Getting device descriptor
Descriptor Length:	12
Descriptor type:	01
USB version:		0200
Device class:		00
Device Subclass:	00
Device Protocol:	00
Max.packet size:	40
Vendor  ID:		1234
Product ID:		5678
Revision ID:		0200
Mfg.string index:	01
Prod.string index:	02
Serial number index:	03
Number of conf.:	01

All tests passed. Press RESET to restart test

Is your scanning device slow? The lcd gets cleared after 200ms of inactivity. With your code from first post what do you see on the lcd and what do you see on the console ?

J-M-L:
Is your scanning device slow? The lcd gets cleared after 200ms of inactivity. With your code from first post what do you see on the lcd and what do you see on the console ?

sorry, i not using lcd, and this code after i delete a code for lcd..

#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>
#define DISPLAY_WIDTH 16
 
USB     Usb;
USBHub     Hub(&Usb);                                          //I enable this line
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)  
{

    Serial.print( (char)key );      //Add char to print correct number in ASCII
};
 
KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    Hid.SetReportParser(1, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"

}
 
void loop()
{
  Usb.Task();
}

and the output is same.

I suggest using the USBHIDBootKbd example program since you do not want the LCD code. I used this code to experiment with bar code readers and RFID readers that emulate USB keyboards.

gdsports:
I suggest using the USBHIDBootKbd example program since you do not want the LCD code. I used this code to experiment with bar code readers and RFID readers that emulate USB keyboards.

yeah i think my barcode is HID keyboard, because if i connect it too PC, PC read my barcode is in HID keyboard.

i done try the USBHIDBootKbd, but the output in Serial monitor just "start". cant display the barcode.

And it's the output if i use USBHID_desc code...

Start
0000: 05 01 09 06 A1 01 05 07 19 E0 29 E7 15 00 25 01 
0010: 75 01 95 08 81 02 95 01 75 08 81 01 95 03 75 01 
0020: 05 08 19 01 29 03 91 02 95 01 75 05 91 01 95 06 
0030: 75 08 15 00 26 FF 00 05 07 19 00 2A FF 00 81 00 
0040: C0 
Usage Page Gen Desktop Ctrls(01)
Usage Keypad
Collection Application
Usage Page Kbrd/Keypad(07)
Usage Min(E0)
Usage Max(E7)
Logical Min(00)
Logical Max(01)
Report Size(01)
Report Count(08)
Input(00000010)
Report Count(01)
Report Size(08)
Input(00000001)
Report Count(03)
Report Size(01)
Usage Page LEDs(08)
Usage Min(01)
Usage Max(03)
Output(00000010)
Report Count(01)
Report Size(05)
Output(00000001)
Report Count(06)
Report Size(08)
Logical Min(00)
Logical Max(FF00)
Usage Page Kbrd/Keypad(07)
Usage Min(00)
Usage Max(FF00)
Input(00000000)
End Collection

riandanualdy:
Each time i scan 8994096215986, the output in Serial monitor is 949258 or 8906196.

Interesting.

After having browsed the USB_Host_Shield_2.0 library sources, I'm wondering whether both

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

are necessary. HIDBoot seems to be almost like a templated version of HIDUniversal - very similar code. However unlikely it seems, could it even be possible, since Keyboard has no ReportParser attached to it, that it is stealing some characters that then disappear into the bit-bucket?

Try getting you sketch to work with either HIDUniversal or HIDBoot, but not both.

Each time i scan 8994096215986, the output in Serial monitor is 949258 or 8906196.

Probably irrelevant but you seem to be getting ever other digit 8994096215986
Maybe your LCD code is to slow for the OnKeyPressed function and you need to just capture the keycode as quick as possible then display it after.

arduarn:
After having browsed the USB_Host_Shield_2.0 library sources, I'm wondering whether both are necessary. HIDBoot seems to be almost like a templated version of HIDUniversal - very similar code. However unlikely it seems, could it even be possible, since Keyboard has no ReportParser attached to it, that it is stealing some characters that then disappear into the bit-bucket?

Try getting you sketch to work with either HIDUniversal or HIDBoot, but not both.

Do you have a code using HIDUniversal or HIDBoot for me to try the code for my device? sorry im beginner in arduino.

Riva:
Probably irrelevant but you seem to be getting ever other digit 8994096215986
Maybe your LCD code is to slow for the OnKeyPressed function and you need to just capture the keycode as quick as possible then display it after.

look at#4, i post the code without LCD there, and the result is same

Why did you change Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);?

riandanualdy:
look at#4, i post the code without LCD there, and the result is same

But your using Serial.print in there that is equally as slow as LCD.print.

Riva:
But your using Serial.print in there that is equally as slow as LCD.print.

This is not true as the call returns immediately and the buffer is 64 bytes so with the type of numbers the OP wants to print there is no meaningful delay created there

riandanualdy:
Do you have a code using HIDUniversal or HIDBoot for me to try the code for my device? sorry im beginner in arduino.

I didn't mean anything complicated, just a tweak to your existing sketch. So for example this:

#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>
#define DISPLAY_WIDTH 16
 
USB     Usb;
USBHub     Hub(&Usb);                                          //I enable this line
HIDUniversal      Hid(&Usb);                                  //Add this line so that the barcode scanner will be recognized, I use "Hid" below
 
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) 
{

    Serial.print( (char)key );      //Add char to print correct number in ASCII
};
 
KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    Hid.SetReportParser(0, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"

}
 
void loop()
{
  Usb.Task();
}

or this:

#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>
#define DISPLAY_WIDTH 16
 
USB     Usb;
USBHub     Hub(&Usb);                                          //I enable this line
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) 
{

    Serial.print( (char)key );      //Add char to print correct number in ASCII
};
 
KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"

}
 
void loop()
{
  Usb.Task();
}

arduarn:

#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>
#define DISPLAY_WIDTH 16

USB    Usb;
USBHub    Hub(&Usb);                                          //I enable this line
HIDUniversal      Hid(&Usb);                                  //Add this line so that the barcode scanner will be recognized, I use "Hid" below

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)
{

Serial.print( (char)key );      //Add char to print correct number in ASCII
};

KbdRptParser Prs;

void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");

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

Hid.SetReportParser(0, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"

}

void loop()
{
  Usb.Task();
}

I Try this code, and the result is same

arduarn:

#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>
#define DISPLAY_WIDTH 16

USB    Usb;
USBHub    Hub(&Usb);                                          //I enable this line
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)
{

Serial.print( (char)key );      //Add char to print correct number in ASCII
};

KbdRptParser Prs;

void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");

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

Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);        //Here I change  "Keyboard" for "Hid"

}

void loop()
{
  Usb.Task();
}

and for this code, the output just "start" nothing output from barcode scanner

J-M-L:
Why did you change Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);?

Because if i use that code, it's error

This is tricky to solve without the hardware in hand. I suppose it is looking more and more like a timing problem - perhaps the barcode reader is presenting the keystrokes one after the other in rapid fashion without allowing the Arduino sufficient time to collect and process them. Based on this, one final suggestion from me before I give up - and this is just another stab in the dark:

  • Using the working sketch, the HIDUniversal one, compile and verify that it still works but with the missing characters.
  • Go to your libraries folder, into the USB host shield library folder, and open hiduniversal.cpp in your text editor.
  • Find the function EndpointXtract.
  • Find the following lines:
if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
  pollInterval = pep->bInterval;
  • And change them to:
if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
  pollInterval = pep->bInterval;
pollInterval = 3;
  • Save your changes.
  • Go back to your Arduino IDE, and change your board type to Arduino/Genuino Micro, recompile.
  • Change the board type back to Arduino/Genuino Uno and recompile.
  • Check the compile output in the console part of the IDE and ensure that the USB host library has been rebuilt.
  • Upload and test if anything has changed.

arduarn:
This is tricky to solve without the hardware in hand. I suppose it is looking more and more like a timing problem - perhaps the barcode reader is presenting the keystrokes one after the other in rapid fashion without allowing the Arduino sufficient time to collect and process them. Based on this, one final suggestion from me before I give up - and this is just another stab in the dark:

  • Using the working sketch, the HIDUniversal one, compile and verify that it still works but with the missing characters.
  • Go to your libraries folder, into the USB host shield library folder, and open hiduniversal.cpp in your text editor.
  • Find the function EndpointXtract.
  • Find the following lines:
if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints

pollInterval = pep->bInterval;




- And change them to:



if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
  pollInterval = pep->bInterval;
pollInterval = 3;




- Save your changes.
- Go back to your Arduino IDE, and change your board type to *Arduino/Genuino Micro*, recompile.
- Change the board type back to *Arduino/Genuino Uno* and recompile.
- Check the compile output in the console part of the IDE and ensure that the USB host library has been rebuilt.
- Upload and test if anything has changed.

Thanks bro, finally i can read the barcode scanner, and the output is same with the barcode.
and my question is, can you explain me what the meaning of your code give to me?