Using USB Keyboard

I need to use a keyboard for the application I'm developing. The keyboard is used to be connected to the USB-Host. Later it will be replaced by a laser scanner.
So I plugged the keyboard in, got the PnP-Event:

[  139.540000] usb 1-1.1: new low-speed USB device number 4 using ehci-platform
[  139.670000] usb 1-1.1: New USB device found, idVendor=0a81, idProduct=0103
[  139.680000] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  139.680000] usb 1-1.1: Product: USB Keyboard
[  139.680000] usb 1-1.1: Manufacturer: CHESEN

tried to hook the input events, but there is only /dev/input/event0 available. Shouldn't the USB device be listed there? I am not very familiar with linux. So I would be happy if someone would explain how to map the keyboard to linino so it can be used.
My second question would be whats the best way to forward the input events to my sketch? I can't use the serial terminal because it conflicts with my TFT...

THe USB HID and HID RAW support at trunk is broken.

HID RAW might needed for Laser Scanner, Magnetic Stripe Reader...

Do you have an LCD connected to the serial pins on the Yun? If so, doesn't that interfere with the bridge between the Arduino and Linino?

I am trying to get an LCD working with my Yun, and think the best way to do it will be to connect it to the USB host on the Linino, then use the Bridge to communicate between the LCD and Arduino sketch. I would think you should be able to do the same thing with the keyboard.

Gernby:
Do you have an LCD connected to the serial pins on the Yun? If so, doesn't that interfere with the bridge between the Arduino and Linino?

It does indeed. But the problem with the USB HID is another. It seems that OpenWRT doesn't support low speed USB devices. I'll try to connect a PS/2 keyboard next, using the PS2Keyboard lib. I hope that a future patch for LININO will fix the USB problem.

Gernby:
I am trying to get an LCD working with my Yun, and think the best way to do it will be to connect it to the USB host on the Linino, then use the Bridge to communicate between the LCD and Arduino sketch. I would think you should be able to do the same thing with the keyboard.

I had the same problem with my TFT. You can't use Pin 0 and 1:
http://forum.arduino.cc/index.php?topic=206923.0

sonnyyu:
THe USB HID and HID RAW support at trunk is broken.

HID RAW might needed for Laser Scanner, Magnetic Stripe Reader...

sonnyyu, do you have a link to share or it's your direct experience?

I compile new module of kmod-hid-generic and recompile kmod-hid with HID RAW support.
Here are the links.

