Hardware & Yun
- Details
- Written by Sonny Yu
Install software:
opkg update opkg install kmod-usb-hid ... Configuring kmod-input-core. Configuring kmod-input-evdev. Configuring kmod-hid. Configuring kmod-usb-hid. ...
Hardware requirements for Yun:
Powered USB hub.
Testing by type at keyboard:
cat /dev/input/event1 | hexdump 0000000 550b b360 000e 8ae8 0004 0004 0007 000b 0000010 550b b360 000e 8af3 0001 0023 0000 0001 0000020 550b b360 000e 8afa 0000 0000 0000 0000 0000030 550b b361 0000 8126 0004 0004 0007 0016
Install Python/C evdev module
cd /usr/lib/python2.7/ wget https://www.dropbox.com/s/n6pafjual1dfcmg/evdev.tar.gz?dl=0 -O evdev.tar.gz --no-check-certificate tar -zxvf evdev.tar.gz rm evdev.tar.gz
nano /mnt/sda1/keyinput.py
#!/usr/bin/python from evdev import InputDevice, categorize, ecodes # import * is evil :) dev = InputDevice('/dev/input/event1') # Provided as an example taken from my own keyboard attached to a Centos 6 box: scancodes = { # Scancode: ASCIICode 0: None, 1: u'ESC', 2: u'1', 3: u'2', 4: u'3', 5: u'4', 6: u'5', 7: u'6', 8: u'7', 9: u'8', 10: u'9', 11: u'0', 12: u'-', 13: u'=', 14: u'BKSP', 15: u'TAB', 16: u'q', 17: u'w', 18: u'e', 19: u'r', 20: u't', 21: u'y', 22: u'u', 23: u'i', 24: u'o', 25: u'p', 26: u'[', 27: u']', 28: u'CRLF', 29: u'LCTRL', 30: u'a', 31: u's', 32: u'd', 33: u'f', 34: u'g', 35: u'h', 36: u'j', 37: u'k', 38: u'l', 39: u';', 40: u'"', 41: u'`', 42: u'LSHFT', 43: u'\\', 44: u'z', 45: u'x', 46: u'c', 47: u'v', 48: u'b', 49: u'n', 50: u'm', 51: u',', 52: u'.', 53: u'/', 54: u'RSHFT', 56: u'LALT', 100: u'RALT' } capscodes = { 0: None, 1: u'ESC', 2: u'!', 3: u'@', 4: u'#', 5: u'$', 6: u'%', 7: u'^', 8: u'&', 9: u'*', 10: u'(', 11: u')', 12: u'_', 13: u'+', 14: u'BKSP', 15: u'TAB', 16: u'Q', 17: u'W', 18: u'E', 19: u'R', 20: u'T', 21: u'Y', 22: u'U', 23: u'I', 24: u'O', 25: u'P', 26: u'{', 27: u'}', 28: u'CRLF', 29: u'LCTRL', 30: u'A', 31: u'S', 32: u'D', 33: u'F', 34: u'G', 35: u'H', 36: u'J', 37: u'K', 38: u'L', 39: u':', 40: u'\'', 41: u'~', 42: u'LSHFT', 43: u'|', 44: u'Z', 45: u'X', 46: u'C', 47: u'V', 48: u'B', 49: u'N', 50: u'M', 51: u'<', 52: u'>', 53: u'?', 54: u'RSHFT', 56: u'LALT', 100: u'RALT' } #setup vars x = '' caps = False #grab that shit dev.grab() #loop for event in dev.read_loop(): if event.type == ecodes.EV_KEY: data = categorize(event) # Save the event temporarily to introspect it if data.scancode == 42: if data.keystate == 1: caps = True if data.keystate == 0: caps = False if data.keystate == 1: # Down events only if caps: key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX else: key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX if (data.scancode != 42) and (data.scancode != 28): x += key_lookup # Print it all out! print key_lookup if(data.scancode == 28): print x x = ''
Write comment (0 Comments)
- Details
- Written by Sonny Yu
Install the HID driver we needed:
opkg update opkg install kmod-usb-hid ... Configuring kmod-input-core. Configuring kmod-input-evdev. Configuring kmod-hid. Configuring kmod-usb-hid. ...
ls -l /dev/input/ crw-r--r-- 1 root root 13, 64 Jan 1 1970 event0 crw-r--r-- 1 root root 13, 65 Oct 18 06:27 event1
The barcode scanner is at "/dev/input/event1"
Now we need compile c program "barcode"
nano /mnt/sda1/barcode.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h> #define KEY_PRESS 1 #define KEY_KEEPING_PRESSED 2 int main (int argc, char *argv[]) { struct input_event ev[64]; int fd, rd,size = sizeof (struct input_event); char name[256] = "Unknown",i; char *device = NULL; char decode_scancode[]={0,0,1,2,3,4,5,6,7,8,9,0}; if (argv[1] == NULL){ printf("Please enter path to device\n"); return 1; } if ((getuid ()) != 0) printf ("You must be as root for correct work!\n"); if (argc > 1) device = argv[1]; if ((fd = open (device, O_RDONLY)) == -1){ printf ("Open error of device %s\n", device); return 1; } ioctl (fd, EVIOCGNAME (sizeof (name)), name); printf ("Reading From : %s (%s)\n", device, name); while (1){ if ((rd = read (fd, ev, size * 64)) < size){ perror ("Read error"); return 1; } for (i=0; i< ((int)(rd/size)); i++) { if (ev[i].type == EV_KEY) { if ((ev[i].value == KEY_PRESS) || (ev[i].value == KEY_KEEPING_PRESSED)) { if (ev[i].code < 12) { printf ("%d", (decode_scancode[ev[i].code])); } else if (ev[i].code == 28) { printf ("\n"); } } } } } return 0; }
gcc -o barcode barcode.c
barcode excutable for Yun:
https://www.dropbox.com/s/1a2860gei4ugiqk/barcode?dl=0
/mnt/sda1/barcode /dev/input/event1 Reading From : /dev/input/event1 (WIT Electron Company WIT 122-UFS V2.03) 8901260131579638577 610214633880 000000610214633880 357510050163655 610214633880 ^C
Write comment (0 Comments)
- Details
- Written by Sonny Yu
lsusb ... Bus 001 Device 005: ID 0922:8000 Dymo-CoStar Corp.
This confirms OS know USB port.
Install the HID driver we needed:
opkg update opkg install kmod-usb-hid ... Configuring kmod-input-core. Configuring kmod-input-evdev. Configuring kmod-hid. Configuring kmod-usb-hid. ...
cat /dev/usb/hiddev0 | hexdump 0001c50 008d 0073 0000 0000 008d 0074 0000 0001 0001c60 008d 0041 ffff ffff 008d 0040 0000 0039
0039 in Hex is 57 in DEC, my Iphone weight 5.7 Oz.
cd /mnt/sda1 wget https://www.dropbox.com/s/uwy1d0lgawljf3b/evdev.py --no-check-certificate chmod 755 evdev.py ./evdev.py '/dev/usb/hiddev0' ... <Event timestamp=9244935.9672950006 type=141 code=64 value=57> ...
Write comment (0 Comments)
- Details
- Written by Sonny Yu
USB controlled relay board with 2 channels is used the HID technology.
https://github.com/sonnyyu/UsbRelay
Specification:
Relay type: 5V relay Contack type: NC / COM / NO (250VAC/125VAC/30VDC, 10A)
Input voltage: DC 5V (USB)
How to Cross Compile for Arduino Yun/Openwrt
A tool to control a USBRelay2 board. These boards are based on the V-USB stack from http://www.obdev.at.
Notes:
If you get a message usb.h file missing, you have to install this library:
sudo apt-get install libusb-dev
If you get following message:
./usbrelay get Warning: cannot query manufacturer for device: error sending control message: Operation not permitted error finding USBRelay2: Communication error with device
Then you had to add sudo in front of the command:
sudo ./usbrelay get
1: ON 2: ON
./usbrelay -h help: ./usbrelay on|off [1|2|3|4] [-n |all] [-name ] [-h] -h|--helpprint this help on|off [1|2|3|4]switch specified relay output on/off
getget relay status -n |alluse specified relay (if there are more than one relay) -name use relay with name, default is "USBRelay2"
Write comment (0 Comments)
Page 1 of 2