USB Host Shield 2.0 Library (code) question.. (basics/beginner)

I am using a USB Host (Mini) Shield from Circuits @ Home:

And the library from here:

I am simply trying to connect a USB keyboard to this and use that for input in certain devices and/or PC's..

I have the USB Host Mini shield (with the +5v VBUS mod/jumper implemented to power the keyboard)

I have successfully ran the board_qc sketch, and gotten a response. Which tells me hardware wise, I am set-up correctly...

I then uploaded the USBHIDBootKbd example…

Here are my questions/behavior I want to test/add to the USBHIDBootKbd example.

1.) I took the USB keyboard, and plugged it into my laptop to test things out.

a.) when I plug the keyboard in normally, (without USB Host shield), both the laptop keyboard & the USB keyboard both ‘type’ text in the open application (notepad for example)

b.) when I plug in the USB keyboard using the USB Host shield (and the USBHIDBootKbd example sketch loaded).. I see the data in the serial monitor:

Start
DN >0A05<
ASCII: b
..etc..etc.

but the USB keyboard doesnt type/pass anything through to the applicaiton (notepad was used again and was in focus).. although I could still see the serial monitor data coming through? Is there a specific method/function/command to actually send the data/text typed from the USB keyboard TO the PC/application?

2.) Is there a way to stop all data from passing over to the PC/application/device?

Example: if I have a button/switch connected to an open/free I/O pin.. and when pressed, it stops all keypresses from being passed to the PC/device/app

3.) Can you conditionally chek the kaypress/data that is being sent and choose to send it or not? or even replace it?

Example 1:
If I press 'P', can I detect that shift + p keys were presssed/sent, and then NOT send it at all.. (skipping/discarding it, while continuing along with the rest of the text/data being sent to the PC/device?

Example 2:
If I press the character/key 'p', can I detect that, and then always send a capital 'P' *or another character, any character for that matter (say the 'o' character for example)

4.) As a first step,…when looking at the example sketch, I am was not sure where to 'hook' in, to start checking the 'character/data' being sent..

I tried to add this to the OnKeyPressed() function..

mykey = (char)key;
if(mykey == "p"){
//Keyboard.print("M");
Serial.println("P");
}

but I get this error:

ISO C++ forbids comparison between pointer and integer [-fpermissive], but I am not sure how?

I have a background in WEB programming (spoiled) and usually dont have to worry about memory/space or casting of vars to much... (which I think is part of the problem for the error I am getting), so I am lagging in getting to grips with all the tight/control that needs to be done in programming in C++ for hardware

If you could help answer the 2/3 questions, and help me understand how to use the library/example better I would appreciate it!

ps. if there is any other infor required to help solicit a response, please let me know.

thanks!

holy cow batman! Already lost from the first page?

^bump! :slight_smile:

Well I dont have my USB Host shield/keybaord with me today at work :frowning:

but I fixed the pointer error I was getting:

Changing:

if(mykey == "p"){

to:

if(mykey == 'p'){

(single quotes)... doesnt give me the error when I verified the code in the Arduino IDE any more.

I guess the next question/step is to figure out:

1.) When connected to my netbook/laptop.. why does the external keyboard (thats connected to the USB Host Shield, ONLY output to the Serial MOnitor.. and not the actual application that is open?, In this example I had Notepad open expecting to see some keys being typed/passed along from the keyboard connected to the USB Host shield?)

Question:

Is it my set-up? plugging in a keyboard to e netbook/laptop that is the problem?
or
Is it that I need to use some sort of method to actually pass the keypress to the end device (in this test a PC with Notepad application open)

Anyone out there is this USB Host Shield 2.0 library before?.. and can clarify this aspect for me?

Thanks!
-xl

To answer 1:
You need a Leonardo if you are going to use HID. The Uno is not capable of doing HID-unless you use HoodLoader on the 16u2(which is easy to do). Does the USB Host shield use SPI? If so, it will be possible to use the ISP header for the 16u2 to connect it. HoodLoader: GitHub - NicoHood/HoodLoader2: 16u2 Bootloader to reprogram 16u2 + 328/2560 with Arduino IDE
EDIT The examples for the USB Host Shield library don't compile for the HoodLoader. :{

Thanks for the reply Issac96

You are (sorta) correct.. I am using a Pro Micro.. which is (more or less) a Leonardo in the same footprint/size as the Pro Mini.

I have all hardware/connection issues worked out, and can get a device sig/feedback when i run the board_qc sketch they provide in the examples.

my confusion is/comes into play here:

Shouldnt the USB host allow the key presses to pass through? (I only get serial data to serial monitor)..

that being said.. I have since posting this added, Keyboard.begin() in setup..

and have been adding in keyboard.write() lines where I see the Serial.print() lines..

to get an output to the PC/application..

but I'm not clear if this is the correct approach for this? (maybe my understanding of how it does/should work is flawed?)

I assumed the keypresses would be passed through naturally..

I have corrected the syntax error.
I have added in some code to 'check' for what value (keypress) is coming through.. and parse certain characters (ie: if a 'p' comes through.. I pass in a capital 'P' character)....etc..

however.. I havent been able to really dig in a work out:

carriage returns,
repeated keys.. (ie: if I held down a key..it should continually repeat out to the PC/device)

This is the example sketch I am using as my base:

USBHIDBootKbd

and have just been taking on code/debugging lines through out to get a feel of how things behave.

Try removing all the Serial stuff and just leaving in the Keyboard calls.