New Book Review!

Posted: June 13, 2022 in General

No Starch Press – The Art of Clean Code by Christian Mayer

I’ve received a review copy of this book, which looked particularly interesting as it promises to provide help and guidance on writing better code.

How could I possibly resist?

Cover of The Art of Clean Code showing two robots in a lab distilling a drop of liquid from a flask
Image: No Starch Press – The Art of Clean Code by Christian Mayer

Read the full review:

No Starch Press – The Art of Clean Code by Christian Mayer

QR Treasure Hunt

Posted: April 9, 2020 in General

With Easter coming up coupled with lots of extra time at home there has never been a better time for a good old treasure hunt.

IMG_20200409_222828.jpg

The QR Code Treasure Hunt Begins

I figured it would be fun to have a little treasure hunt with a modern twist and add a little more challenge than simply looking for chocolate in random places.

So why not make them work for their treats!

You Will Need

  1. Treasure Hunters – locate some keen participants (bribery is acceptable)
  2. Android / Apple device with QR Code reading software
  3. Printer
  4. Raspberry Pi / Ability to run Python / QR Code Online Generator (or use the example QR Codes)
  5. Ideas for questions/answers
  6. Most importantly a prize for the end!

Introducing my QR Treasure Hunt!

The concept is quite simple, for my example quiz I am using Characters and Films/TV but you could use anything you like (dare I say it you could even make it “educational”).

At the start of the hunt, my little hunters will need to find the first clue, marked “Start Here!”.  On the back of this clue they will find a QR code (see later on how to generate these easily using Python code).

QuizStartHere

First clue for the treasure hunt, find the film which features a character called “Albus Dumbledore”

The hunters will need to scan the QR code, in this case the code will say “Albus Dumbledore”.  Now they will need to find the next clue which will be marked with the name of the film (the black QR code) this particular character (blue QR code) is from.

… Any guesses?

Quiz00-01

1st Answer (on left) – Harry Potter”, 2nd Clue (on right) – find the film which features characters called “Oompa-Loompas”

Even if you did know the answer, remember the hunters would need to check all the other QR Codes until they find the correct one.  They then move on to the next clue (which will be another character to match with the next film).

Finally, when the hunters have followed all the clues, you can put on the back of the last one the final location of the treasure (alternatively, point them back to clue one and see how long it takes for them to notice that they are going around in circles… 😉 ).

Variations

You can adjust the treasure hunt to be as easy or as difficult as you like, choosing obvious or difficult answers, or perhaps adding extra clues (and award points if the hunters do not need them).  Also, the more questions you have, the more running around the hunters will need to do to check each one (and the harder it will be to remember where each answer is).

Creating the treasure hunt

First you will need to think up your questions and answers, picking a common theme will help since ideally the answers shouldn’t be too difficult but should suit for any question (the challenge will be working out which answer fits with each question).  It also helps to keep them small, as you will see, the size of the QR Code is proportional to the amount of text (so 40-50 characters at most)*.

*The maximum is over 4000 characters but that may make for a lengthy treasure hunt with very large QR Codes.

Example Questions/Answers

#  CHARACTER                             FILM
0  Albus Dumbledore                      Harry Potter
1  Elsa & Anna                                Frozen
2  Belle, Gaston, Mrs Potts            Beauty and the Beast
3  Rapunzel                                    Tangled
4  Han Solo, Luke Skywalker          Star Wars
5  Flopsy, Mopsy, Cottontail            Peter Rabbit
6  Baloo, Bagheera, Shere Khan    The Jungle Book

Creating the QR Codes

Next we will generate the QR-Codes, there are a few ways to do this, so pick whichever suits you best.  I can only vouch for the Raspberry Pi solution, which is the method I used.

NOTE – I’ve also included a copy of the QR Codes from the above example questions and answers, so you can try it out if you want to.

Raspberry Pi – Python Code

If you can, a little python code on a Raspberry Pi will work very nicely.  The following code requires pyqrcode to be installed (see the PyQRCode documentation for details).

sudo apt-get install python3-pyqrcode

