Uniqueness of Rasperry Pi Serial Numbers

My SID project needs the user to type in the last 4 digits of a PI’s serial num in order to connect remotely.

I chose 4 as I thought (intuitively) that it was enough digits to almost certainly be unique in a class of 15 Pi.

Of course,  if it takes one year 7 child x attempts in t time to get it right then imagine the number of attempts a class of 30 children working in “teams”  of two takes to do this.  then make it 2 digits – then 3 – then 4.

…….. so 30 mins later, all pupils have connected their laptops to their Pi :)

OK – lets try and me more scientific and find the probability of 1/2/3 or 4 digits letting us uniquely identify a Pi.

Turns outs to be one of those great maths problems called the “birthday problem” and that the probability of any 2 Pi out of 15 having same last digits of serial number is (in %) where r = num of Pi and d = number of hex digits is given by

a = (16^d)!
b = (16^d)^r)
c = ((16^d)-r)!

P(%) = 100*(1 – a/(b * c)

Substituting r = 15 and d =2 gives 34%

Substituting r = 15 and d =3 gives 2.5%

Substituting r = 15 and d = 4 gives 0.2%

So maybe we could get away with 3 digits but with say 30 Pi the numbers change to

Substituting r = 30 and d = 3 gives 10%

Substituting r = 30 and d = 4 gives 0.7%

So in a class of 30 you’d have to use 4 digits and so for compatibility for rich schools  – I’ve stuck with 4 digits :)

Just for an exercise, I wondered if I converted the serial num into Base 30 (using 0,1,2….x,y,z) for digits I get this

Substituting r =15 and d =2 gives 11%

Substituting r =15 and d =3 gives 0.4%

and even for a class of 30

Substituting r =30 and d =2 gives 38%

Substituting r =30 and d =3 gives 1.6%

So I’d say we could get away with three Base 30 digits.

But since its a lot of trouble to convetr from Base 16 to Base 30, I’m going to stick with 4 hex digits and stick them on the side of each Pi :)




ScratchGPIO5 launched

I’ve made ScratchGPIO5 the “stable” version and it’s available here

The main fundamental change is to go back to early philosophy and set pins 11,12,13,15,16 and 18 as outputs and all other pins as inputs with internal pull-up resistors enabled.

This makes it very easy for beginners on a budget to get going using breadboards as switches just have to be wired between pins and 0V to produce input changes.

ScratchGPIO 5 Plus icon launches exactly the same program as ScratchGPIO 5 but all pins are set as inputs with no pull-ups enabled.

This should satisfy both beginners and advanced Scratchers who don’t want their home fusion setup to scram the reactor when the program launches :)

Any comments and suggested improvements and bug reports always welcome either here or on twitter @cymplecy


Why so serious?

I just thought I’d give some background to my recent unfortunate outbursts in the online world.

I work in primary schools and for a number of years have been helping (and directly teaching) teachers with ICT lessons.  When  I first came along, teachers had recently been on a computing control course using the original Mk1 Lego mindstorms – they came back from a one day course and unless they immediately tried it out  by the time the came to use the one set that each school bought – they’d forgotten how to do it.

So they went into cupboards.

Along came the Data Harvest FloGo box – brilliant hardware concept – very robust – £100 so quite pricey and the software used uses old style flow-charting techniques – easy to get started but soon becomes quite messy.

I worked in a school cluster and we collaborated on fairground ride type stuff mixing Design Technology with Control Programming.

Good times.

Then in 2005, along came Scratch and I loved it.  Here was the Lego equivalent for programming for kids.  I started teaching it in Year 6 and then pushed it down over the years to Year 3.

The only problem was the lack of an external interface box like the FloGo so everything had to be simulated and I missed being able  to control lights and motors.

Then 2 years ago, the Raspberry Pi appeared :)

I bought one as soon as I could, I went to Preston and Manchester Raspberry Jams, I saw the PiFace  borrowed their code and got Scratch on the Pi to control lights and motors via the GPIO pins using a few £ worth of components.

The integration of an open platform being able to run high level code is fantastic and I thought – great – there will soon be affordable packaged versions of this ready to use in classrooms up and down the land.

