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)
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.
[code]sudo wget http://goo.gl/L7BJ79 -O isid.sh[/code]
using Raspberry Pi as a normal user, then just type (or copy and paste as before)
[code]sudo bash isid.sh[/code]
(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
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
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
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.