Autostart ScratchGPIO project

Sometimes it can be useful to make your Pi autorun something when it is switched on.

With ScratchGPIO, you can autorun a Scratch program (it doesn’t have to be one controlling the GPIO pins but ScratchGPIO is needed to make it autorun

There are 2 steps

Create Linux Script

Run LX Terminal

mkdir -p  /home/pi/.config/autostart

cd /home/pi/.config/autostart


then type in following

cd /home/pi/scratchgpio5
sudo python &
scratch “/home/pi/Documents/Scratch Projects/”

If using ScratchGPIO6Alpha then do this instead

cd /opt/scratchgpio6alpha
sudo python &
scratch “/home/pi/Documents/Scratch Projects/”
CTRL-X then Y to save

chmod +x

Create a Scratch Autostart script

Make the Scratch script include the following in its On Green Flag Event


Then press the Green Flag to set AutoStart to True and save it in /homepi/Documents/Scratch Projects as

Reboot your Pi and it should automatically run the Scratch file


Scratch 1.4 Messaging on Windows Computers for Schools

My ScratchGPIO for the Raspberry Pi can send messages between 2 computers so I’ve made a version that runs on Windows so that two windows PCs running Scratch 1.4 can send messages between themselves or to from a Pi

Its all alpha level at moment but if anyone fancies playing with it here is some rough instructions

On 1st PC

Install Python 2.7

Download these 2 files and save them in a folder

Run the program

Open up Scratch 1.4 and enable Remote Sensor Connections (or just open this file)

If you don’t know the IP of the computer – broadcast getip and then look at ipaddr sensor to find out what it is

On the 2nd PC – do exactly the same

then make up 2 blocks

When I recieve hello

say Hello for 2 secs

Then on 1st PC broadcast linka.b.c.d  where a.b.c.d is the ip address of the other computer

then you can broadcast send hello

and the 2nd PC should say hello


Scratch on Ipad – Pyonkee

Updated 3rd Oct – connect added

We now have a Scratch clone for the IPad called Pyonkee 

This is great news at last as a lot of Scratchers only have Ipads nowadays and not desktop/laptop computers at home

I’ve managed to get it to be be used to play with ScratchGPIO by doing the following

On Ipad

Find out the Ip address of your IPad (its in wifi info button) = lets assume

run Pyonkee

select sensing blocks

press and hold down last block labelled sensor button pressed until enable remote sensor connections comes up and then click on that to enable it

(this can be a bit tricky to do but once sucessful you should see Remote Sensor connections enabled message)

On Raspberry Pi there are 2 ways of connecting your Pi to the IPad

Method 1

Run ScratchGPIO6 and make

on Green Flag
broadcast Connect

and then press Green Flag

Method 2

run LX terminal

cd scratchgpio5

sudo python

Eithre way, Your Pi should now connect to your IPad and you can now do all the normal ScratchGPIO commands on it :)


Raspberry Pi Auto-Hotspot

Initial software from

The concept of headless Pi at Jams and in classrooms has always been a subject close to my heart and recently I’ve been trying to go down the route of a Pi that see if it gets an IP address from a DHCP server, if not – it turns itself into a hotspot so that other computers can connect and communicate to it over WiFi.

So sequence should be

1.  Check if IP been handed out on WiFi from a DHCP server – if OK End

2.  If not, create hotspot for other Pi/clients to use.

The basic software needed is something called hostapd to make the Pi appear as a WiFi access point and dnsmasq so that it can hand out ip addresses to anything connecting to it.

Current situation

Note:  Hopefully this current state will be taken over by @heeedt

Working Hotspot (but no automatic changeover) using 8188CUS based adaptors

To get this working you need to connect your Pi to the internet using a LAN cable.

Then copy and paste this into an LX Terminal session

wget -O

and then type

sudo bash

You will be asked a series of questions but unless you an advanced geek or the network you are running on is using 10.0.0.xx addresses – just accept the default for each question

The only exceptions to this would be for your country and WiFi channel number

At the end, it will ask to reboot – once done, you should now see a open ClassPi available WiFi connection that you can connect to.

The hotspot does not supply a bridged connection to your LAN and the internet – (it would be an access point if it did that) it is purely designed to let you connect to it from a WiFi laptop or any WiFI enabled device such as as tablet

Please try and give me feedback


