I've managed to bodge together a RaspberryPi, a Mesh enabled Scratch mod and a Python message handler to bridge between Scratch and the GPIO pins.
To make life easy for others I thought it would be great if Scratch could be modded to not only enable Mesh,, but to launch a host session and also launch the python handler script so all a user would have to do would be connect hardware to the GPIO and run the modded Scratch.
Is it possible and is someone up for it?
Simon
Offline
Is it easier to use Remote Sensor Connections? You could mod Scratch to enable them by default; and then write a small shell script to launch the python script and then the Squeak VM.
It only has to work on Linux, right?
Offline
What is the difference between Mesh and Remote Sensor Connections?
Simon
Offline
They implement the same protocol, but one might be easier to enable by default.
I think once enabled, remote sensor connections automatically start listening on the RSC port. Then Python could just connect to the socket.
Offline
Ok - learning fast here - seems RSC is just a local machine version of Mesh - my Python handler program seems to work with normal Scratch with RSC enabled just as well as using a modified Scratch with Mesh enabled
And - even better - if I've enabeld RSC and saved a project - RSC is restarted when I load the project
That will do me for the moment - might need to come back to auto-launching my python GPIO handler script later
Simon
Offline
RSC is local mesh, and mesh is over a network. However when mesh is used its handled by RSC (On each client).
If you want to think about it like this:
RSC is all external I/O in Scratch.
Mesh acts like a new "sensor" and allows connections to other devices.
Last edited by johnnydean1 (2012-07-21 04:21:48)
Offline
I can write this for you, I'm working on something similar right now.
Offline
Remote Sensor Connections is "basically" hosting a Mesh network on Scratch, since both hosting and enabling RSC does the same thing. All Mesh does, is make it so you can directly connect with another computer without needing to program it yourself or create a proxy.
For what you want to do, is look for a SmallTalk command that runs OS commands (i.e. "python script.py"). https://www.google.com/search?q=smallta … l+commands
Offline
Magnie wrote:
Remote Sensor Connections is "basically" hosting a Mesh network on Scratch, since both hosting and enabling RSC does the same thing. All Mesh does, is make it so you can directly connect with another computer without needing to program it yourself or create a proxy.
For what you want to do, is look for a SmallTalk command that runs OS commands (i.e. "python script.py"). https://www.google.com/search?q=smallta … l+commands
Magnie talk gives me the dumb. o.e
Kiddin'. Thanks Magnie! Very useful stuff.
Offline
SimpleScratch wrote:
if I've enabeld RSC and saved a project - RSC is restarted when I load the project
![]()
That will do me for the moment - might need to come back to auto-launching my python GPIO handler script later![]()
Great!
I still think the easiest way is to write a shell script that runs the Python script in the background (isn't the syntax something like "python gpio.py &" ?) and then launches Scratch/the Squeak VM.
Offline
My main problem at the moment is that my python program needs to "hear" Scratch talking to it when it launches so I need to launch Scratch with RSC enabled before launching my python script.
I've sorted launching Scratch with RSC enabled by creating a blank project (called /home/pi/Scratch/rsc.sb
) and I've made a new desktop shortcut (called ScratchRSC
) that execs "scratch --document /home/pi/Scratch/rsc.sb" - so nearly there now without having to mod Scratch itself
I'm off to play with the Python script
For info - this is where I'm at now
http://cymplecy.wordpress.com/2012/07/20/how-i-got-scratch-talking-to-my-raspberry_pi/
Offline
Don't you just need to try connecting several times until you're successful? Perhaps wrap the "create socket" call in a while loop, or something.
Perhaps then you can modify your desktop shortcut to read something like
scratch --document /home/pi/Scratch/rsc.sb; sudo python scratch_gpio_handler.py
Or even add a "wait" command, like
scratch --document /home/pi/Scratch/rsc.sb; wait 10; sudo python scratch_gpio_handler.py
Last edited by blob8108 (2012-07-26 15:04:42)
Offline
Things are progressing - the python program is a lot less CPU intensive (a bit more sleeping in loops than before
)
Its easy (I now know) to launch a python prog and then Scratch in one script (and the python program just waits for RSC to be enabled now so thats sorted)
http://cymplecy.wordpress.com/2012/07/20/how-i-got-scratch-talking-to-my-raspberry_pi/
gives upto date info - just looking into the other problems at the moment
http://scratch.mit.edu/forums/viewtopic.php?id=103605
Offline