arduino due and bar code reader

I need a source code language Arduino programming software to read the codes of a bar code reader with arduino due and display has an LCD display.
thx.

a bar code reader

Can you please give us a clue as to which reader you have in mind ?

leuze electronic
IT 1900g SR-2

should we assume that you have at lrast the lcd part working already?

it is just a standard type with 4-7 data lines or is it the i2c type ?
getting these lcd to work is easy and is very educational....

dan

the bar code reader does not work and the LCD part does not work as.
the lcd is a standard type with 4-7 data lines.

my main problem is the communication between Arduino due and the bar code reader.

The barcode reader looks like it uses USB. How have you got it connected to the Arduino ?

Please post your code that does not work but read this before posting a programming question

Does the barcode reader have a serial option?

I've used two different USB HID type barcode readers with microcontrollers. I had to make my own cable but it wasn't hard to do this.

There's some more information about converting USB barcode readers to TTL output in this Parallax forum post.

this is my source code

#include <LiquidCrystal.h>
#include <avr/pgmspace.h>

#include <hid.h>
#include <hiduniversal.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);
HIDUniversal Hid(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);

class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key);
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(char) key );
lcd.print(char)key );
};

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);
// 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();
}

Sigh....
Did you read this before posting a programming question, especially the part about using code tags ?

okey thx :slight_smile:

DuaneDegn:
Does the barcode reader have a serial option?

Maybe it's because I haven't used an USB host shield, but I was under the impression it's a lot easier to use TTL serial with the Arduino than it is to use USB.

I'm not positive it would be easier, but I hope you at least consider using the barcode reader with a TTL interface.

You don't need a USB shield with a Due, just plug a USB OTG adapter into the native USB port.