R4 HID/USB host capabilities

Hi,

For an project I'd like to use the HID capabilities of the R4 WIFI. I am however unsure if the R4 supports being an HID/USB host;

I'd like to connect a controller or keyboard to the R4, and read the key/button presses using USB. In the past managed to do this using an USB host shield and a Arduino MEGA2560; This is working perfectly, but I'd like to upgrade the project, using the new R4 WIFI.

I am aware that i can connect the R4 to an PC, so it will recognize it as keyboard/mouse. but this is not what i am looking for.

Unfortunately the libraries for USB hosting shield are not yet available for the R4, or not compatible at least.

so hence my question;

Does the R4 WIFI support HID/USB hosting?

Thanks in advance!

-Nick

Hi, please have a look at this documentation for details.

1 Like

Thanks for the documentation, but it is unfortunately not the solution to the problem I am having/ the project I am trying to attempt:

I want to connect a controller to the Arduino, and use the inputs of the controller to toggle lets say an output, or translate joystick movement to an analog value.

The documentation only shows how to connect the Arduino as an "keyboard/mouse". but this is not something I am looking for. Thanks for the documents though!

I am guessing that you would need some form of USB Host shield. Maybe something like:
SparkFun USB-C Host Shield - DEV-21247 - SparkFun Electronics

or Amazon sells several of them like:
Amazon.com: HiLetgo USB Host Shield for Arduino UNO Support Google Android ADK USB HUB : Electronics

I believe that @Merlin513 has played some with the USB HostShield 2 in the thread:
Uno R4 Poor SPI Performance - UNO R4 / UNO R4 Minima - Arduino Forum

1 Like

Just to add a bit more since @KurtE mentioned USB Host Shield 2.0. I added it the library status for the R4 as USB Host Shield 2.0 · Issue #9 · arduino/uno-r4-library-compatibility (github.com)

To Quote:
Updated the library to support the Maxima and WiFi boards. Issued a PR: felis/USB_Host_Shield_2.0#779

My fork it currently updated and tested with the PS4 and XBOX controller sketches: GitHub - mjs513/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

2 Likes

Thanks! it seems my old code is now able to compile and upload once again, I however am having problems with it:

I keep getting the message in the serial monitor "OSC did not start." this also happens with the PS4 and XBOX sketches, so I suspect there might still be an issue with the library, as my code is still working on my Arduino Mega. (maybe it has something to do with the R4 WIFI? as I saw the sketches were tested on a Minima)

Curious, I just ran the PS4BT sketch on the WiFI board and it paired and ran no issues.

If I run the qc sketch:


Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K................ SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
Test failed. Value written: 00 Value read: FF 
Press any key to continue...
GPIO test passed.
PLL test. 100 chip resets will be performed
Resetting oscillator

Reset number 0 Time to stabilize - 406 cycles
Reset number 1 Time to stabilize - 406 cycles
Reset number 2 Time to stabilize - 406 cycles
Reset number 3 Time to stabilize - 406 cycles
Reset number 4 Time to stabilize - 406 cycles
Reset number 5 Time to stabilize - 406 cycles
Reset number 6 Time to stabilize - 406 cycles
Reset number 7 Time to stabilize - 406 cycles
Reset number 8 Time to stabilize - 406 cycles
Reset number 9 Time to stabilize - 406 cycles
Reset number 10 Time to stabilize - 406 cycles
Reset number 11 Time to stabilize - 406 cycles
Reset number 12 Time to stabilize - 406 cycles
....
...
Reset number 98 Time to stabilize - 406 cycles

Reset number 99 Time to stabilize - 406 cycles

Checking USB device communication.

Reset complete. Waiting for the first SOF...
Getting device descriptor
Descriptor Length:	12
Descriptor type:	01
USB version:		0200
Device class:		FF
Device Subclass:	01
Device Protocol:	01
Max.packet size:	40
Vendor  ID:		0A5C
Product ID:		21E8
Revision ID:		0112
Mfg.string index:	01
Prod.string index:	02
Serial number index:	03
Number of conf.:	01

All tests passed. Press RESET to restart test

Maybe just try the examples to start with.

I just ran the QC sketch, this was the output:

Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision invalid. Value returned: 09
Unrecoverable error - test halted!!
0x55 pattern is transmitted via SPI
Press RESET to restart test

So I think my board is "fake" or something :smiley:

@nickmeijer
Before giving up I remembered that I am using the SPI PR version and not the production version. It may make a difference. If you want to download it you can and then just replace the current spi library with those files. You can get the files from here:
Reworked SPI class with direct register access to fix #28 for R_SPI by RudolphRiedel · Pull Request #45 · arduino/ArduinoCore-renesas (github.com)

Which one are you running?

I've tried installing the "new" SPI version, but the problem keeps persisting... strange how it is working on my other arduino, but not this one.

USB hostshield

I got this one from a supplier here in the Netherlands.
USB Host Shield voor Arduino Uno, Mega of Due - Otronic.

when I look at the one I have, and some shields from China/Ali-express, they are looking the same. maybe that is why I keep running into the "Die revision" error?

@Merlin513 What shield are you running? maybe the shield itself is the issue.

I have the one from tkj electronics: shop.tkjelectronics.dk/product_info.php?products_id=43 (note I get an error opening the page). This is the original host shield that the others are based off of,

Think @KurtE has used the sparkfun one: SparkFun USB-C Host Shield - DEV-21247 - SparkFun Electronics

I should try and pull one out and see what mine does

Just ordered another one from Sparkfun to see how it behaves.

This one appears to start up...

Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register... Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K................ SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
Test failed. Value written: 00 Value read: FF
Press any key to continue...

Sparkfun one:

USB Host Shield Quality Control Routine
Reading REVISION register... Die revision invalid. Value returned: 00
Unrecoverable error - test halted!!
0x55 pattern is transmitted via SPI
Press RESET to restart test

Now this one does not have the bottom ins like the other one does. Wonder if that makes a difference...

I always had some issues getting them to work with Teensy...

I'll add to this thread that if you need an Arduino board with native USB host capability, there's the GIGA R1 supporting HID, mass storage etc.