Create the following python script, named genQRquiz.py:

#!/usr/bin/python3
''' genQRquiz.py '''
import pyqrcode

quiz={
    "Albus Dumbledore":"Harry Potter",
    "Elsa & Anna":"Frozen",
    "Belle, Gaston, Mrs Potts":"Beauty and the Beast",
    "Rapunzel":"Tangled",
    "Han Solo, Luke Skywalker":"Star Wars",
    "Flopsy, Mopsy, Cottontail":"Peter Rabbit",
    "Baloo, Bagheera, Shere Khan":"The Jungle Book"
  }

print("Generate QR-Codes")
for i,item in enumerate(quiz):
  print(f'{item} -> {quiz[item]}')
  qr_code_q = pyqrcode.create(item)
  qr_code_q.png(f'{i:02}.png',
                scale=5, module_color=(128,128,255))
  qr_code_ans = pyqrcode.create(quiz[item])
  qr_code_ans.png(f'{i:02}-ans.png', scale=5)
print("Completed")

Run the script using the following command:

python3 genQRquiz.py

This will create the QR codes as png files, called  00.png, 00-ans.png, 01.png, 01-ans.png etc. for each question (blue QR Code) and answer (black QR Code).

Using an online QR Code generator

NOTE – I have not tested or verified this web-page, so please use your own judgement as to whether it is safe and suitable for your needs.

QRCode-monkey.com

You’ll need to generate QR Codes for each question and answer.

Using an Android App to generate codes

NOTE – I have not tested or verified these apps, so please use your own judgement as to whether it is safe and suitable for your needs.

QR Droid Private from DroidLa

QR Code Generator from YKART

You’ll need to generate QR Codes for each question and answer.  Also you will need a QR Reader app for the hunters to use, so you can use this app later if required.

Using an iPhone/iPad to generate codes

NOTE – I have not tested or verified this app, so please use your own judgement as to whether it is safe and suitable for your needs.

Qrafter – QR Code Reader (QR Code Reader and Generator) from Kerem Erkan

You’ll need to generate QR Codes for each question and answer.

Creating your QR Treasure Hunt Clues

We can create our clues using the QR Codes as follows:

Start Here!       |       00.png
--------------------------------
00-ans.png        |       01.png
--------------------------------
01-ans.png        |       02.png
etc.
--------------------------------
06-ans.png        |       End!

Insert the QR Codes into a document file and print.

Our example clues…

Cut the clues into strips and fold them in half, answers (black QR Code) on the front and the following question (blue QR Code) on the back.  Next, stick the clues around the house/garden etc. for the hunters to discover.

IMG_20200409_223835.jpg

Our family QR Code Treasure Hunt, ready to go!

Get QR Code Readers Ready

You’ll need to have QR Code Reading device.  You can use either use one of the above QR Code generator apps above (they will also read QR Codes) or install a dedicated QR Code reader.

Make sure your treasure hunters are fully trained on how to use the QR Code Reader and understand what they will need to do before they start.

Android QR Code Reader

NOTE – I have not tested or verified these apps, so please use your own judgement as to whether it is safe and suitable for your needs.

– It is fast and simple, although this doesn’t include 3rd Party adverts, it has extensive terms and conditions and will pop-up with adverts for their password manager.
Or use one of the QR Code generator apps previously mentioned.
[Better free alternatives are welcome suggestions in the comments]

iOS QR Code Reader

I believe there is one built into the iOS camera app.

On Your Marks, Get Set…Go!

Now all that remains is to place all the clues everywhere and release the hunters!

IMG_20200409_155754-1.jpg

QR Code Treasure Hunt

Let me know how you got on and if you have any improvements/suggestions.

1.44″ TFT LCD Hat with buttons

I recently saw this little board, which provides a little screen (120×120 1.4″) and some buttons, in a nice little form-factor which would stack directly onto a Pi Zero. I figured this would allow a neat setup which would allow testing of various setups and also something I could use as a user interface for many other Raspberry Pi based projects.

1.44″ TFT Hat with Buttons Rear

