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
to send ISS Altitude, Direction and Distance into my Scratch script
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
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…
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
See here to see the background info
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…
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 🙂