Author Topic: USB host for Arduino  (Read 3140 times)

0 Members and 1 Guest are viewing this topic.

Offline MitiTopic starter

  • Super Contributor
  • ***
  • Posts: 1324
  • Country: ca
USB host for Arduino
« on: October 19, 2021, 09:26:42 am »
I’m trying to connect an USB bar code scanner to Arduino for a stand alone functional tester. Do you have any experience with this and is there any USB host to serial adapter that you can recommend? I have Google, I want experience, preferably easily obtainable in NA. I know I could use PS2 but I need USB.

Cheers,
Miti
Fear does not stop death, it stops life.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: USB host for Arduino
« Reply #1 on: October 19, 2021, 09:50:49 am »
Just to clarify requirements, what kind of USB device does the barcode scanner appear as? IIRC, USB barcode scanners normally appear as USB keyboards, right? (I.e. they just "type out" whatever barcode they see?)

If that's the case, then I assume one promising lead could be a USB-keyboard to PS/2 adapter (the more unusual USB-device to PS/2-host variant), assuming you can get the arduino to speak PS/2.
 

Offline capt bullshot

  • Super Contributor
  • ***
  • Posts: 3033
  • Country: de
    • Mostly useless stuff, but nice to have: wunderkis.de
Re: USB host for Arduino
« Reply #2 on: October 19, 2021, 09:54:00 am »
If you need USB host capabilities, a Raspberry Pi would be the better choice over Arduino.
Safety devices hinder evolution
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: USB host for Arduino
« Reply #3 on: October 19, 2021, 09:59:32 am »
I agree that an RPi is definitely worth exploring.

Can also consider: https://www.hobbytronics.co.uk/usb-host-dip  (better alternatives may exist?)
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: USB host for Arduino
« Reply #4 on: October 19, 2021, 12:37:50 pm »
If you need USB host capabilities, a Raspberry Pi would be the better choice over Arduino.
Depending on the needs, also a Raspberry Pi Pico might be a cheap solution for a HID USB host.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2297
  • Country: gb
Re: USB host for Arduino
« Reply #5 on: October 19, 2021, 12:48:58 pm »
I've used these as host interface for FTDI devices, works well.
This one is USB keyboard host which apparently works with barcode readers.

https://www.hobbytronics.co.uk/usb-host-keyboard
Quote
Note: This software also works with USB Barcode Readers

Edit: just noticed rs20 pointed to same, beat me to it.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12852
Re: USB host for Arduino
« Reply #6 on: October 19, 2021, 01:22:01 pm »
Although its probably not cost-effective vs the previous suggestions, Arduino did used to do a USB Host Shield, using the SPI interface  MAX3421E USB controller which is USB 2.0 full and low speed host capable. See: https://docs.arduino.cc/retired/shields/arduino-usb-host-shield
Clones of the USB host shield are still widely available, which would allow you to read keystrokes from a HID keyboard (or other device that emulates one) on anything from an Arduino Uno upwards.   The easiest way of finding the correct library to install is to use the library manager so search for MAX3421E, which gets you Oleg Mazurov's USB Host Shield Library 2.0, which has plenty of exampes.
 

Online MLXXXp

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: ca
Re: USB host for Arduino
« Reply #7 on: October 19, 2021, 03:53:11 pm »
There are a number of boards in the official "Arduino" family. If by "Arduino", you mean the very popular UNO, then some of the previous replies will apply.

If instead you just want to stay in the Arduino programming world, you could consider a board with USB host capabilities, such as the Arduino Zero. There are also other third party Arduino compatible boards based on the same SAMD21 microprocessor family, such as the SparkFun SAMD21 Mini Breakout and Adafruit Feather M0.

Here is a library that can talk, as a USB host, to various USB devices, including a keyboard, which is what a bar code reader likely emulates.
https://github.com/gdsports/USB_Host_Library_SAMD
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6239
  • Country: fi
    • My home page and email address
