Better external Python calls from ScratchGPIO8dev
I’ve improved calling external Python scripts from ScratchGPIO8dev to allow for long time running programs.
This allows you to make your own mini sensor script to get some data from somewhere – your own sensors or from an Internet source and feed the values back into Scratch as sensor values.
I’m using this technique for my ISS Tracker Robot Arm project
To start data sensing I call this block
which calls this Python Script
http://pastebin.com/5LPpMwy2
to send ISS Altitude, Direction and Distance into my Scratch script
Note:
ScratchGPIO only handles one such process per program at the moment do don’t try and call 2 running processes.
Behind the scenes, ScratchGPIO will attempt to kill any previous launched external script but if you change the name of your script then you yourself should manually kill the old process
Hi,
is there a way to get data back from a python script to scratch? I don’t see an option to read a file or so in Scratch itself…
thanks!
Raf
ps: great work! 🙂
Yep. “All” you need do is send properly formatted data to port 42001 on the Pi (This is the way Scratch communicates with external programs by reading writing data to port 42001
here’s some example code
https://www.dropbox.com/s/4g4mfr8oml87udl/scratch_python_test.sb?dl=0
https://www.dropbox.com/s/dwhh4lv4kuawkb5/scratch_python_test.py?dl=0
See here to see the background info
https://wiki.scratch.mit.edu/wiki/Remote_Sensors_Protocol
ok, thanks! I’ll have a look.
Fyi, I’ve bought a sensorkit from joy-it (sensorkit.joy-it.net; all in german so you might need google translate). Most of their examples are in Python… But this way, it should be easier to access it from Scratch…
Raf
A lot of those modules will work directly with Nuscratch/ScratchGPIO directly – leds and switches for example – only need to write own python code for some of the specialist items
No need to re-invent the wheel 🙂