I decided this would make a very nice little RetroPi setup, see how I got on in my Guide to…Mini RetroPi setup.

Latest Book Reviews!

Posted: February 15, 2019 in General, review
Tags: , , ,

I’ve recently received a few books to review (and to share at STEM events and workshops) from NoStarch Press.

No Starch Press books for review

 

Both of these titles draw me back to my youth when I was first getting in all things “computery” and electronic.

I can remember a little LadyBird book Ladybird Learnabout Simple Electronics by Kris Cochrane and dreaming about building all the circuits contained therein.

I don’t think I even got as far as making a single one of them, but I ended up with an Electronics Engineering degree so I suppose it served its purpose.

The second book, Mission Python, reminds of the copy out program books which you used to get for the micro computers of the 80’s (the ZX Spectrum, BBC micro, Commodore etc.).  This is still on my review list, so I hope to have a review for this at a later stage.

Enjoy!

New Pi-Stop Workshop

Posted: February 19, 2018 in General, Pi-Stops

Following another great day at the Digimakers event, I’m pleased to release the workshop files for the Pi-Stop “Whereabout Clock” workshop.

I will continue to update and improve the files, however the workshop files for the day can be download from the github repo.

You can also find more about the workshop in the Lessons > Pi-Stop Workshops > Whereabout Clock.

You can get Pi-Stops directly from the 4tronix , or from  Image result for cpc logoFarnel.

The way forward for Pi-Kitchen

Posted: August 15, 2017 in General

So the Pi-Kitchen has been running for sometime now, and although I managed to solve many of the issues with configuring the Raspberry Pi out of the box, it has always remained an experimental project.

PiKitchen

The purpose of the Pi-Kitchen was to explore the ways in which we could provide a flexible method for configuring the Raspberry Pi.  It did that very well and I have used it successfully ever since…however…I suspect I was one of the few that actually managed to set it up and make use of it (I don’t mind too much since I was the one who wanted it…and it worked great for me).

There were even quite a range of recipes supported and development with around 25 supporting various settings and hardware out of the box, plus several automatically running demos which were great for setting up for events etc.

The Pi-Kitchen had two main issues:

  1. Difficult to setup – a user friendly GUI for install and config was in the works but time wasn’t available to complete it.  So it was quite a challenge to get running for others.
  2. Recipes become out-dated – having a smaller user-base (i.e. 1) and rather complex recipes meant that I only updated them when I next used them.  This was further compounded because Raspbian changed quite significantly during this time.

The experimental work has proven the pre-configuration and setup can work, and I’ve tried out some interesting ideas along the way, but a different approach is required to meet the full objective.

The dream remains…

The overall concept and idea still remains:

Turn the Raspberry Pi into a plug and play appliance

Essentially, I want to enable the Raspberry Pi to be configured completely up-front, via a GUI or from a supplied configuration.  Ideally, people would be able to provide a setup file and then it can be used with the latest Raspbian image to recreate their project.  After that, they need only insert the SD-Card and add power…no screen, no keyboard, no mouse (if suitable).

Potentially, the Pi-Kitchen was close to this but required specific recipe files carefully crafted to achieve this, and the non-trivial initial setup.

Raspberry Pi Appliances

Many projects are distributed as apt-get packages, or as git-hub repos, which require a operating system already setup and manually configured before you start.

Otherwise they are distributed as pre-built IMG files which have everything pre-installed.  This had several big problems:

  1. Typically the image ends up being out of date, since the base image often gets updated and the pre-built image does not.
  2. The user must configure the Raspberry Pi afterwards (i.e. to add their network settings or setup specific options) – so a screen and keyboard is often needed (Plug and Play fail) and a new install means you have to do it again (and again, and again)!
  3. All the details on how and what is installed within the IMG is hidden, so not only do you not know for sure what someone has put into the operating system but you don’t learn much about the project either.

The GoogleAIY is a great example of this (an awesome kit!), if it was setup using a supplied configuration which also allowed the required customisation to be done up-front then it would be possible to have made it an out-of-the-box appliance.  You’d configure and generate your SD-Card on a computer, insert it into the GoogleAIY kit and add power!

