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 https://github.com/gbaman/Pi_Connector 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 gpio.sh, 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 http://goo.gl/L7BJ79 -O isid.sh

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

sudo bash isid.sh

(If logged in as a different user, then type sudo bash isid.sh 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
https://www.dropbox.com/s/o3h8qbmlq46iynp/handshake_py2.py

Use this code for a Mac running Python 3.3
https://www.dropbox.com/s/4x8rc0zgv1k98ht/handshake_py3.py

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 handshake.py.

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 handshake.py 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 mail.com

Plans
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?
    Chris

      • 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\__init__.py”, line 1475, in __call__
        return self.func(*args)
        File “C:\Users\goldteacher\Downloads\handshake.py”, 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.
        Chris

  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
      /home/pi/sid/sid.sh
      and you should see something like this
      00000000bb70873f
      873f
      Timeout is: 300

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

      Can you try this method out and see what happens?

      Simon

      • 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 Sid.sh 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 Sid.sh 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 πŸ™‚

        Simon

  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:

WordPress.com Logo

You are commenting using your WordPress.com 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