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?