Boom-You have your google assistant ready and waiting for that first question “what does the fox say?” right off the bat.

aiy-projects

Image from RaspberryPi.Org

For those who haven’t used the GoogleAIY kit, it requires a number of steps to setup correctly on the Raspberry Pi after you have imaged the pre-built IMG file supplied, requiring a screen, keyboard, mouse and some careful config (not truly pure out of the box IoT experience).

By providing everything as a configuration script (even if it is tied to a specific release of OS) it allows the community to be able to understand (and perhaps update) the setup which is packaged into these pre-built IMG files.  This would also ensure updates and fixes are pulled in and enabling these projects to develop further within the Raspberry Pi ecosystem over time.

Enter PiBakery stage right…

blocks-on-workspace

Image from PiBakery,Org

The PiBakery has been developed by David Ferguson and provides another solution for configuring Raspberry Pi SD-Cards.  It provides an excellent solution for setting up the SD-Card out of the box and provides a very neat interface for customising the configuration quickly and easily.

In fact, the whole thing works very nicely and is a lot better than what I was planning for the Pi-Kitchen (without requiring time I don’t have to develop it!).  If used correctly, and developed with a few additional blocks, this could easily be a platform by which people could create and share projects that enable the Raspberry Pi to be a proper plug and play solution.

So… hopefully we can help with it and build up the recipes available so that it is possible to create that complete Raspberry Pi setup from a configuration file and allow users to customise it before they install and power up.  To get that plug and play dream!

NOOBS / PINN Image support

The PiBakery functions by using a customised IMG file (based on Raspbian) which has a few scripted inserted to support the execution of the PiBakery configuration when the Raspberry Pi boots up.

This does mean that every time the official Raspbian image is updated, David has to update his image file (and that has to get pushed to your local PiBakery installation).  It also means that in order to support other variants (such as Raspbian-Lite, OpenElec or possibly Arch Linux and Ubuntu), each one would need the custom PiBakery files inserted manually and downloaded.

Using the methods used by Pi-Kitchen, we can use Procount’s NOOBSCONFIG (with NOOBS) or PINN (Procount’s advanced version of NOOBS), which will allow the required custom files to be added to the installed operating system post install.

The advantage of using PINN over NOOBS is that not only does PINN support the file injection methods without any changes, but Procount has enabled support for a much larger range of source images (in .IMG and .tar.xz formats) and allows source images to be served from a local server or even from a connected USB drive.

1

Image from matthuisman.nz

I’ve successfully used PiBakery in combination with PINN and a clean Raspbian image, to install a PiBakery configuration automatically.  This required 5 basic steps:

  1. Copy PINN/PINN-Lite to a clean SD-Card.
  2. In order to support a standard NOOBS type installation, the resulting SD-Card structure is slightly different to a clean IMG file type install.  NOOBS creates a FAT formatted recovery partition, this changes which partition will be visible by PiBakery from the host operating system.  Therefore, a few mods to these PiBakery files are needed to support different locations for the PiBakery configurations.  This requires removeFirst.py, removeNext.py and runScript.py to check for the PiBakery configurations in the Recovery partition as well as the boot partition.  I’ve prototyped these changes already and shown this to work with a clean Raspbian image.
  3. Create the configuration to copy the PiBakery configuration files to the correct place in the operating system and setup PINN to perform an automated install.  Currently, I’ve added a Pi-Kitchen recipe to do this, but practically we’d only need this single configuration so these can be created as a standalone configuration to be copied to the SD-Card (along-side the configurations generated by PiBakery).
  4.  Fool PiBakery to think it has already installed the OS so that it is ready to “update” the configuration (otherwise it’ll try to format and install the custom PiBakery image).  This is achieved by creating a folder called PiBakery and adding an empty blocks.xml file onto the SD-Card.
  5. Create your custom PiBakery configuration using the super nice block interface to build your custom setup, enter your settings, and update the SD-Card.

The SD-Card will be ready to power on and PINN will install the OS and then PiBakery will perform all the customisations.

