Added a few more lines to my first python script in order to achieve ‘Record and Play’ functionality, like the original LEGO Code Pilot.
Also change a bit the structure of the dicitionary, adding the code to execute to each “barcode item”. So the recording part is just adding “items” to a list and the playing is just a loop through the list, picking the code and executing it with the ‘exec’ function (kudos to Daniel Walton).
So ‘codepilot03.py’ is now able to record an undefined number of steps and execute them in a row. And since the barcode scanner is fully Plug and Play we can detach it and reattach it between runs (and since wi-fi is not needed, we can also remove the clumsy USB hub).
Next version will have an extended “language set”.
The first MINDSTORMS programmable bricks, the RCX, had several “incarnation”. Most people remember the yellow brick but there were several others, including the Code Pilot that used light sequences as commands. Those VLL codes could be printed as barcodes:
and the Code Pilot set had a companion sheet with some codes and also key notes that could be used as a barcode piano.
So let’s try a simple set of instructions:
The barcodes are just EAN-13 code generated online from EAN-13 barcode generator. They all start with ‘560’ (the code for Portugal-based companies) and the remaining 12 digits are just 1/2/…/5 left padded with zeros. The last digit is the checksum code and is generated by the tool.
So my first program uses a nested dictionary with the EAN-13 codes paired with an action to be spoken. So the program waits for a barcode to be read, checks for the action to be spoken and execute the action we chose:
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()
ucc = input('Scan a UCC: ')
ucc = ucc.lower().strip().replace('\t','').replace('\n','')
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.
It’s Easter time so I’m considering organizing a workshop with my LUG to show them The Light of Ev3 MicroPython 🙂
I already have a few microSD cards that I can share but will probably need some Wi-Fi dongles (no way I’ll ever teach a bunch of Windows-addicted guys how to use USB or Bluetooth on their first contact with Ev3 MicroPython).
My local robotics store has no more Edimax dongles so I went after another Asus USB Nano, it works fine with ev3dev (I think it even works better than the Edimax but if I want to switch to LeJOS or Ev3-G I prefer to have the Edimax with me as it is officially suported by LEGO).
Didn’t find the Asus but got a TP-Link “Wireless N Nano USB Adapter” (TL-WN725N) and it also seems to work fine.
usbcore: registered new interface driver r8188eu R8188EU: Firmware Version 11, SubVersion 1, Signature 0x88e1