Re: USB host for Arduino
« Reply #8 on: October 19, 2021, 04:09:09 pm »
I'd suggest a Teensy 4.1 (about $27 USD), plus the USB Host connector (about $3 USD, only need to solder standard 4-pin 0.1" spacing pin header).  I also like to get the Ethernet kit ($4 USD) just in case I want to use the hardware 10/100Mbit wired Ethernet connection also.
Note that you can connect the main USB connector to your development host while the barcode reader is connected to the Teensy USB Host connector, as long as the barcode reader doesn't require too much current (keeping the maximum current from the development host via the USB bus under 500mA).  If using external power, note that the board does not have diodes, so you'll need to cut the VUSB trace (as described in the Teensy card) to make it externally powered only; or use an USB cable with the +5V line disconnected to connect the Teensy to your development machine while externally powered.

Of course, you'd need to port your Arduino project over to Teensyduino, the add-on for Arduino for Teensy support.  Biggest differences are in fast I/O port access (instead of PORTD etc., you use digitalWriteFast(); like in standard Arduino, digitalWrite() works too), interrupts, and timers: Teensyduino has easier interfaces for using all those.

Teensyduino developer, Paul Stoffregen, is a frequent contributor to Arduino (authored many common libraries et cetera), and I've found the Teensy forums useful.

Oh, forgot.  Teensy 4.x has 1,048,576 bytes of RAM, and can run at up to 600 MHz.  (It's a really powerful Cortex-M7 microcontroller from NXP.) With one PSRAM chip ($2 USD) soldered to SMD pads on the board, you can add 8 MiB of RAM; and you can use up to two of those PSRAM chips, if you find you need lots of RAM.  This RAM appears as ordinary memory from address 0x70000000 upwards, so you can use it for your own data without worrying about bank switching or that kind of nonsense.

(I'm not affiliated, just a very satisfied and happy customer.  I also occasionally help out on the forum there, too.)
« Last Edit: October 19, 2021, 04:13:19 pm by Nominal Animal »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: USB host for Arduino
« Reply #9 on: October 19, 2021, 04:20:28 pm »
I’m trying to connect an USB bar code scanner to Arduino for a stand alone functional tester. Do you have any experience with this and is there any USB host to serial adapter that you can recommend? I have Google, I want experience, preferably easily obtainable in NA. I know I could use PS2 but I need USB.
The majority of commercial-grade bar code scanners are multi-interface, typically supporting at least RS-232, USB, and PS/2 "keyboard wedge" (i.e. PS/2 with passthrough for an actual keyboard) modes. You just connect a different cable to it.

So if you're not committed to a particular USB-only scanner, I'd look for a model with RS-232 (easily converted to UART/TTL signals with a MAX232 or equivalent), or maybe even PS/2, since there are PS/2 keyboard input libraries for Arduino.

There are also bar code (1D/2D, even) scanner modules with UART interfaces that are easily controlled by Arduino.
 

Offline MitiTopic starter

  • Super Contributor
  • ***
  • Posts: 1324
  • Country: ca
Re: USB host for Arduino
« Reply #10 on: October 20, 2021, 12:17:46 am »
Thanks a lot for all the info! I need some time to digest it.

I prefer to stay with the Arduino Mega 2560. It is just a simple LCD and keypad tester, all through an I2C interface.
I have all the libraries I need and there's no time to discover. Maybe some other time.
Fear does not stop death, it stops life.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: USB host for Arduino
« Reply #11 on: October 20, 2021, 01:40:41 am »
The barcode reader in keyboard mode (which is the default generally) might work with a USB PS/2 Adapter, which is nothing fancy just a dumb pin to pin adapter, so you could try it out and see all you need is a USB-A socket and some wire.  See the reply in this thread for the wiring....

https://forum.arduino.cc/t/is-it-possible-to-connect-a-usb-keyboard-to-the-arduino-without-a-shield/631323
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: USB host for Arduino
« Reply #12 on: October 20, 2021, 02:17:04 am »
The barcode reader in keyboard mode (which is the default generally) might work with a USB PS/2 Adapter, which is nothing fancy just a dumb pin to pin adapter, so you could try it out and see all you need is a USB-A socket and some wire.  See the reply in this thread for the wiring....

https://forum.arduino.cc/t/is-it-possible-to-connect-a-usb-keyboard-to-the-arduino-without-a-shield/631323
I would not expect a USB bar code scanner to support a passive PS/2 adapter, since they normally support PS/2 mode by using a different cable altogether. (Configuration of the scanner is performed by scanning special bar codes.)
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: USB host for Arduino
« Reply #13 on: October 20, 2021, 03:04:35 am »
I would not expect a USB bar code scanner to support a passive PS/2 adapter, since they normally support PS/2 mode by using a different cable altogether. (Configuration of the scanner is performed by scanning special bar codes.)

Converesely, if I was making a barcode reading wand and wanted to sell both a USB and a PS/2 version/cable, I'd make the wand capable of both just like a keyboard is, and the cable be just that, a cable.

I have an el-cheapo wand it only has a fixed USB cable, defaults to keyboard mode (also can appear as a USB serial port).  Maybe I should test the theory sometime.

I just tested with my el-cheapo wand, it didn't work with that one, but the manufacturer doesn't have a PS/2 version by the looks so perhaps not much of a data point, but i didn't put any effort in either. 
« Last Edit: October 20, 2021, 03:26:48 am by sleemanj »
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline spostma

  • Regular Contributor
  • *
  • Posts: 118
  • Country: nl
Re: USB host for Arduino
« Reply #14 on: October 20, 2021, 09:43:16 pm »
the lowest cost USB Host option would be the CH554; it even has DMA:
https://github.com/Blinkinlabs/ch554_sdcc
https://github.com/Blinkinlabs/ch554_sdcc/tree/master/examples/usb_host_KM
https://www.mikrocontroller.net/topic/462538?page=single  (german)

and the CH554 toolchain for Arduino fans:
https://github.com/DeqingSun/ch55xduino

You could use it us USB->PS2 or USB->UART converter.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: USB host for Arduino
« Reply #15 on: October 22, 2021, 04:56:00 am »
Quote
I prefer to stay with the Arduino Mega 2560.
There are "USB Host Shields" for Arduino, usually based on the MAX3421.  But they tend to be more expensive that boards that have native support for USB host (like the Teensies and SAMD51 boards.))

Or you could look around to see if anyone is still selling the "Arduino Mega ADK" (Android Development Kit) - this is essentially a mega2560 with the MAX USB host chip already on the board.
 

Offline MitiTopic starter

  • Super Contributor
  • ***
  • Posts: 1324
  • Country: ca
Re: USB host for Arduino
« Reply #16 on: October 22, 2021, 07:34:12 pm »
Quote
I prefer to stay with the Arduino Mega 2560.
There are "USB Host Shields" for Arduino, usually based on the MAX3421.  But they tend to be more expensive that boards that have native support for USB host (like the Teensies and SAMD51 boards.))

