Scratch GPIO – PiGlow Support

Controlling a Pimoroni PiGlow using ScratchGPIO

This is a little fun add on from the Pimoroni gang with 18 high brightness LEDs on it.

To get an add-on like this to work on a Raspberry Pi (it uses what’s called the I2C protocol)  you need to run a few little things using LX Terminal.

sudo apt-get install i2c-tools


sudo apt-get install python-smbus

and finally a little tool to enable the I2C pins to be used for this purpose


followed by

sudo bash

Then once you’ve rebooted – come back here 🙂

Make sure you’ve installed ScratchGPIO of course

PiGlowAddonOnce you’ve added I2C support to your Raspberry Pi then just create a variable called AddOn and set it to PiGlow as the first line in your Green Flag event.

You can then create variables Led1 to Led18 and set them to values between 0 (for off) to 255 (Fully on). You can also have variables for Red,Orange,Yellow,Green,Blue and White to refer to each of the colours and the the same for Leg1, Leg2 and Leg3.

PiGlowLegAs usual, you can use also use simple broadcasts instead of creating variables and say things like Broadcast Led1On to switch LED1 on

This script shows a how using the the join statement you can blink each leg in turn without having to use a lot of if statements.

Use your Raspberry Pi as a Wi-Fi, Scratch interface device

This post is for an older version4 of ScratchGPIO

Click here to goto uptodate version

Acknowledgement: Connection concept/original code supplied by Martin Bateman 🙂

Although a Raspberry Pi can be programmed to use Scratch to control the GPIO pins, because of the limited computing power of the Pi, once the Scratch scripts become  longer and more complex, it can become quite slow to use.  [Edit:This has been improved tremondously with the Sep13 Scratch update 🙂 ]

However, there is another way of using the GPIO pins on your Pi – turn it into SID – a Scratch Interface Device –  and simply use Scratch on a desktop/laptop PC and get it to remotely control the GPIO pins via a WiFi connection.

@gbaman is working on a full remote control suite but its not yet packaged up for classroom deployment so in the meantime, please try out the following code/instructions.

To do this, first follow the instructions to install my normal ScratchGPIO software and then install the extra software to turn your Raspberry Pi into a remote SID (Scratch Interface Device)

Installing SID
Your Raspberry Pi needs to be connected to internet to install the software.

Copy the text below ( left click just before the s of sudo and drag right until all the text in the line, up to and including, as been selected) then right-click and select copy. Open up an LX Terminal window and select Edit and the Paste that into an LX Terminal window and run it to download the installer.

sudo wget -O

using Raspberry Pi as a normal user, then just type (or copy and paste as before)

sudo bash

(If logged in as a different user, then type sudo bash yourusername)

You should get a successful message and then your Pi is setup to listen for a request for it to become a SID from a desktop/laptop computer.

At the moment, the software on the PC is a simple python program that allows you to enter which SID you want to use.

To do this download and run the following program on a Windows computer

Use this code for a Mac running Python 3.3

and then enter the last 4 digits of your Pi’s serial num and then press Connect.  As long as you do this within 5 minutes of switching on your Pi, then it will connect.

You can find your RPi serial number digits by doing

cat /proc/cpuinfo

in an LXTerminal window on your RPi.

Put them into the above script and save it as

Getting your SID to connect to another computer

Reboot your RPi and after a couple of minutes yo should notice that the on-board green SD card activity LED is flashing the morse code for S (3 dots)  This means your RPi is listening out for the next 5 mins for a connect message from your other computer.

Simply run the program on your main computer and then enter the last 4 characters of your RPi serial num that you found out earlier and press connect.

Watch the green LED on your RPi and you should notice that it changes to flashing an O in morese code (3 dashes) for 30 seconds and then goes out.

Finally, launch Scratch on your main computer and enable Remote Sensor connections (right click on bottom block in Sensing section)

You should then be able to run exactly the same Scratch scripts on your PC as you can on your Pi and get the same control of the GPIO pins.

If you have any problems – please contact me @cymplecy on twitter or mail simplecy at google

As I said @gbaman1 is developing a more featured version that I will hopefully be able to just use instead of my one-trick pony 🙂

I think the RPi should broadcast its last 4 digits or its serial number so that the program at the PC just needs to pick which one to connect to from a list.