In theory, this can be integrated into a single option within PiBakery (or in PINN) so the whole thing is as seamless as possible.

Extra Blocks

I’ll talk about some useful extra blocks next time, which will allow some of the customisations I’ve come to enjoy with using Pi-Kitchen, and also some which will streamline deploying your own projects via PiBakery.

Thoughts??

Hopefully David Ferguson will appreciate the concept and will be happy to integrate some of these ideas into his excellent project.

PiBakery and Procount’s PINN could make a rather nice combination, and perhaps a new era as the Plug and Play Raspberry Pi appliance.

New book review!

Posted: December 20, 2016 in General

Check out my new review:

The Hardware Hacker – Andrew “bunnie” Huang

hardwarehacker_cover

Available January 2017.

Experimenting with a few things…

Posted: July 20, 2016 in General

Once again, time has gone on and I’ve not added much for a while to the site.  However I’ve been playing around with a few things which have been lots of fun.

So I’ll keep adding to this post a little at a time and take you through a few of the interesting things I’ve got my hands on…  No spoilers..yet..but a few really excellent things (at least I think so).

Using Micro-Python with the NodeMCU Board

As usual I’ve written myself some notes on getting this setup, and I fully intend to share (once I get time to write it properly).  However some very quick lessons learnt…

Lesson 1: Micro Python is very nice, and you can use a Python-like terminal with the device by connecting through the serial.  Very swish…but frankly no cigar yet.

Lesson 2: Micro Python with a Wifi device like the ESP8266 on the NodeMCU board is great…but remember the ESP8266 Wifi settings are separate to the firmware, so you may need to ensure it is set to station mode first, before the micropython firmware will reset it.

Lesson 3: When you get webREPL running…we are getting better  – developing over Wifi yes please!  If it isn’t running once you’ve programmed the firmware (which it wasn’t on mine) you’ll never be able to connect using the webREPL console page (which is a html page – you can download a local copy or visit http://micropython.org/webrepl/).  Don’t get annoyed it doesn’t work until you’ve started it!

Lesson 4: Use the serial python console to start webREPL on the device as follows:

>> import webrepl
>>> webrepl.start()
WebREPL daemon started on ws://192.168.4.1:8266
Started webrepl in setup mode
>>>

Lesson 5: You must connect to the device via Wifi to use the web console!  Connect to the device via the AP it provides “MicroPython-ffffff” with default password “micropythoN).

First time you connect via the console (using the address shown when it starts) you’ll set a new password.  Then reset the board and reload webrepl as before.

Lesson 6: Unless you want to always manually start webrepl use the boot.py file and upload it.  This will run on power up!

boot.py

import webrepl
webrepl.start()

Lesson 7: Micro Python is a little annoying…it supports files so you can upload .py files and import them…BUT there is no editing via the webREPL console.  So edit and upload? No not quite!

Lesson 8: Uploading new files and “import mymodule” isn’t enough to update your code!  Import will not reload a module if it is already loaded…deleting a module (using “del mymodule”) will remove it but it is still cached so it will still not update.  WHAT A PAIN!

