First useful version

This post is part 3 of 3 of  barcode

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”.

EV3 Code Pilot

This post is part 2 of 3 of  barcode

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:

From ‘http://www.elecbrick.com/lego/’

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:

Source code:

https://github.com/JorgePe/ev3-barcode/blob/master/codepilot01.py

The code sheet used and further developments I might make are also at github:

EV3 barcode scanner

This post is part 1 of 3 of  barcode

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

How to change your EV3 hostname

Now that more and more people are using ev3dev thanks to LEGO Education’ EV3 MicroPyhton a few might find in need to change their bricks’s names.

Until that feature is available at BrickMan level, this is the a way:

  1. access the ev3dev shell either through SSH (puTTY) or Visual Studio Code – don’t forget that the default user is ‘robot’ and it’s password is ‘maker’
  2. change te hostname with command ‘sudo hostnamectl set-hostname NAME’
  3. restart avahi service with command ‘sudo service avahi-daemon restart’

David Lechner pointed me to the ‘ev3dev-config’ tool having also an option for this purpose:

sudo ev3dev-config

Then choose

4 Advanced Options  Configure advanced settings

Followed by

A1 Hostname    Set the visible name for this ev3dev device on a network

This can all be done from Visual Studio Code through the EV3DEV Device Browser plugin – I wrote a detailed visual explanation for those less confortable with above explanation.

Clearing MQTT retained messages

When using your own ‘mosquitto’ broker and things start to get weird, ghost messages being received as soon as you start subscribing…

sudo service mosquitto start
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start

This will crear your retained messages. Next time be careful with option “retain message” when playing with MQTT Dashboards…