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.

12 thoughts on “Use your Raspberry Pi as a Wi-Fi, Scratch interface device

  1. Hi Simon,
    I’m having a bit of bother getting the Python module to run. I am on a mac, have the handshake file on my desktop and when I run it, it can’t find the tkinter file. Any ideas?

      • Hi Simon, this folder is present….but…is titled “tkinter”. I changed the .py file on line 4 to:
        from tkinter import *
        and ran it. It started well, I got the interface for the last 4 digits of the pi, but when I submitted this I got the following error message in the python shell:
        Exception in Tkinter callback
        Traceback (most recent call last):
        File “C:\Python33\lib\tkinter\”, line 1475, in __call__
        return self.func(*args)
        File “C:\Users\goldteacher\Downloads\”, line 20, in onSend
        s.sendto(message, (”, 50000))
        TypeError: ‘str’ does not support the buffer interface
        I think that this is a filenmae issue, but as yet can’t see where I need to change in the code.
        Thanks for the support thusfar.

  2. I can not make this to work. First of all i get an error, when installing the SID. It complains about absense of .config/autostart folder. If i create those folders manually before running the SID shell script, it completes successfully – but still does not work to connect.

    What else can i do to troubleshoot ?

    I did have the part of ScartchGPIO4 installed successfully, and blink11 works correctly.

    • Finally – someone tries it out 🙂

      Sorry about the .config/autostart – I’ll make sure they get created in future

      In LX terminal type
      and you should see something like this
      Timeout is: 300

      1st line is RPi serial number
      2nd is last 4 digits and what you need to use on the program on your PC

      Can you try this method out and see what happens?


      • Hi I could reach to you git rep, and get most up todate script. That didn’t have the auto start problem. I could also figure out the part, and got it to work yesterday. Thanks for great scripts.

        Do you have any idea about creating modules in scratch 1.4? I find all those pin high low sequencing bulky enough that for better reuse and readability would want them packaged as modules. Seems one can do that in scratch 2, but that does not support remote sid..

      • I could also figure out the part, and got it to work yesterday.

        What did you need to do to get it working?

        If you mean create own blocks then that is not possible in Scratch 1.4 without modifying the underlying squeak image.

        You have given me an idea to write a Scratch 2.0 handler to interface between Scratch 2 on a PC and Scratch 1.4 on an Rpi using SID 🙂


  3. can you share with me some information pointers about how to change the squeak image? I tried opening it up, and it showed many procedures and classes. e.g. if i want to add another block in motion, lets say fly(distance) to essentially do a projectile motion, how do i do it ?

    Scratch 2.0 handler would need to run on raspberry too .. right ? and that would first means running AIR on raspberry

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s