Lesson 9: After a few experiments (and a hint from @mnelsoneorm1 to checkout https://forum.micropython.org) managed to work out a way to do it.  Sometime later, I wrapped up all the useful bits into a util.py file, which I loaded at startup as well.

boot.py

import webrepl
import util
webrepl.start()

util.py

def readfile(file="boot.py"):
  with open(file,'r') as thefile:
    data = thefile.read()
    print(data)

def delfile(file):
  import os
  os.remove(file)

def reload(module):
  import sys
  del sys.modules[module]

Lesson 10: The upload might not upload a new version of your file…You may need to upload a different file first to ensure the newer one is reloaded into the browser.

Final lesson is NeoPixels are simply awesome (and deceptively easy)!

neo.py

import machine,neopixel
v=0.5
print(v)
NUM=24
np=neopixel.NeoPixel(machine.Pin(4),NUM)
OFF=off=(0,0,0)
R=r=(255,0,0)
G=g=(0,255,0)
B=b=(0,0,255)
Y=y=(255,255,0)
C=c=(0,255,255)

def clear():
  all(OFF)

def all(val):
  for i in range(NUM):
    np[i]=val
    np.write()

def pattern(val1,val2,val3,val4):
  for i in range(NUM/4):
    np[(i*4)]=val1
    np[(i*4)+1]=val2
    np[(i*4)+2]=val3
    np[(i*4)+3]=val4
  np.write()

def demo():
  import time
  for i in range(10):
    pattern(R,R,G,B)
    time.sleep(0.1)
    pattern(B,R,R,G)
    time.sleep(0.1)
    pattern(G,B,R,R)
    time.sleep(0.1)
    pattern(R,G,B,R)
    time.sleep(0.1)

np[0]=(255,0,0)
np[1]=(0,128,0)
np[2]=(0,0,64)
np.write()

GPIO Zero Hero.

I thought it was time I took at GPIOZero by Ben Nuttall.  You can see my write up on my Guide to…Embracing GPIOZero.

This also includes a solution for using GPIO.BOARD (physical pin numbering) with the GPIOZero library.  The best part is that you can keep using GPIO.BCM (BCM numbering) by default and just enable GPIO.BOARD when required.  WIN-WIN-WIN!

RPiGPIOBasic

GPIO.BOARD Physical pin number, just as it says on the tin.

Pi Zero USB-LAN Fan.

I’ve also been playing around with my PiZero.  Which still makes an excellent USB-LAN Device.  You can see the whole Pi-Kitchen process in my Using Pi-Kitchen to “bake” a Raspberry Pi Zero as a USB LAN Device video.

cz1bdigwwaeopxs

Smaller than a Bourbon????  Well not really (it is a super size Bourbon)

 

Pi-Stop to go.

Also, I’ve added some details of the Pi-Stop python module which I use in my workshops.

czydpoiwaaeglij

The Pi-Stop is plug and play!

This allows easy plug and play without the wires and hassles with pin numbers.  Just select one of the standard locations A, B, C and D (plus A+ and B+ for Model +/ RPi 2) and away you go!

A neat little HDMI screen.

I also got a nice little HDMI screen which although only being 5″ provides 800×480 resolution and a resistive touch screen.  The config will get added to the Pi-Kitchen in the next update (proto-type recipe is working well).

czaxcphxeaedw2m

The screen is from Bandgood.com and was about £20 (GBP) and runs well via a standard USB power pack (surprisingly low power and includes a switch to turn off the back-light too).

It is perfect for my Pi-Kitchen testing since unlike SPI/I2C/DSI interfaces, it works well enough without extra configuration.  The additional configuration makes the display fill the screen and enable the touch screen.

This makes a Model A with keyboard a handy lightweight “kit-to-go” set-up.

 

That is all for now!  Enjoy.

Time…it just keeps on rolling…

Posted: January 18, 2016 in General

What a year it was for 2015.  Taking a look my blog I’ve not posted for quite some time, but I have been very busy with a lot of other stuff.

Here’s a quick overview of the latest things on the plate for today…

Book review…

First off we have a review of Learn to Program with Minecraft by Craig Richardson.  I had a go with it yesterday and introduced some Python programming to our family Minecraft actives.

IMG_20160116_200201

Minecraft on the Raspberry Pi – a small keyboard and mouse is ideal for smaller hands!

PiZero enters the Pi-Kitchen and comes out a fully baked USB-LAN device

I’ve managed to package the required modifications to make a Pi Zero (and Model A/A+ Raspberry Pi) into recipes for the Pi-Kitchen.

For more details see the Git-Hub:

https://github.com/PiHw/Pi-Kitchen

To get started use:

Pi-kitchen – Start Baking

See the following video to see the whole Pi-Kitchen process in action and some of the features that can be pre-configured ready for power up.

 

Some other things I’ve been playing with…but not had time to post about…

IMG_1658

Pi-Stop workshop at Digimakers at the @Bristol science centre, along with a selection of books on show.

6623OT_08_027

Movement tracking with the Raspberry Pi Camera module!

 And much much more!