Read data from USB host port in Arduino YUN board

Hi,

I'm trying to read data from a USB bar code reader plugged into the USB host port of the Arduino YUN board. I was wondering if there are already libraries to read this type of devide, since it beaves exactly as a USB keyboard or USB mouse. The problem that I've noticed is that in this type of board, it seems the port talks to Linux and then I should make a kind of python script to obtain that data into the ATmega.

All the examples I've reviewed on the web, are using a USB shield with other arduino's boards. Is there any way to solve this using YUN's board ??

I will appreciate some guidance.

Regards.

PS. The bar code reader works perfectly in Ubuntu as a normal keyboard in all text editors.

PS. The bar code reader works perfectly in Ubuntu as a normal keyboard in all text editors.

Try and get a USB keyboard to work first on the Yun ...

Look for linux and not Arduino as any software you write for this would be running of the Linux half of the Yun and not the "Arduino"/AVR half.

Mark

Hi there!

This issue has been SOLVED. Just for the record, the Arduino Yun was not working properly because of the linux distro inside of it. Regarding the USB host port, the dependecies were broken, that's why the devices were not identified in the path /dev/input .

I tried to download the source files from linino, and I found several things. The link indicated inside a command in their page was not right:
git clone https://github.com/linino/dogstick.git

The right one was
git clone GitHub - arduino/linino

After that, u need to modified a files, like 001-depends.mk
The whole problem is described in the links below.

#12631 (Keyboard usb not create /dev/input/eventX) – OpenWrt (to add hid-generic - see patchwork url at the end)
#11145 (Support special HID devices (hidraw support)) – OpenWrt (to add hid raw)

It was needed to compile to modules from Linino, which I couldn't because of a misterious "Error 2",
but this person "sonnyyu" could:
http://forum.arduino.cc/index.php?topic=207069
Those files are GOLD, since Openwrt hasn't released the corrected version, since it was detected 13 months ago, and the solution was provided in that time by Álvaro Fernández Rojas noltari at gmail.com. After this, Sonnyyu followed the guidelines of Alvaro, and successfully compiled the packages needed.
kmod-hid-generic_3.8.3-1_ar71xx.ipk
kmod-hid_3.8.3-1_ar71xx.ipk

In order to avoid checksum problems, I recommend to install first these files (from http://download.linino.org/dogstick/all-in-one/latest/packages/) and then the ones from Sonyyyu (kmod-hid***):
opkg install kmod-input-core
opkg install kmod-input-evdev
opkg install kmod-usb-hid

After all this, any generic keyboard, mouse or barcode reader can now send data to linino, and you can see it displayed in the terminal screen.

After this, all that remains, is to write a python script that reads from "event1" (already created because fo golden packages), and sends the data though the bridge library, into the ATmega32u4 from the Arduino Yun board (similar to this python - Using STDIN in a Linux init script - Stack Overflow).

Regards.

PS. While trying to compile the source files from linino along with the patches, several apps were missing in my computer, as: gettext, xml parser, svn, git, and so forth.
PS. If you use make distclean, or make clean, u erase the confirgurations u need for the whole thing to work. Also using all cores from your computer for the compilation, will freeze it. If you have 8 cores, use 7, with make -j 7 V=s

Just to add up.
Linino page is under constuction now (jan-2014), but this was the originally link of it, in order to read the instructions to download source files.
http://linino.org/doku.php?id=wiki:getstartbuild

So to clarify, this is broken right now?

Reading from the SD card is so easy, I would have thought Arduino would have this worked out and tested before releasing the Yun. Seems like a pretty big oversight on a rather expensive device.

I've been able to duplicate the hexdump on event1, and have a bash script that listens to the keycodes and translates them, but it is too slow to keep up with user input without dropping key events.

Does anybody know a good tool to automatically manage the keyboard and expose the actual keystrokes rather than doing a hexdump, parsing, and decoding?

Simply doing a hexdump means the script must be in charge of controlling Caps Lock, Shift, Control, Num Lock etc. Also the keyboard lights aren't managed automatically....

Hi bernext,

I want to read data from a USB bar code reader plugged into the USB host port of the Arduino YUN board.

Just as you have done, but I have a problem:

barcode scanner (handheld Datalogic Gryphon GD 4130) bips on plug into Arduino Yun , but green led blinks.

Is current through USB from Arduino Yun is to low for the scanner?

TIA

Hello everyone,

It's been a while. Finally I got time for myself. It's weird but on Xmas eve I got time! Anyway, back to the barcode reader topic. My previous solution was inconsistent. So, I reviewed this topic again and found out several things that you should do to make it work:

  1. Upgrade your YUN image. The USB-host port drivers are NOW stable. (Release 1.0 - April 17th, 2014, changes read from : openwrt-yun/ChangeLog at master · arduino/openwrt-yun · GitHub). Download image from: http://arduino.cc/en/Main/Software#toc8
  2. Expand YUN's disk space using SD card: http://arduino.cc/en/Tutorial/ExpandingYunDiskSpace
  3. Install gcc compiler in YUN: http://noblepepper.com/wp/blog/2014/10/22/gcc-g-on-an-arduino-yun/
  4. Download the barcode.c from this page: Barcode scanner in OpenWrt | Hardware solutions for OpenWrt
  5. Upload that code into YUN in /mnt/sda1/
  6. Compile that code inside YUN with: gcc -o barcode barcode.c
  7. Run the code right there with the barcode reader plugged into the YUN: ./barcode /dev/input/event1
  8. The prompt part will appear, then use the barcode reader, and voila! You should see something like this:
    Reading From : /dev/input/event1 (HID Keyboard Device HID Keyboard Device)
    7811483187071

Notes: Discard my previous comments. The Golden files are no longer needed. Python Script is no longer needed for this test, and so forth.
Additionally, one should be able to cross-compile for YUN architecture, but it's a long trip or long shot. You could simply go nuts if you are working under pressure.
It's too complicated for now. So this is the solution that worked for me at this time.

Hope this helps you all and Merry Xmas.

Regards,
Bernext / Berham Horadrim / BRT-MXN

Hi,

I kept thinking about this topic and I found a better solution.
The previous one works perfectly, but involves C code, and its limitations.
I tried writing a script with python using the python-evdev binding provided by Georgi Valkov and it works! This binding was recently created (in October 2014) for Ubuntu and archlinux. I contacted directly Georgi Valkov, and he sent me the package cross compiled in order to work in OpenWrt Yun.

After u install the package, u can use the code I posted in my answer of stackoverflow:

In my arduino, it worked perfectly
root@Arduino:/mnt/sda1# python pybar.py
7501483187071

Regards,