I'm using USB Host Shield 2.0 on the Arduino Leonardo board.
Is it impossible to use like a typical USB port?
For example, I wonder if it's impossible to use like connecting a USB port keyboard.
Instead of detecting the keyboard signal with Arduino and sending it back to the "Keyboard.Write" command, Can USB Host Shield replace the USB Port of the computer, just like connecting the computer and keyboard directly?
I wonder if there's no other way but to map the keys.
The Leonardo has got native USB capabilities. It can be made to emulate the behaviour of a USB keyboard and the PC will see it as such. You can output chars from the Leonardo and the PC will think you pressed a key on the keyboard. Is that what you want?
What do you mean? You output 'x', you get 'x'. Job done.
I think...
OP wants to connect a real USB keyboard to the USB host shield connected to Leonardo, Instead of using Leonardo as a keyboard.
@bluebirdconfig
When you connect a USB device to your PC, the driver will be installed, right?
In the case of USB host shield + microcontroller, the driver needs to be processed by the microcontroller, and you need to implement yourself.
Since the microcontroller's program was placed read only memory, you cannot install the driver flexible later. (In addition, the ROM capacity is very small compared to the PC.)
So perhaps the USB host shield will only accept connect from devices has predetermined (your job!) protocol.
The device driver doesn't come from the connected USB device.
It is software used and prepare by the "host side" of the device.
Many drivers are pre-installed on your PC's operating system.
Or the OS is automatically getting the driver from the internet.
In the case of Arduino, there is basically no OS, no pre-installed drivers, even can't to get it from the Internet (In the first place, the driver for microcontroller is not released in many cases).
So you create the driver with write code yourself.
You can see an sample of doing that for some devices in the USB Host Shield Library example.
There is also a sample for receiving a standard HID USB keyboard connection.
A typical keyboard has a substrate for communication with a motherboard (mainboard).
The driver of the substrate and the motherboard is input through data communication.
When I used Leonardo and USB Host Shield, It only sends signals when the keyboard is physically input.
Leonardo doesn't have a driver to handle, so it's not actually working. (*)
In fact, I know the library example you uploaded, and I was looking for a way to use it "right away" like a desktop USB port without sketching Arduino without an example. But this is my fault that I didn't think of a driver.
Did I understand correctly?
In the end, Arduino driver (often referred to as 'key mapping' That's what I call it in my country.)
I know how to do it, but I asked you how to use it right away like a USB port without any hassle.
But thanks to you, I understood the keyboard device properly!
it's a little different.
In USB communication, the host periodically queries the device and the device returns answer it.
In other words, even if the keyboard is pressed, it will not be freely sent from the keyboard without hosts permission.
Think of it as answering "The 'A' key is being pressed" only when the host asks "Are you recognised pressing something?"
Actually, I knew how to use the keyboard input with Arduino, USB Host Shield 2.0, and keyboard even before I asked you the first question.
I thought this wasn't a driver, so I tried not to use it. (*)
I don't know how the keyboard works on the computer, so I thought it wasn't a driver.
As I said earlier, I basically thought that this method was not a common method because it was called key mapping instead of "Driver" in my country. Anyway, I don't know how to explain it, but I hope the meaning will be conveyed.
Through the answers, I learned how the keyboard works on the computer.
Keyboard -> USB Host Shield 2.0 -> Arduino -> Enter the key from your computer.
If you look at the library example, it might seem simple,
In reality, it's a very complicated process.
USB Host Shield 2.0 is connected to Arduino.
When a key is pressed through USB to Arduino, the resulting packet is transmitted to serial communication.
At Arduino, you have to make a driver like "What key did you press?" or something.
Arduino and my computer are connected via USB.
Arduino sends signals back to the computer through USB.
Keyboard input (for example, 'print')
I think it's similar, but I think I need to study more about USB.
You might think, "That's not what I'm trying to explain."
But I got the answer I wanted and the question was solved.