USB host shield, input device and LCD

Hello everybody!

I bought a USB host shield last week and i am trying to connect a barcode scanner.
Luckily for me there are a lot of tutorials in the internet.
The barcode scanner is currently working properly with a some different barcode scanners.
The arduino outputs the code that i scan on the serial monitor.
But i would like to make a stand alone device. Because i can also use the barcode scanner directly connected to my computer.
I tried adding LCD support to the code. But i can't get the data to show op correctly on my LCD.
The data does show up correct on the serial monitor.
The code works without the LCD.
And the LCD works without the rest of the code.

#include <usbhid.h>
#include <usbhub.h>
#include <hiduniversal.h>
#include <hidboot.h>
#include <SPI.h>
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

class MyParser : public HIDReportParser {
  public:
    MyParser();
    void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
  protected:
    uint8_t KeyToAscii(bool upper, uint8_t mod, uint8_t key);
    virtual void OnKeyScanned(bool upper, uint8_t mod, uint8_t key);
    virtual void OnScanFinished();
};

MyParser::MyParser() {}

void MyParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
  // If error or empty, return
  if (buf[2] == 1 || buf[2] == 0) return;

  for (uint8_t i = 7; i >= 2; i--) {
    // If empty, skip
    if (buf[i] == 0) continue;

    // If enter signal emitted, scan finished
    if (buf[i] == UHS_HID_BOOT_KEY_ENTER) {
      OnScanFinished();
    }

    // If not, continue normally
    else {
      // If bit position not in 2, it's uppercase words
      OnKeyScanned(i > 2, buf, buf[i]);
    }

    return;
  }
}

uint8_t MyParser::KeyToAscii(bool upper, uint8_t mod, uint8_t key) {
  // Letters
  if (VALUE_WITHIN(key, 0x04, 0x1d)) {
    if (upper) return (key - 4 + 'A');
    else return (key - 4 + 'a');
  }

  // Numbers
  else if (VALUE_WITHIN(key, 0x1e, 0x27)) {
    return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1');
  }

  return 0;
}

void MyParser::OnKeyScanned(bool upper, uint8_t mod, uint8_t key) {
  delay(250);
  uint8_t ascii = KeyToAscii(upper, mod, key);
  Serial.print((char)ascii);
  lcd.print((char)ascii);
}

void MyParser::OnScanFinished() {
  Serial.println(" - Finished");
}

USB          Usb;
USBHub       Hub(&Usb);
HIDUniversal Hid(&Usb);
MyParser     Parser;

void setup() {
  lcd.begin(16, 2);
  Serial.begin( 115200 );
  Serial.println("Start");
  //lcd.print("Start");

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

  delay( 200 );

  Hid.SetReportParser(0, &Parser);
}

void loop() {
  Usb.Task();
}
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

What pins does the USB host shield use?

#include <SPI.h>

SPI uses pins 13, 12, 11 and in some cases 10 and/or 4. Pin 10 must be an OUTPUT.

I found this page which may have some information of interest. In particular items 6 and 8.

groundFungus:

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);




What pins does the USB host shield use?



#include <SPI.h>




SPI uses pins 13, 12, 11 and in some cases 10 and/or 4. Pin 10 must be an OUTPUT.

Oh of course. The Rs and EN pins are interfering with the usb host shield.
sometimes you need a second pair of eyes.

I switched the RS to 6 and the EN to 7.
Still not what i want but i can use the LCD now.

I already tried using the GPOUT pins. But i couldn't make it work with my arduino using de MAX_LCD library.
So i tried it the other way.

The usb host uses the ISCP pins. It uses SPI to send and receive the data.

Thanks!

Got it al working right now.
i got another device that doesn't support boot protocol.

I can't figure out how to read data from a device like this.
I hope anyone can help me a little bit.

below is the output from the USB_desc

Start


01
--

Device descriptor: 
Descriptor Length:	12
Descriptor type:	01
USB version:		0110
Device class:		00
Device Subclass:	00
Device Protocol:	00
Max.packet size:	40
Vendor  ID:		067B
Product ID:		2303
Revision ID:		0400
Mfg.string index:	01
Prod.string index:	02
Serial number index:	00
Number of conf.:	01

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

Interface descriptor:
Intf.number:		00
Alt.:			00
Endpoints:		03
Intf. Class:		FF
Intf. Subclass:		00
Intf. Protocol:		00
Intf.string:		00

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

Endpoint descriptor:
Endpoint address:	02
Attr.:			02
Max.pkt size:		0040
Polling interval:	00

Endpoint descriptor:
Endpoint address:	83
Attr.:			02
Max.pkt size:		0040
Polling interval:	00


Addr:1(0.0.1)
Vendor  ID: 067B    Prolific
Product ID: 2303    PL2303

You have a USB to UART/serial/RS232 bridge chip. Usually googling for the USB VID and PID tells you what you have. The USB Host Library includes an example for pl2303 devices.