Hello everyone
i have downloaded the project (Arduino code modified – Bar Code Scanner and USB Host Shield.) from https://www.electroingenio.com but it didnt work.....
the compile and the upload going well after i have modified the file hid.h to usbhid.h and added USB_ to
parameter : HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
but the barscanner doesn't work, it is beep but no data over serial monitor or LCD.
when i use mouse or keyboard instead barscanner ,it is OK and there is a data in serial mointor and lcd.
i use arduino mega2560 + usb shield host + lcd + barscanner made in china
note: the barscanner works well when i use it with the notpad.
I appreciate your help
thanks.
this is the code :
#include <usbhid.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>
#include <LiquidCrystal_I2C.h> //Download & include the code library can be downloaded below
#define DISPLAY_WIDTH 16
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); // Initialize LCD Display at address 0x27
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<USB_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( 500 );
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( 500 );
}
void loop()
{
Usb.Task();
}