- EV3 barcode scanner
- EV3 Code Pilot
- First useful version
Should be finishing my EV3 Alexa program… but not in the mood.
So I got a USB barcode scanner in front of me… hmm, I wonder…?
My Ubuntu linux laptop recognizes. HID device, a keyboard. Great, plug and play!
So does my EV3 running ev3dev:
[ 538.808906] usb 1-1.2: new full-speed USB device number 6 using ohci-da8xx [ 538.972308] usb 1-1.2: New USB device found, idVendor=04b4, idProduct=0100 [ 538.972383] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 538.972425] usb 1-1.2: Product: USB Virtual PS2 Port [ 538.972462] usb 1-1.2: Manufacturer: Future [ 539.040788] input: Future USB Virtual PS2 Port as /devices/platform/soc@1c00000/ohci-da8xx/usb1/1-1/1-1.2/1-1.2:1.0/0003:04B4:0100.0001/input/input2 [ 539.128526] hid-generic 0003:04B4:0100.0001: input,hidraw0: USB HID v1.00 Keyboard [Future USB Virtual PS2 Port ] on usb-ohci-da8xx-1.2/input0
So if this is a keyboard I can read it with input functions:
#! /usr/bin/env python3
# if you are running from ssh session invoke this script with 'brickrun'
from ev3dev2 .sound import Sound
sound = Sound()
while True:
ucc = input('Scan a UCC: ')
ucc = ucc.lower().strip().replace('\t','').replace('\n','')
sound.speak(ucc)
Yes, it works. Just need to disable Brickman interface (first time I ran it the ‘keys’ read from from the scanner disabled my Wi-Fi connection). I can use print but the since the LCD is so small I prefer to use ‘speak’.
Now… what can I do with it?
Of course… identify LEGO sets!
So I found out that there are online databases of barcodes and some even offer webservices API. I asked a free trial key at “https://www.barcodelookup.com/api” and copy&pasted their python demo code… and it just works.
Code: https://github.com/JorgePe/ev3-barcode/blob/master/barcode02.py