# Unable to get data from USB HOST Shield and keyboard

**URL:** <https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752>\
**Category:** 3rd Party Boards\
**Created:** [October 3, 2023, 7:05pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752 "2023-10-03T19:05:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![why-a-cloak-007](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@why-a-cloak-007](https://forum.arduino.cc/u/why-a-cloak-007)\
**Post date:** [October 3, 2023, 7:05pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752/1 "2023-10-03T19:05:39Z")

</div>

Hi all. I am trying to use a USB host shield to read keystrokes from a keyboard, but i am unable to receive any data from the shield. I have the following products

A Arduino Uno  
A USB Host Shield [link](https://www.amazon.com/dp/B07J2KKGZ4?psc=1&ref=ppx_yo2ov_dt_b_product_details)  
A generic keyboard [link](https://www.amazon.com/dp/B09NLS9TK4?psc=1&ref=ppx_yo2ov_dt_b_product_details)  
5V power supply

I already soldered the 3 power pins pads 5v and 5V and 3.3V. I uploaded the USB host shield library and uploaded the USBHIDBootKbd and the serial monitor says start and then when i press any key nothing happens

I tried uncommenting this line //USBHub Hub(&Usb); NO change

I tried using the multimedia keyboard example NO change  
I tried the HID mouse example and No change

keyboard and mouse work.

multi-meter testing  
USB pins have 5V and GND connected  
Vbus is 5V  
Vin is 5V  
5v is 5V  
3.3V is 3.7V

What do I need to do? My plan is to make a Arduino with the keyboard connected and you type a password and it unlocks a relay.

Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 3, 2023, 7:24pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752/2 "2023-10-03T19:24:47Z")

</div>

Please explain how you are trying to receive the data.

Post the code, using code tags, and a wiring diagram showing all connections, with pin designations clearly labeled.

Did you connect the grounds?

---

<div class="post-metadata">

**Author:** ![why-a-cloak-007](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@why-a-cloak-007](https://forum.arduino.cc/u/why-a-cloak-007)\
**Post date:** [October 23, 2023, 9:05pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752/3 "2023-10-23T21:05:30Z")

</div>

I am using the Serial Monitor.

I am using this code from the library USB Host library 2

```arduino
#include <hidboot.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

class KbdRptParser : public KeyboardReportParser
{
    void PrintKey(uint8_t mod, uint8_t key);

  protected:
    void OnControlKeysChanged(uint8_t before, uint8_t after);

    void OnKeyDown	(uint8_t mod, uint8_t key);
    void OnKeyUp	(uint8_t mod, uint8_t key);
    void OnKeyPressed(uint8_t key);
};

void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
{
  MODIFIERKEYS mod;
  *((uint8_t*)&mod) = m;
  Serial.print((mod.bmLeftCtrl == 1) ? "C" : " ");
  Serial.print((mod.bmLeftShift == 1) ? "S" : " ");
  Serial.print((mod.bmLeftAlt == 1) ? "A" : " ");
  Serial.print((mod.bmLeftGUI == 1) ? "G" : " ");

  Serial.print(" >");
  PrintHex<uint8_t>(key, 0x80);
  Serial.print("< ");

  Serial.print((mod.bmRightCtrl == 1) ? "C" : " ");
  Serial.print((mod.bmRightShift == 1) ? "S" : " ");
  Serial.print((mod.bmRightAlt == 1) ? "A" : " ");
  Serial.println((mod.bmRightGUI == 1) ? "G" : " ");
};

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
  Serial.print("DN ");
  PrintKey(mod, key);
  uint8_t c = OemToAscii(mod, key);

  if (c)
    OnKeyPressed(c);
}

void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) {

  MODIFIERKEYS beforeMod;
  *((uint8_t*)&beforeMod) = before;

  MODIFIERKEYS afterMod;
  *((uint8_t*)&afterMod) = after;

  if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) {
    Serial.println("LeftCtrl changed");
  }
  if (beforeMod.bmLeftShift != afterMod.bmLeftShift) {
    Serial.println("LeftShift changed");
  }
  if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) {
    Serial.println("LeftAlt changed");
  }
  if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) {
    Serial.println("LeftGUI changed");
  }

  if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) {
    Serial.println("RightCtrl changed");
  }
  if (beforeMod.bmRightShift != afterMod.bmRightShift) {
    Serial.println("RightShift changed");
  }
  if (beforeMod.bmRightAlt != afterMod.bmRightAlt) {
    Serial.println("RightAlt changed");
  }
  if (beforeMod.bmRightGUI != afterMod.bmRightGUI) {
    Serial.println("RightGUI changed");
  }

}

void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
{
  Serial.print("UP ");
  PrintKey(mod, key);
}

void KbdRptParser::OnKeyPressed(uint8_t key)
{
  Serial.print("ASCII: ");
  Serial.println((char)key);
};

USB Usb;
//USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);

KbdRptParser Prs;

void setup()
{
  Serial.begin( 115200 );
#if !defined( __MIPSEL__ )
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");

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

  delay( 200 );

  HidKeyboard.SetReportParser(0, &Prs);
}

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

```

---

<div class="post-metadata">

**Author:** ![why-a-cloak-007](https://avatars.discourse-cdn.com/v4/letter/w/3da27b/32.png) [@why-a-cloak-007](https://forum.arduino.cc/u/why-a-cloak-007)\
**Post date:** [October 24, 2023, 8:14pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752/4 "2023-10-24T20:14:10Z")

</div>

So i reread the library page and realized it said it needs a Arduino Leonardo or 32u4 or SAMD board. I got a Arduino Leonardo and uploaded the keyboard sketch and it works. Thank you for the help!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [April 21, 2024, 8:14pm UTC](https://forum.arduino.cc/t/unable-to-get-data-from-usb-host-shield-and-keyboard/1174752/5 "2024-04-21T20:14:48Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
