GeneralScratch and BerryClip

This blog post is to introduce you to the berryclip scratch handler, a simple way for primary school aged children to control lights, a buzzer and use a physical button with their scratch programs.

‘The Overland Launch’  themed school term saw my wife’s school use the highly effective 6 LED BerryClip Addon board and the popular MIT Scratch programming environment.  The children were able to build up their understanding of Scratch whilst also being able to light things up and make a noise. Each week they mastered a different aspect of the BerryClip, they were then able to create simple morse code examples and various light patterns. By the end of the term each group had designed and created an RNLI pager using their own creativity and their newly found computing skills.

scratch_logoTo allow Scratch to communicate with the BerryClip,  I’ve developed a python ‘handler’ script that can talk ‘GPIO’ to the addon board and talk ‘remote sensor connection’ with Scratch. The result is that scratch can be used to control led lights, a buzzer and the input signal of a push button.

Remote Sensor Connections (RSC)


Scratch uses this RSC feature to talk to external devices over a network.  To enable this in scratch, go the ‘sensor’ blocks, then right click on either of the last two blocks to find a menu item called ‘Enable remote sensor connection’.  Your scratch program will remember this setting when you save your scratch file. RSC has two main types of communication:

  • Broadcast messages

These are simple messages that can be sent and received over RSC. e.g.’led1on

  • Sensor-updates

These are special messages that pass a value associated to a changing sensor input or variable.  These sensor updates are only sent when a variable or sensor’s value has changed. The berryclip push button is a simple sensor, when pressed a value of 1 is sent, on releasing the button a value of 0 is sent.

Python Handler

The python code is open source, and you can find it here.

To directly download it on the pi use:


Then run it from a terminal with:

sudo python ./

(I’ll post a ‘Tip’ blog entry here in the near future, which explains exactly how to create a Desktop icon, so the running of this handler is as simple as double clicking an icon on the Desktop.)

You’ll then see something like this:


it will keep saying it’s trying to connect to scratch until it finds scratch running with RSC enabled. At which point it will then say ‘Connected!’ like this:

To close the handler broadcast the message quit – or use CTRL-C in the terminal window.

Using scratch with the BerryClip


Broadcast is the easiest method. The following broadcast messages will switch the leds on or off respectively.

allledson, allledsoff
led1on , led1off
led2on , led2off
led3on , led3off
led4on , led4off
led5on , led5off
led6on , led6off


Buzzer – broadcast commands are buzzeron and buzzeroff simple as that.

To quickly switch on or off all lights and the buzzer in one step use allon and alloff messages respectively


To get some button action going you need to pick up on the ‘button’ sensor value.

TIP: the ‘button’ sensor value will not appear in the sensor drop down list if you started the handler before scratch, to remedy this – just press the button on the berryclip, the sensor will then be available in scratch.

The best way to explain how to use the button sensor value is with some examples. The following are different ways you might utilise the BerryClip button in scratch :


Good Luck

This post is a quick start guide, targeted at anyone with a BerryClip who is interested in using it with Scratch.

Future blog  posts will cover the learning aids I created to gently introduce Primary School children to the above capabilities.

Any questions on this post – please don’t hesitate to comment below.

2 thoughts on “Scratch and BerryClip

  1. Pingback: Using the BerryClip with Scratch and the #RaspberryPi | Raspberry PiPod

  2. Pingback: Lessons in Pi | raspberrypistrangford

Leave a Reply

Your email address will not be published. Required fields are marked *