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 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…

Wi-Fi Dongles for ev3dev

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.

dmesg:

usbcore: registered new interface driver r8188eu
R8188EU: Firmware Version 11, SubVersion 1, Signature 0x88e1