opkg update
opkg install kmod-input-core
opkg install  kmod-input-evdev
rm /tmp/opkg-lists/*; opkg install kmod-hid_3.8.3-1_ar71xx.ipk
opkg install kmod-hid-generic_3.8.3-1_ar71xx.ipk
opkg update
opkg install kmod-usb-hid
insmod  hid-generic
echo "hid-generic" >>/etc/modules.d/62-hid-generic
cat /dev/input/event1  | hexdump
0000000 52c8 f605 0002 118a 0004 0004 0007 0004
0000010 52c8 f605 0002 118a 0001 001e 0000 0001
0000020 52c8 f605 0002 118a 0000 0000 0000 0000
0000030 52c8 f605 0003 e636 0004 0004 0007 0004
0000040 52c8 f605 0003 e636 0001 001e 0000 0000
0000050 52c8 f605 0003 e636 0000 0000 0000 0000
0000060 52c8 f606 000c 140f 0004 0004 0007 0005
0000070 52c8 f606 000c 140f 0001 0030 0000 0001
0000080 52c8 f606 000c 140f 0000 0000 0000 0000
0000090 52c8 f606 000d 8b0e 0004 0004 0007 0005
00000a0 52c8 f606 000d 8b0e 0001 0030 0000 0000
00000b0 52c8 f606 000d 8b0e 0000 0000 0000 0000
00000c0 52c8 f608 000e 468b 0004 0004 0007 0006
00000d0 52c8 f608 000e 468b 0001 002e 0000 0001
00000e0 52c8 f608 000e 468b 0000 0000 0000 0000
00000f0 52c8 f609 0000 b9ca 0004 0004 0007 0006
0000100 52c8 f609 0000 b9ca 0001 002e 0000 0000
0000110 52c8 f609 0000 b9ca 0000 0000 0000 0000

Above is keyboard input "abc"

I googled around but I couldn't find neither openwrt forum topics or anything else related. Do you have some links to share?

I couldn't find neither at openwrt, I did hardway use up stream OS of Openwrt , at Debian I setup working case.
lsmod

hid_generic            12540  0
usbhid                 47346  0
hid                   105826  2 hid_generic,usbhid

Now I know I need hid_generic, then read through openwrt source and linino source code. fix the bug and recompile.

Thank you sonnyyu. I was working towards compiling this and this was the info I had come across:
#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)
Keyboard in OpenWrt | Hardware solutions for OpenWrt (general usb keyboard info for openwrt)

Not sure if this is the correct way, but I was modifying these files:
~/linino/trunk/package/kernel/modules/001-depends.mk (to add +kmod-hid-generic)
~/linino/trunk/package/kernel/modules/input.mk (to add CONFIG_HIDRAW=y)

Thanks again.

Hi thomas-c is it possible for you to supply your new kernel/firmware here?

I am second one need new kernel/firmware source as well.

Thanks again sonnyyu for providing the kmod-hid-generic and kmod-hid module install packages above. My USB keyboard (/dev/input/eventX) and HID RAW (/dev/hidrawX) devices are now visible for use.

Sorry, I only have access to the same public precompiled binaries/firmware that are located at download.linino.org where our Yun's web panel OPKG-Configuration (/etc/opkg.conf) is configured to point to.

Anybody have any code to access the USB HID on the Yun for a keyboard?
Not sure how to expose the keystrokes to my sketch.

Im compiling right now a new kernel with usb hid for /dev/input/eventx support. After its finished i post here the results.

Update:
im running to an error during compile i dont know how to fix, maybe someone can help:

/home/dennis/storage/kernelbuilder/linino/trunk/scripts/download.pl "/home/dennis/storage/kernelbuilder/linino/trunk/dl" "cpu-mcu-bridge-1.1.0.tar.bz2" "afa194cf16a3d2b1ca5180f630054ed2" "http://downloads.arduino.cc/"
--2014-01-21 14:43:48--  http://downloads.arduino.cc/cpu-mcu-bridge-1.1.0.tar.bz2
Resolving downloads.arduino.cc (downloads.arduino.cc)... 64.90.32.4, 2607:f298:4:143:acce:55:0:1
Connecting to downloads.arduino.cc (downloads.arduino.cc)|64.90.32.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10843 (11K) [application/x-tar]
Saving to: `STDOUT'

100%[=======================================================================================================>] 10,843      --.-K/s   in 0s      

2014-01-21 14:43:49 (69.3 MB/s) - written to stdout [10843/10843]

MD5 sum of the downloaded file does not match (file: 0b877889de3c28601a599f7222ebb1c3, requested: afa194cf16a3d2b1ca5180f630054ed2) - deleting download.

here is a reported issue ...

For anybody who's a noob like me, I've outlined the exact steps of what to do to get the keystrokes to echo properly

  1. Download sonnyyu's custom .ipk files on SD card in \arduino\www
    https://drive.google.com/file/d/0B49lSur2AThlQ1NnX1hzWFV6UEE/edit?usp=sharing
    https://drive.google.com/file/d/0B49lSur2AThleW04WHNqRDc2S0E/edit?usp=sharing

  2. Do general package updates

   opkg update
   opkg install kmod-input-core
   opkg install kmod-input-evdev
  1. Install USB updates kmod-hid***.ipk from your sd card
   opkg install /mnt/sda1/arduino/www/kmod-hid_3.8.3-1_ar71xx.ipk
   opkg install /mnt/sda1/arduino/www/kmod-hid-generic_3.8.3-1_ar71xx.ipk
  1. Install necessary HID driver
   opkg update
   opkg install kmod-usb-hid
  1. Put hid in kernel
   insmod  hid-generic
   echo "hid-generic" >>/etc/modules.d/62-hid-generic
  1. See the data on the terminal
   cat /dev/input/event1  | hexdump     #continuous dumping of raw (useless) hex data

OR

   hexdump -n 96 /dev/input/event1 | head -n 2 | cut -d' ' -f9  #single keystroke's code and value
  1. write a script to continuously monitor and decode /dev/input/event1 stream and echo the characters to the bridge
    (still in the works. I'm still very new at this)

here's a link for the USB keycode to ascii lookup:
https://chromium.googlesource.com/chromium/chromium/+/master/ui/base/keycodes/usb_keycode_map.h

Nice!

sonnyyu:
Nice!

Sonnyyu, do you know the best way to have the actual characters dump into the console rather than the keycodes? I've written a script that listens to the events, parses them, and translates them, but it is not looping fast enough to keep up with user input. Keys are being dropped and I'm having to manage the shift and control keys manually. This can't be right...

It seems like there should be a simple solution to this. I'm not super-familiar with linux, but I have a feeling that it is a simple answer that I am just not aware of.

Plan A: C's evtest
At evtest is include evtest-capture,

evtest-capture "/dev/input/eventX" [evtest-capture.xml]

evtest-capture captures the information and events from the input device specified on the command line and writes it to the xml file given. If no filename is given for the output file, evtest-capture.xml is chosen as default.

Cross compile is needed.

Plan B: Python evdev (c-api)

http://packages.python.org/evdev/
Even name is python but it is c-api python, Cross compile is needed.