Or you could look around to see if anyone is still selling the "Arduino Mega ADK" (Android Development Kit) - this is essentially a mega2560 with the MAX USB host chip already on the board.

That’s a very interesting idea, thanks! I didn’t know about this board, even though it is right there in the boards manager.  |O
Do you know a good usb hid host library for that board?
Fear does not stop death, it stops life.
 

Offline salihkanber

  • Regular Contributor
  • *
  • Posts: 140
  • Country: us
  • Hello all.. It's nice to be here..
    • Dynamic, Versatile, Innovative Start-Up
Re: USB host for Arduino
« Reply #17 on: October 22, 2021, 07:44:55 pm »
I've found some videos I hope they might help:


 

Offline MitiTopic starter

  • Super Contributor
  • ***
  • Posts: 1324
  • Country: ca
Re: USB host for Arduino
« Reply #18 on: October 22, 2021, 08:07:16 pm »
Right, it is right there on arduino.cc, USB Host Shield Library 2.0. I’ll give it a try.

Cheers,
Miti
Fear does not stop death, it stops life.
 

Offline rpiloverbd

  • Regular Contributor
  • *
  • Posts: 157
  • Country: bd
Re: USB host for Arduino
« Reply #19 on: December 12, 2021, 10:14:08 am »
I think using an USB host shield will be the best option. Here you can find a detailed tutorial: https://www.theengineeringprojects.com/2020/12/introduction-to-arduino-usb-host-shields.html
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf