-
- Posts: 23
- Joined: Sat Jul 07, 2012 6:46 pm
- Location: Oviedo, Florida U.S.A.
- Contact: Website
Scratch connectivity
I was very pleased to learn that Scratch was included in the Debian squeeze build for the Ras-Pi. Unfortunately, Scratch doesn't seem to be fully functional in this scenario. Saving to and loading from the scratch site didn't work for me initially from within the scratch interface. I'm sure this is likely due to integration with Debian Linux and the 1.4 Scratch build. Has anyone else run into this?
Mac Rutan
macrutan@mac.com
macrutan@mac.com
- csoutreach
- Posts: 32
- Joined: Mon Nov 28, 2011 1:06 pm
- Contact: Website
Re: Scratch connectivity
We've had some trouble too, we fixed it changing the startup script. Think it's to do with where it looks for libraries. We'll post the code once we've tested it more.
http://piface.openlx.org.uk/ Raspberry Pi IO Interface Board
Re: Scratch connectivity
Please do. If there's a bug in the Scratch packaging, I'm sure the Debian developer will be very interested (and I'd be keen to integrate the fix also).
-
- Posts: 16
- Joined: Sun Jun 24, 2012 1:13 pm
Re: Scratch connectivity
Could someone please provide me with a step-by-step approach to using Scratch with the PiFace. I've downloaded the 4gb Debian distro provided by the PiFace team which should include everything necessary to control Scratch (with Mesh-enabled) from the desktop. But I just can't seem to get my head around how to use it.
It's no problem to control the actual PiFace with Python, except I can't get the emulator to work when the PiFace is attached, even though I've replaced piface.pfio with piface.emulator as stated in the stated in the instructions. I get a 'global name emu_screen is not defined' error. Any help to a Python newbie appreciated.
It's no problem to control the actual PiFace with Python, except I can't get the emulator to work when the PiFace is attached, even though I've replaced piface.pfio with piface.emulator as stated in the stated in the instructions. I get a 'global name emu_screen is not defined' error. Any help to a Python newbie appreciated.
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
I know your mother said not to do this but if you lived near Chorley, Lancs I could come round your house and help get you sorted 
I don't have a pi-face so this is only way of me helping you I'm afraid but maybe others (from the pi-face team) will come along - I'll tweet one of them for you
Simon

I don't have a pi-face so this is only way of me helping you I'm afraid but maybe others (from the pi-face team) will come along - I'll tweet one of them for you

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
-
- Posts: 16
- Joined: Sun Jun 24, 2012 1:13 pm
Re: Scratch connectivity
It's OK
I've finally got my head around how to do it. Although technically correct, the instructions from the PiFace team are not at all clear for someone who is not familiar with the Scratch and Linux environment, even when they are experienced computer users. Anyway, I'm now controlling the PiFace with both Scratch and from Python and I offer my help to anyone who is having the same difficulties as I was two days ago.
Please don't come round to my house

I've finally got my head around how to do it. Although technically correct, the instructions from the PiFace team are not at all clear for someone who is not familiar with the Scratch and Linux environment, even when they are experienced computer users. Anyway, I'm now controlling the PiFace with both Scratch and from Python and I offer my help to anyone who is having the same difficulties as I was two days ago.
Please don't come round to my house

-
- Posts: 16
- Joined: Sun Jun 24, 2012 1:13 pm
Re: Scratch connectivity
Due to a couple of requests, I've produced this verbose guide on how to control the PiFace with Scratch. I can't claim any specialist technical wizardry on this matter and all the info is available on the web, but I do hope I have managed to clarify the steps needed to do this.
How to use Scratch to control the Raspberry Pi PiFace interface - A Guide for Dummies (like me)
Pre-requisite:
1) Download the 4gb Raspbian Linux SD Card image from the PiFace team from here (http://pi.cs.man.ac.uk/download/). This includes all the required libraries and extension programs (including a graphical emulator of the PiFace) for interfacing the PiFace with Scratch, including a modified version of Scratch. You can download and install the additional components yourself, but this is much easier.
2) Burn the .img to SD card using your preferred method (check the web if you don't know how), insert into the RPi with a keyboard, mouse and monitor attached, connect the PiFace and boot the RPi (network or internet access is not needed unless you want to use ssh/vnc for remote access) Login with pi and raspberry as usual and type startx at the command prompt to run the desktop environment.
Setup:
3) Run Scratch from the desktop and then shift-click on 'Share' in the top menu line
4) Select 'Host Mesh' from the drop down menu
5) Note IP address displayed (mine was 127.0.1.1) and click OK
6) Minimise Scratch (don't close it) and run LXTerminal from the desktop. Type in the following commands at the pi@raspberrypi$ prompt in the terminal window:
cd piface/scratch
python scratch_handler.py 127.0.1.1 (replacing the IP numbers with those from your machine if necessary)
Note: Do not click on the 'Scratch Handler' icon ion the desktop!
If everything is correct, the terminal window will now show:
Connecting … Connected!
sending sensor-update 'piface-input1' 0
sending sensor-update 'piface-input2' 0
sending sensor-update 'piface-input3' 0
sending sensor-update 'piface-input4' 0
sending sensor-update 'piface-input5' 0
sending sensor-update 'piface-input6' 0
sending sensor-update 'piface-input7' 0
sending sensor-update 'piface-input8' 0
Minimise the LXTerminal Window (don't close it) and maxmise Scratch again - you should now be good to go.
It's messy but simples when you know how. Hopefully someone will create an set up program or installation script that will automate this process for those of a nervous disposition - i.e. non-specialist ICT Teachers
Note: Make sure not to close the terminal window or else the connection with the 'scratch_handler' will be lost.
Using Scratch:
(Sorry, being a text-based description with no graphics, this is very verbose and, as I don't know the correct Scratch terms yet, I'm using my own i.e. 'button', 'control' and 'program window' in these instructions)
To program the outputs:
1) In Scratch, click on the 'Variables' button (top left corner of Scratch) followed by the 'Make a variable' button (which appears below)
2) Type piface-output1 into the pop up dialog box and click OK
3) Repeat this seven more times with different numbers ie piface-output2, piface-output3 etc to make variables for all 8 outputs
To make the PiFace LED 1 flash 10 times
1) Click on the 'Control' button (top left corner of Scratch) and drag the 'when space key is pressed' control to the empty 'program window' on the right
2) Drag the 'repeat 10' control to the 'program window' and drop it directly below the 'when space is pressed' control so that the two become attached
3) Drag two separate copies of the 'wait 1 secs' control and leave them unconnected in the lower half of the 'program window'
4) Click on the 'Variables' button and drag 'set piface-output1 to 0' to the 'program window'. Change the value of the output from 0 to 1 in the control
5) Drag one of the 'wait 1 secs' controls (from the lower half of the screen) underneath the 'set piface-output to 1' control so that it attaches to it
6) Drag another copy of 'set piface-output1 to 0' to the 'program window' and drop it below the 'wait 1 secs' control so that it attaches to it.
7) Drag the other 'wait 1 secs' controls (from the lower half of the screen) underneath the 'set piface-output to 0' control so that it attaches to it
Now, if you press the 'space key' on the keyboard the program should run immediately and LED 1 should flash on and off 10 times. It's interesting to note that once the program controls are dropped in the program window they can be run just by clicking on them - or in this case by pressing the 'space' key.
To program the inputs:
(this carries on from using the program created for flashing LED 1 above)
1) Click on the 'Control' button (top left corner of Scratch) and then drag the 'forever if' control into the lower half of the program window
2) Click on the 'Operators' button and drag the green '[ ] > [ ]' control on to the empty space of the same shape in the 'forever if' control
3) Click on the 'Sensing' button (top left corner of Scratch) and drag the blue 'sensor value' control into the first white box in the 'forever if' control
4) In the 'sensor value' control, change the dropdown value from 'slider' to 'piface-input1' Note: if there are no piface-inputs available, the connection has been lost with the scratch handler and the 'setup' routine outlined above will need to redone.
5) In the second white box after the > operator, type 0
6) Separate the 'when space key is pressed' control from the 'repeat 10 loop' in the previous program (by dragging the 'repeat 10 loop' away from it and then delete the 'when space key is pressed' control by dragging and dropping it left out of the program window
7) Finally, drag the 'repeat 10 loop' and drop it inside the 'forever if' loop so that it connects
Click on the 'forever if' loop and the program will run, but nothing will happen until the PiFace's Input 1 switch is pressed (or a switch is connected to the PiFace and pressed). When the Input 1 switch is pressed, the loop will start flashing the LED 1 10 times. This will continue forever or until you stop it due to boredom!
This should be enough to give anyone the basic concepts of using Scratch to control the Raspberry Pi with the PiFace interface. It would be much better to use graphics to explain the Scratch programming and so I will probably do this somewhere on the web. Any constructive comments are welcome including notification of any typos.
Hope this helps the RPi community.
Martyn (jones_mp@yahoo.com)
P.S.
PiFace Emulator:
All the above instructions will also work with the PiFace Emulator (a graphical simulation of the PiFace included with the Raspian image provided by the PiFace team) too, so you don't actually need to have a PiFace to try them out. To use the emulator (instead of or as well as the PiFace) add the -e switch to Step 6 of the Setup instructions above so that it becomes:
cd piface/scratch
python scratch_handler.py -e 127.0.1.1 (or whatever the IP address Scratch gives to your machine)
How to use Scratch to control the Raspberry Pi PiFace interface - A Guide for Dummies (like me)
Pre-requisite:
1) Download the 4gb Raspbian Linux SD Card image from the PiFace team from here (http://pi.cs.man.ac.uk/download/). This includes all the required libraries and extension programs (including a graphical emulator of the PiFace) for interfacing the PiFace with Scratch, including a modified version of Scratch. You can download and install the additional components yourself, but this is much easier.
2) Burn the .img to SD card using your preferred method (check the web if you don't know how), insert into the RPi with a keyboard, mouse and monitor attached, connect the PiFace and boot the RPi (network or internet access is not needed unless you want to use ssh/vnc for remote access) Login with pi and raspberry as usual and type startx at the command prompt to run the desktop environment.
Setup:
3) Run Scratch from the desktop and then shift-click on 'Share' in the top menu line
4) Select 'Host Mesh' from the drop down menu
5) Note IP address displayed (mine was 127.0.1.1) and click OK
6) Minimise Scratch (don't close it) and run LXTerminal from the desktop. Type in the following commands at the pi@raspberrypi$ prompt in the terminal window:
cd piface/scratch
python scratch_handler.py 127.0.1.1 (replacing the IP numbers with those from your machine if necessary)
Note: Do not click on the 'Scratch Handler' icon ion the desktop!
If everything is correct, the terminal window will now show:
Connecting … Connected!
sending sensor-update 'piface-input1' 0
sending sensor-update 'piface-input2' 0
sending sensor-update 'piface-input3' 0
sending sensor-update 'piface-input4' 0
sending sensor-update 'piface-input5' 0
sending sensor-update 'piface-input6' 0
sending sensor-update 'piface-input7' 0
sending sensor-update 'piface-input8' 0
Minimise the LXTerminal Window (don't close it) and maxmise Scratch again - you should now be good to go.
It's messy but simples when you know how. Hopefully someone will create an set up program or installation script that will automate this process for those of a nervous disposition - i.e. non-specialist ICT Teachers
Note: Make sure not to close the terminal window or else the connection with the 'scratch_handler' will be lost.
Using Scratch:
(Sorry, being a text-based description with no graphics, this is very verbose and, as I don't know the correct Scratch terms yet, I'm using my own i.e. 'button', 'control' and 'program window' in these instructions)
To program the outputs:
1) In Scratch, click on the 'Variables' button (top left corner of Scratch) followed by the 'Make a variable' button (which appears below)
2) Type piface-output1 into the pop up dialog box and click OK
3) Repeat this seven more times with different numbers ie piface-output2, piface-output3 etc to make variables for all 8 outputs
To make the PiFace LED 1 flash 10 times
1) Click on the 'Control' button (top left corner of Scratch) and drag the 'when space key is pressed' control to the empty 'program window' on the right
2) Drag the 'repeat 10' control to the 'program window' and drop it directly below the 'when space is pressed' control so that the two become attached
3) Drag two separate copies of the 'wait 1 secs' control and leave them unconnected in the lower half of the 'program window'
4) Click on the 'Variables' button and drag 'set piface-output1 to 0' to the 'program window'. Change the value of the output from 0 to 1 in the control
5) Drag one of the 'wait 1 secs' controls (from the lower half of the screen) underneath the 'set piface-output to 1' control so that it attaches to it
6) Drag another copy of 'set piface-output1 to 0' to the 'program window' and drop it below the 'wait 1 secs' control so that it attaches to it.
7) Drag the other 'wait 1 secs' controls (from the lower half of the screen) underneath the 'set piface-output to 0' control so that it attaches to it
Now, if you press the 'space key' on the keyboard the program should run immediately and LED 1 should flash on and off 10 times. It's interesting to note that once the program controls are dropped in the program window they can be run just by clicking on them - or in this case by pressing the 'space' key.
To program the inputs:
(this carries on from using the program created for flashing LED 1 above)
1) Click on the 'Control' button (top left corner of Scratch) and then drag the 'forever if' control into the lower half of the program window
2) Click on the 'Operators' button and drag the green '[ ] > [ ]' control on to the empty space of the same shape in the 'forever if' control
3) Click on the 'Sensing' button (top left corner of Scratch) and drag the blue 'sensor value' control into the first white box in the 'forever if' control
4) In the 'sensor value' control, change the dropdown value from 'slider' to 'piface-input1' Note: if there are no piface-inputs available, the connection has been lost with the scratch handler and the 'setup' routine outlined above will need to redone.
5) In the second white box after the > operator, type 0
6) Separate the 'when space key is pressed' control from the 'repeat 10 loop' in the previous program (by dragging the 'repeat 10 loop' away from it and then delete the 'when space key is pressed' control by dragging and dropping it left out of the program window
7) Finally, drag the 'repeat 10 loop' and drop it inside the 'forever if' loop so that it connects
Click on the 'forever if' loop and the program will run, but nothing will happen until the PiFace's Input 1 switch is pressed (or a switch is connected to the PiFace and pressed). When the Input 1 switch is pressed, the loop will start flashing the LED 1 10 times. This will continue forever or until you stop it due to boredom!
This should be enough to give anyone the basic concepts of using Scratch to control the Raspberry Pi with the PiFace interface. It would be much better to use graphics to explain the Scratch programming and so I will probably do this somewhere on the web. Any constructive comments are welcome including notification of any typos.
Hope this helps the RPi community.
Martyn (jones_mp@yahoo.com)
P.S.
PiFace Emulator:
All the above instructions will also work with the PiFace Emulator (a graphical simulation of the PiFace included with the Raspian image provided by the PiFace team) too, so you don't actually need to have a PiFace to try them out. To use the emulator (instead of or as well as the PiFace) add the -e switch to Step 6 of the Setup instructions above so that it becomes:
cd piface/scratch
python scratch_handler.py -e 127.0.1.1 (or whatever the IP address Scratch gives to your machine)
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Great info 
Simon

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Scratch connectivity
What a lot of different topics this thread contains! 
re: uploading projects to the Scratch website. Just testing this today, and it seems to work well. So I'm assuming this issue is resolved!
re: PiFace - that's awesome! Shouldn't that be on it's own thread though, so people can find it?