Why Traffic Lights are good for Computing

I’m well known for promoting the simulation of Traffic Lights using Scratch so I thought it was about time I said why and explained how good they are for the new computing curric.

In the old days,  Data Harvest with with Flow-Go box and GO software were the No 1 method of engaging pupils in the practical computing.

The Flo-Go box has yet to be bettered (or equalled) in terms of its design/sturdiness and ease of use.

The Go software had many activities but no 1 in my mind was the concept of simulating Traffic Lights.  They even provided a 1 m high cardboard set of lights with Red/Amber/Green – a wait light and a switch for whole class room

The hardware was superb but the programming software was based on flowcharting concepts.

Which was fine at the time but then Scratch came along :)

So, although the hardware stuff was brilliant, Scratch was such a transformation in bringing programming to young people that I switched to doing all my teaching using it and abandoned  Flow-Go :(

I still loved using Traffic Light simulations to teach control concepts but missed having real lights to control.

2 Years Ago
The Raspberry Pi was launched with Scratch built into it and the capability of easily controlling its GPIO pins.  The PiFace team very generously shared their code with me and I’ve built up ScratchGPIO so that Scratch on Pi can be used to control lots of hardware plugged into the Pi and we can now do “real” Traffic Lights again :)

Using Traffic Lights as Teaching Tool.

You can approach this in various ways – I like to use it as a bit of Road Safety exercise and a test of observation skills to see who knows what the main TF sequence is.

It turns out not many young people know the full sequence and you can have a lot of discussion on why they go Green/Amber/Red – Red & Amber/Green

(TopTip: Always start off from Green as the sequence down is much simpler than the sequence up)

So then you can get your pupils to program up the Green/Amber/Red sequence.

The move onto the Red & Amber/Green up sequence.

Then we can discuss and get into the pedestrian crossing version with its flashing Amber.

Then add in Red/Green Man – and the Wait light – and the button

So with all this we have used sequencing, repetiton and hardware input/output .

But we can also use costume changes on a TF sprite to do the same (or as well as) as using LEDs

And have a baby doing cartwheels across a crossing when the lights go to Red :)

I love it :)



Arduino class-set in Year 6

Today I tried out a class-set of 15 Arduinos with LEDs with Win 7 laptops with a Year 6 class with past experience of Scratch.

First  issue was that I only managed to get 8 set-ups working before the start of the lesson!

This was due to driver issues – I thought I was OK as I’d used Arduinos in the past in the school but all machines wanted to install a new driver and only 4 of them decided that the ones it had already were suitable.

With all the others, I had to download the latest Arduino package and use the drivers in that.

After that, plain sailing using ScA (Arduino version of ScratchGPIO) to make some Red/Yellow/Green LEDs go on and off.

All groups had a full pedestrian crossing LED Sequence and Scratch cat walking across a Zebra crossing on the screen with quite a lot having cars going back and forth and one group had a baby doing cartwheels across the road!

Technically ScA throws an error if they save and then reload another script meaning it has to be killed and restarted but I’ll hopefully sort that out and get some input handling added to it so be can use switches as well.

As usual, forget to take pics – will try and do better next time.


Post Post

There may be as easy solution to the driver probelm!

Pin Trigger handling in ScratchGPIO

I was looking at some of William Bell’s RPiScratchIO scratch code and notice that he had the concept of receiving broadcasts on inputs pins changing state.

So I’ve started implementing this (in dev version)

Basic concept is that if an input changes state – it will send a broadcast message to Scratch.

So if Scratch has a hat block that says

On Trigger received
Say “An input has changed state” for 2 seconds
Broadcast ResetTrigger

then if  any pin changes from 0 to 1 (or 1 to o) then Scratch will run the On Trigger block.

To make sure that only one event is dealt with at a time, my handler will not send any more changes until it receives a ResetTrigger from Scratch which is why that Broadcast ResetTrigger command is at the end.

As well as this global trigger, each pin has its own trigger so to just detect a change in pin7 use

On TriggerPin7 received
Say “Pin7 has changed state” for 2 seconds
Broadcast ResetTriggerPin7

If using an addon that names the inputs (say Switch) then the following would be triggered on a switch press

On TriggerSwitch received
Say “The switch has changed state” for 2 seconds
Broadcast ResetTriggerSwitch