I persuaded my schools that this was the way forward and they clubbed together to buy 6 other Pi and I used them to run after school clubs – controlling Robots in 2012-13 school year and trialing Scratch interfacing to the real world.

Having learnt Python and interfacing it with Scratch, I also worked on doing the same to let Scratch on PC/Mac/Linux laptops/desktops control Arduino based devices including the £3 Shrimp.

Although a complete Arduino package was much cheaper than the equivalent Pi setup, the lack of integration in one unit meant it is harder to produce an easy software Scratch interface and so I switched back to developing on the Pi.

I’d hoped by the end of that year, that the Foundation would be ready to roll out whatever they had planned for UK schools for the start of the school year in Sep 2013 but nothing appeared.

I picked up a few hints that something big might be announced at the 2014 Jamboree but nothing concrete appeared.

I had spoken to a number of people and said that I would be coming out into the open to complain about the lack of evident progress but as usual, the way I expressed myself (or more accurately – my bad reaction to the Foundations reaction to my forum post) has led to a lot of trouble all-round which is not good.

Now, I’m hoping that people can separate inter-personal differences and respond positively to getting the Pi INTO schools in a big way.

Simon Walters

Changing WiFi Settings on Raspberry Pi when away from home

DRAFT Post – not yet fully checked and verified by anyone so beware :)

If you set up your Pi at home with a WiFi dongle (in a robot say) and you take it off to a Raspberry Jam event you soon find out that you can’t talk to your Pi using the WiFi at the venue.

There are many routes to go down at this point – the most popular being:

  • Use a mobile phone as a WiFi hotspot with home WiFi settings
  • Use a spare WiFi router with same home WiFi settings

The best way however, to avoid interference with other attendees would be to enter the venue WiFI settings into your Pi.  However this is very difficult unless you have another Linux machine that can read/write your SD card as a Windows machine can’t do that.

One method I’ve come up with is to add a few lines of code into your and used these settings and added it to the end of /etc/network/interfaces :

auto eth0:1
iface eth0:1 inet static

and then use this command via LX Terminal

sudo apt-get purge ifplugd

And then re-boot.

What this then does is that it allows you to just plug an ethernet cable between a Windows laptop/netbook and your Pi when you get to the venue.  You can then remote into your Pi (using your normal methods) and change your WiFi settings to match up with the venue (Normally just simply  editing /etc/wpa_supplicant/wpa_supplicant.conf and putting the venues WiFi name and password in)


Auto Install Remote Control for Raspberry PI (X11VNC)

Following on from previous sucess with my autoinstall samba (Windows Networking ) I hope that this script will provide a simple way of installing x11vnc which give you full remote control over the normal Raspberry Pi standard desktop.

This is very useful when you want to power your Pi off batteries and stick some wheels on it and turn it into a robot vehicle.

To install, run LX Terminal and copy and paste the following code:

wget http://goo.gl/MbfUEp -O isx11.sh

and then press enter to download the installer

Once it has finished downloading, type the following and follow the instrutions:

sudo bash isx11.sh

At the end, you need to reboot your Pi and then you should be able to use a VNC program on another computer (I use TightVNC myself) to connect and control and view your Pi

Good luck.

Wheel encoders on a Raspberry Pi Robot

One of the problems with normal DC motors on robots is that you can’t accurately control them- you can vary the power to them using PWM but you’ve no real idea how far your’ bot will travel.

If you use stepper motors instead, then you can get very accurate results but the cheap ones don’t turn very fast and so are not suitable for a large floor area but ideal for table top use.

Recently, the Initio Robot Chassis from 4tronix has come along  and has wheel encoders built in and I’ve attempted to incorporate them into my ScratchGPIO project.

Basically, I use the RPi.GPIO library to do all my GPIO in and out and it has a facility to generate a pseudo-interupt (a callback routine)  every time it gets a pulse.  The wheel encoders produce 36 pulses for every 1 revolution of the wheels so its just a case of using the callback mechanism to count the number of pulses.

So I tell the wheels to turn 1 revolution and the count goes up by 36 – well not quite :)

I have no idea what power for what length of time (but approx 0.5) will give 1 revolution so I just switch the motor on, wait until count exceeds 36 then stop the motor.