re: uploading projects to the Scratch website. Just testing this today, and it seems to work well. So I'm assuming this issue is resolved!
re: PiFace - that's awesome! Shouldn't that be on it's own thread though, so people can find it?
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
The forum is in its early stages and creativity is to the fore as opposed to thread cohesion 
Until 2 weeks ago, we didn't even have a Scratch section
But PI-Face does need at least one thread on its own once a few people get one.
Simon

Until 2 weeks ago, we didn't even have a Scratch section

But PI-Face does need at least one thread on its own once a few people get one.
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Look at this that's been thrown into the mix
http://scratch.mit.edu/forums/viewtopic ... 0#p1375440
If you look at the video towards the end - you'll see that Kazuhiro seems to be controlling the GPIO ports via serial commands without any python program in the way
Simon
http://scratch.mit.edu/forums/viewtopic ... 0#p1375440
If you look at the video towards the end - you'll see that Kazuhiro seems to be controlling the GPIO ports via serial commands without any python program in the way

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
-
- Posts: 16
- Joined: Sun Jun 24, 2012 1:13 pm
Re: Scratch connectivity
I have now been informed of the correct Scratch terminology for items to which I refer in my post above about using the PiFace interface:
'button' - Blocks Palette
'control' - Blocks
'program window' - Scripts Area
Thanks to Steve Swindley (http://steve.swindley.co.uk/) for this.
'button' - Blocks Palette
'control' - Blocks
'program window' - Scripts Area
Thanks to Steve Swindley (http://steve.swindley.co.uk/) for this.
-
- Posts: 1
- Joined: Sun Dec 30, 2012 5:01 pm
Re: Scratch connectivity
Really useful
Thanks
Lee
Thanks
Lee
Re: Scratch connectivity
Hi,
I could really do with some help, I am doing this as part of my job and pulling my hair out! I've been looking for information for nearly a week now and it's driving me nuts!
Lord knows how the kids would cope!
It's almost like buying a gadget from China on Ebay with no instructions! All I keep getting is these guys telling me to reflash my SD card with their updated distro. With all I have done on mine so far, I don't think so! I want to keep mine that way I've made it!
Anyway sorry about the rant, any help or links would be awesome of you!
Ben
I could really do with some help, I am doing this as part of my job and pulling my hair out! I've been looking for information for nearly a week now and it's driving me nuts!
Lord knows how the kids would cope!
It's almost like buying a gadget from China on Ebay with no instructions! All I keep getting is these guys telling me to reflash my SD card with their updated distro. With all I have done on mine so far, I don't think so! I want to keep mine that way I've made it!
Anyway sorry about the rant, any help or links would be awesome of you!
Ben
GeekTeacher wrote:It's OK![]()
I've finally got my head around how to do it. Although technically correct, the instructions from the PiFace team are not at all clear for someone who is not familiar with the Scratch and Linux environment, even when they are experienced computer users. Anyway, I'm now controlling the PiFace with both Scratch and from Python and I offer my help to anyone who is having the same difficulties as I was two days ago.
Please don't come round to my house
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Hi Ben
Now you've got that off your chest
What's your actual question?
Simon
Now you've got that off your chest

What's your actual question?

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Scratch connectivity
Hi, I've found the guide quite useful for getting setup with scratch & piface on the pi. However, I'm really struggling with shift clicking anything over vnc. I need this to turn on mesh.
Anyone manage it?
Anyone manage it?
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Hopefully my tweet about using X11VNC has got you up and running 
Simon

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Scratch connectivity
Thanks Si, it turned out to be my vnc client. I also tried x11vnc, but in the end I've stuck with tightvnc on the pi as it seems a bit easier for me to run headless.
Now I've got a wireless raspberry pi drawing robot buggy that I program from scratch via VNC on another computer! http://www.flickr.com/photos/matthewven ... 724032000/
Cheers!
Now I've got a wireless raspberry pi drawing robot buggy that I program from scratch via VNC on another computer! http://www.flickr.com/photos/matthewven ... 724032000/
Cheers!
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Easier? - How?in the end I've stuck with tightvnc on the pi as it seems a bit easier for me to run headless.

X11VNC has the advantage (and I don't know of any disadvantages BTW) is that you can plug a monitor into the RPi and see what is going on with your session whereas if you use TightVNCServer, you won't see your activity as it doesn't show on the main display.
Unless things have changed in the last 6 months

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Scratch connectivity
Excellent post - many thanks. I didn't want to reflash my SD card so I installed the PiFace code and modified Scratch manually - will write this up on this site somewhere soon. After that I followed your instructions to the letter and all worked fine.
I did find that while editing the code it was better to turn the handler off as the CPU maxed out.
thanks again
I did find that while editing the code it was better to turn the handler off as the CPU maxed out.
thanks again
Re: Scratch connectivity
I would guess your problem with tightVNCServer is that it is running on a different DISPLAY. If you connect to it, run a terminal and typesimplesi wrote:Easier? - How?in the end I've stuck with tightvnc on the pi as it seems a bit easier for me to run headless.
X11VNC has the advantage (and I don't know of any disadvantages BTW) is that you can plug a monitor into the RPi and see what is going on with your session whereas if you use TightVNCServer, you won't see your activity as it doesn't show on the main display.
Code: Select all
echo $DISPLAY
Code: Select all
vncserver :0
-
- Posts: 2327
- Joined: Fri Feb 24, 2012 6:19 pm
- Location: Euxton, Lancashire, UK
- Contact: Website
Re: Scratch connectivity
Ta - I'll give that a go next time I'm setting up an SD card from the start 
Simon

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter