Arduino USB Host expansion board

Last updated on 14 November 2020 by Suffocation

An add-on board for the Arduino Uno and compatible boards. It doesn't have much more than a USB port. Various peripherals such as mice, keyboards, gamepads and hard drives can be connected to this.

As there is no operating system on the Arduino that offers various drivers, the functionality is limited by the library. Of course, new drivers can be written yourself, and the library found (see below) already offers quite a bit.

I found a nice project online that controls a cursor on an LCD display using a mouse. To see if I was capable of doing it myself, I've modified it slightly without looking at the existing code.

Areas of application

Generally, the USB board can be used to connect various devices, here's just a small excerpt:

  • Connecting HID devices like mice and keyboards
  • Using PS3/4 controllers
  • Xbox Controller
  • Accessing Mass Storage*
  • Connecting Bluetooth Adapters
  • ...

*USB sticks and hard drives could cause problems, for example, the Arduino Uno is too small.

Facts

The facts are quite brief, the board includes:

  • USB port
  • Reset Button

Bill of materials

  • USB expansion board
  • Arduino Uno or compatible
  • USB mouse (a cheap Logitech for me)
  • LCD Display
  • A few pin header cables

Views

Programming

Libraries

USB

There is a library that has become very extensive:

https://github.com/felis/USB_Host_Shield_2.0

I have copied the files from the USB library used into the project folder. CAUTION: only the required files are in the folder.

Graphics

Since the Adafruit Display library and the USB library don't fit on an Uno together, I've been looking for a smaller graphics library. I came across the u8g library online:

https://github.com/olikraus/u8glib

I integrated this library via the library manager, as it contains many files and I wanted to avoid having to pick out only the necessary ones.

The integration of libraries in general is described under the following link, and I will not go into further detail here.
https://fambach.net/arduino-ide#Bibliotheken

Test programme

Test 1 – Read out mouse

As my first test program, I used the example Mousetest from the library. I adapted the MouseRptParser class so that the mouse values for the current position only change within the valid range of the display. (Moving from 0-127 in the X direction and 0-63 in the Y direction). The factor indicates how quickly the values should change and corresponds to the mouse speed. 0.1 is very slow... 1.0 is very fast. For me, 0.1-0.2 is about right. Otherwise, the class does nothing but output the values on the console.

Test 2 – Graphics

To test the graphics library, I have drawn three symbols on the display (a circle, a triangle, and a rectangle). A small circle, representing the cursor, moves automatically from left to right. The larger symbols have collision detection. If the „cursor“ hits them, they fill with the foreground colour. The cursor itself is then drawn with the background colour.

I have created a class for each of the symbols and the cursor, which also handles collision detection.

Here is the example program:

This is what it looks like:

https://photos.app.goo.gl/b7yznVixQkmf6gnD8

Joint final product

I have merged the two test programs here and adapted them so that the current mouse position is passed to the cursor.

The source code can be downloaded here.

That's how it is

https://photos.app.goo.gl/ivEyLbXQM34mccop8

Problems

Connection of mass storage devices

StrumpfEule reports that connecting mass storage devices to the Arduino with the above-mentioned library does not work. Disbelieving, I researched and tested this, and unfortunately, I must confirm this, at least partially. On the Arduino Uno, it seems not to work at all; its memory is too small, and it lacks a third timer.

For the Arduino Mega 2560, the supplied example compiled and, according to the output on the console, also appeared to function. Further tests were not carried out.

Conclusion

Integrating the wireless mouse was very easy. The USB library offers almost everything you need. It uses a lot of memory, but it's within limits. However, this should be taken into account when using other memory-intensive libraries. Otherwise, from my perspective, there were no major hurdles. I wish other libraries would work as smoothly.

Related Posts

Sources

https://www.watterott.com/en/USB-Host-Shield-20-for-Arduino

https://github.com/felis/USB_Host_Shield_2.0

2 thoughts on “Arduino USB Host Zusatzplatine

  1. It's a shame USB sticks hardly ever work.
    nix USB stick FAT or FAT32 support.. simply doesn't work with Arduino

    1. Hello StockingOwl,
      Thanks for your contribution. At first, I didn't want to believe it, but being able to read certainly helps; it's in the header for the Mass Storage driver. I researched this a bit because I still found it hard to believe. My current understanding is that it doesn't work with an Arduino Uno and this library. It's missing the 3rd timer; even if you managed with two, the memory would be too small. While there are success stories, they're rather haphazard and only use fragments of this or other libraries. Furthermore, it seems possible to address USB flash drives via a special USB controller. However, the controller handles the work in that case. It's supposed to work on the ATmega, though. I haven't tried it yet, but I will. I'll update the post in the coming weeks.

      Hello
      Stefan

Leave a Reply

Your email address will not be published. Required fields are marked *