The problem with this is that the motor takes some time to stop and so the final count ends up at about 48 or so.

The trick at this point is to remember the over-shoot and use the difference to compensate for the next move.


encoderpicBut, as usual with ScratchGPIO, all this is hidden beneath the bonnet and all the Scratch has to do is the scripts on the left to move forward and back one wheel circumference.

At the moment only the left hand encoder is read and I only use one of the sensing wires.


To connect it up
Looking at your PirRoCon board with GPIO pins on the left and regulator nearest you, remove the blue link nearest you in the bank of 8. (This disables the level-shifter for pin 7 (GPIO 4) which is the one I’ve designated for using for this.

Connect the brown wire from the left hand encoder (that’s left hand as if you were driving the robot yourself) and connect it to the exposed pin nearest the GPIO pins on the link you have just removed

Connect the black wire to a 0V pin and connect the red wire to 3.3 (NOT 5V!!!!!!) (The 1.2 version has dedicated 3.3V pins but if you have an original PiRoCon then you need to connect to the 3.3V on the i2C sockets using a short male-male lead)

ScratchGPIO Documentation

This post is out-of-dat.-  Please update to latest version

This post is to hopefully document all the available broadcasts and variable usage that ScratchGPIO understands and responds to


Scratch Variable “bug”

Although using variables is necessary once you start writing complex scripts, there is a “bug” or a “feature” (depending on yourpoint of view) in the way that Scratch sends out variable changes to any external programs.

If you say broadcast pin11On then Scratch will always send Pin11On out to any listening programs

But if you use a variable called Pin11 and say set Pin11 to On then it only sends this information out if the previous value of Pin11 variable was not On i.e. only changes are sent out

pindocThis code will not switch pin11 on the second time as the variable has not changed from its previous value.

One workaround is to use the green join block and broadcast any variables


This method will ensure than any variable changes are always sent out

Fish Dish Raspberry Pi Addon Board

This post is out-of-date.- Please update to latest version

Fish Dish This board is available from PiSupply and is a simple board to use for a Traffic Light simulation with its 3 LEDs and buzzer and switch. It also has an added advantage of providing all of the GPIO pins for further expansion so any I2C device or any extra addon board can be piggy backed on top of it :)

The LEDS are called Led1..3, the buzzer is called buzzer and the switch is called switch (up and down)

The LEDs can also be referred to by name e.g red, yellow or green.

Ryanteck Motor Controller Board

This post is out-of-date.- Please update to latest version

This inexpensive motor controller board http://www.raspberrypi.org/archives/5269 gives full control over 2 motors and is one of the easiest ways to get into Robotics on the Raspberry Pi.

To use it in ScratchGPIO, simple set variable AddOn to RTKMotorCon and then you can use 2 variables – Motor1 and Motor 2 and vary the speed and direction of the motors from -100 to 100.

It also breaks out the 3.3V, GND and the I2C pins so it is very easy to add on other I2C devices as well.

(Support currently only available in the ScratchGPIO dev version http://cymplecy.wordpress.com/2013/11/26/scratchgpio-development-testing/ )


20131128_223714These instructions refer to old 4 Please upgrade


The Pibrella is nice add-on board for the Raspberry Pi which consists of 3 large LEDs (Red/Amber/Green), 4 buffered outputs (OutE-F) with white LEDs to indicate their state, 4 inputs (InA-D) a built in large switch and a little piezo beeper.

Support for it has been added to the ScratchGPIO V4 developement version.

To use it, create a variable called AddOn and set its value to Pibrella in your On Green Flag event.

You can then use the usual AllOn/Off broadcasts and well as individual broadcasts for Red/Amber/Green/OutputE/OutputF/OutputG and OutputH

Also there is a special broadcast BeepXXXX where XXXX is the frequency in kHz that you want the beeper to make (The quality is very low so don’t expect Hi-Fi )

The 4 inputs are recognised as sensor values InA/InB/InC and InD and the switch is called “switch”

To control the brightness of the LEDs or the level of the outputs use redpower/amberpower/greenpower or powere/powerf/powerg or powerh.