This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-20 04:48:39

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

A mod to launch RaspberryPi python handler

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?  smile

Simon

Offline

 

#2 2012-07-20 06:41:04

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#3 2012-07-20 13:20:05

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: A mod to launch RaspberryPi python handler

What is the difference between Mesh and Remote Sensor Connections?
Simon

Offline

 

#4 2012-07-20 15:32:17

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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.  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#5 2012-07-21 03:03:10

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: A mod to launch RaspberryPi python handler

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  smile

And - even better - if I've enabeld RSC and saved a project - RSC is restarted when I load the project  smile 

That will do me for the moment - might need to come back to auto-launching my python GPIO handler script later  smile

Simon

Offline

 

#6 2012-07-21 04:20:30

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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)


You can now reach me on Twitter @johnnydean1_

Offline

 

#7 2012-07-21 06:44:19

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

I can write this for you, I'm working on something similar right now.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#8 2012-07-21 10:17:06

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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

 

#9 2012-07-21 10:31:38

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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.


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&display=small

Offline

 

#10 2012-07-21 13:11:18

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

SimpleScratch wrote:

if I've enabeld RSC and saved a project - RSC is restarted when I load the project  smile 

That will do me for the moment - might need to come back to auto-launching my python GPIO handler script later  smile

Great!  smile

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.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#11 2012-07-26 14:28:35

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: A mod to launch RaspberryPi python handler

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  smile  ) and I've made a new desktop shortcut (called ScratchRSC  smile  ) that execs  "scratch --document /home/pi/Scratch/rsc.sb" - so nearly there now without having to mod Scratch itself  smile

I'm off to play with the Python script  smile
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

 

#12 2012-07-26 15:03:50

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: A mod to launch RaspberryPi python handler

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)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#13 2012-08-12 21:35:26

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: A mod to launch RaspberryPi python handler

Things are progressing - the python program is a lot less CPU intensive (a bit more sleeping in loops than before  smile  )

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  sad
http://scratch.mit.edu/forums/viewtopic.php?id=103605

Offline

 

Board footer