ScratchGPIO support for MotorPiTx

This board makes it very easy to control Motors and Servos without any extra hardware as well as giving you the ability to switch your Raspberry Pi on and off and power it from AA batteries. See xxxx for further info on all its capabilities. This section is about controlling and using it with Scratch.

MotorPiTxIf you’ve got one of these then just create a variable called AddOn and set it to MotorPiTx as the first line in your Green Flag your Green Flag event.

MotorPiTxUpDownThese show you how to use the variables Motor1 and Motor2 to make a vehicle go forwards or backwards with the arrow keys

Servo control is done through variables Servo1 and Servo2 (or you can use Tilt or Pan instead).

The servo1 accepts values from -60 to +60 degrees (to avoid jamming issues if used as a tilt servo) and servo2 accepts -90 to 90

If Ultrasonics are connected to inputs 1 or 2 as per then they are reffered to as Ultra1 or Ultra2

PiRoCon from 4tronix

pirocon1Draft information

The PiRoCon from 4tronix is a robot vehicle controller board with direct support for 2 bi-directional motors, 2 servos, an Ultrasonic Module and 8 input/outputs that can handle 5V and 3.3V devices so its very useful for just plug and play robotics 🙂

As well as the above, you can plug an additional expansion module – the Adafruit 16 channel PWM/Servo Board into it and control those outputs as well.

The script on the left shows the variables that it responds to

Tilt can be from -70 to 80, Pan from -90 to 90, MotorA/B from -100 to 100.

Setting Tilt or Pan to off is available to help extend battery running time and the servos will just stay in there last position.

The Ulrasonic support input is exactly the same  as previously documented except no need to wire any resistors as the PiRoCon board does that for you 🙂

If you plug in the Adafruit board, then the pins can be reffered to as Servo1 to Servo16 or Power1 to Power16 if just needing normal PWM outputs for driving motors(thru extra buffer electronics) or direcly varying LED brightness

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.

Using Scratch controlling Raspberry Pi GPIO Remotely

This information is largely superceded by the SID post but is still useful for experimentation

One thing that I’d completely forgotten about is that the Scratch GPIO handler program can be run with a parameter of an LAN IP address.

What this means is that you can run Scratch on your desktop of your PC/Mac/Linux machine or even another Raspberry Pi and write you code on that and get it to control the GPIO pins on your Raspberry PI remotely.

These instructions are not for beginners


run a LX terminal session on your RPi

sudo python simplesi_scratch_handler/

(replace with your main computer IP address)

Your Pi will then listen for broadcasts from your main computer and you can simply run Scratch on yoru main computer, enable Remote Sensor Connections and then your Pi will pick up any broadcasts/variable changes that you make on your main computer

MiniPiiO Protoboard for Raspberry Pi

Courtesy of Gordon Henderson

When I was up at MakerFaireUK at Newcastle, I found this great product by one of the Newcastle Makerspace people called Tony Dixon of

Gordon already reviewed this last year but I missed it.  I think is a brilliant concept and I hope that Tony gets production ramped up (or farmed out to a UK supplier) so we can all get hold of them. (At a good price of course 🙂 )  And I think that a bigger version that goes the whole length of the Raspberry Pi or just another little one tagged on would be great

ScratchGPIO – Add on Modules/Boards

Scratch Controlling the GPIO Pins on a Raspberry Pi
Part 4 of 4

Ultrasonic Sensor Boards ultrasonic1pinSingle Pin Ultrasonics – if you connect a cheap 4 pin Ultrasonic Module as per this diagram, then you only need one spare GPIO pin to trigger it and receive the returned pulse

So now you simply use it (assuming connected to pin 23)

Use Sonar23  followed by a wait 1 and then just use the sensor item sonar23 to get the distance measured in cm.  Any pin can be used for this purpose and if you had several of them you could broadcast each of them in turn.

Ultra8Alternatively, you can use this syntax which will tell your Raspberry Pi to continuously do a distance check every 1 second and update sensor item Ultra8 with the results without any further need to do another broadcast

Gordon’s Ladder Board
This cheap and useful educational board (link) is an ideal introduction to getting kids to turns things on and off and saves having to wire up a breadboard to get going.  It does need someone to solder it together and if you don’t have that skill or tools – jsut give a shout out at a RaspberryJam and I’m sure someone will help you out 🙂

LadderAdOnIf you’ve got one of these then just create a variable called AddOn and set it to Ladder as the first line in your Green Flag event. This tells the system that your using one and then you can use broadcasts such as:

ld2This script will simply turn all the LEDs out and then just switch on every other one.

ld3To vary the brightness of a LED, you can use a Power variable like this example:

The state of the switches can be accessed through the sensing blocks.ld4 Scroll down to the bottom and click on the arrow next to slider and you should see switch1 – 4 (they will only appear after you have  run a Green Flag event as above)


This board makes it very easy to control Motors and Servos without any extra hardware as well as giving you the ability to switch your Raspberry Pi on and off and power it from AA batteries.


See for full support info


CompassYou can plug in a HMC5883L based I2C device and access the magnetic heading value it outputs.  Simply set AddOn to Compass and then use the heading sensor value which is updated 4 times every second


This really cheap and useful board is an alternative to @drogon LadderBoard.

It has 6 LEDs, a switch and a buzzer

To use it just set the AddOn variable to Berry and then you have easy methods of accessing it

Broadcasts available
[Led1..6] [On/Off/High/Low] e.g broadcast Led1On will make first red led light up

[All] [On/Off/High/Low] e.g broadcast AllOn will make all LEDs and the buzzer come on.

[Buzzer] ]On/Off/High/Low] e.g broadcast BuzzerOn

You can use variables instead e.g Set Led1 On will turn on 1st LED
And also use Power1..6 (values 0-100) variables to vary the brightness as

There is only one sensor value returned and that is called switch (1 if not pressed – 0 if pressed)


This board is a complete robotics controller for your Raspberry Pi based mobile robot.