Sending messages between Raspberry Pi using ScratchGPIO
NB Only available in dev version
For a while I’ve wanted one computer running a Traffic Light program to easily talk to a Pi running as robot vehicle so that the robot can respond easily to the traffic light sequence.
And extending this to another robots crossing the lights as vehicles or pretend pedestrians!
I’ve added in a basic syntax for this
Link is used to setup connection to any other computer running Scratch with Remote Sensor Connections (RSC) enabled. (All ScratchGPIO instances running on Pi are and it can be simply enabled on other computers by users)
Then simply, prefix any broadcasts that you want to send to the other computer with Send. The other computer will receive the broadcast without the Send prefix e.g Stop or Go
Ideas to enhance/change
Let Link work with just last octet of IP (ie. assume on the same LAN and automatically determine first 3 octets. (easy)
Try and come up with using last 4 digits of serial num like SID uses (hard)
Or something to make it less geeky if possible (hard)
Add a prefix/identifier to the broadcast so that receiving computer can identify/filter/differentiate non-local broadcasts (to prevent advanced Scratchers from taking control of a remote Scratch device without permission and make it possible to have more 1 computer sending messages into a remote computer)
The code is in the dev version (but liable to change) but please have a play and pass on your ideas/thoughts
Please remember my target audience are 7-11 year olds and their teachers 🙂
I’m trying to broadcast through one raspberry to another with its IP address but it doesn’t work. Could you help me?
I’m trying a simple broadcast lie your example, but nothing.
Are you using the dev version ?
Just tried between Pi and and XP machine using dev version and it works ok – I did broadcast link192.168.0.11
then broadcast sendhello
then on XP I did when I receive hello
say hello for 10 secs
Clicked on broadcast sendhello on Pi and my XP machine said Hello 🙂
Make sure also that receiving compueter has Remote Sensor Connections enaabled
ther is a bug on Pi that means you have to disable then re-enable it to make it work properly 🙂
I’m trying between two raspberrypi, but I’m gonna try re-enabling de Remote Sensor Conection and then let you know if it works.
I’m sorry I’m a little noob on this.
I have onde rpi on 192.168.1.107 and another on 192.168.1.108 and I’v open Scratch on both and both send the message “Remote Sensor Connections enabled”.
Then I made this simple code:
On rpi with 192.168.1.107:
When “GreenFlag” clicked
Broadcast Join Link 192.168.1.108
Broadcast Send roda
On rpi with 192.168.1.108 I have:
When I receive roda
turn 15 degrees
Now when I click on the green flag on rpi (192.168.1.107) just don’t work 🙁
By the way, I didn’t find out how to disable and re-enable the Remote Sensor Connections 🙁
So, sorry to bother you again, but can you help me on this?
1st thing is that once link is set up the broadcast isn’t needed again.
So try on green flag broadcast link ……
Then make space bar do broadcast send roda
I’ll power up 2 pi later to check myself
PS must be running dev version.
Your the 1st person to test it 🙂
Thanks in advance for your support.
I’ll try that.
Just on more thing: how can I check if I’m running the dev version? If not, from where can I install it ?
I’ve made it clear in the blog post – ta for pointing it out
I’m keen to get some feedback on this feature and then expand it to talk to more than just 1 other Scratch instance
I found that I was not runnig the dev version.
I’ve installed it (from your blog) and now with just this:
When “greenflag” clicked
Broadcat join Link 192.168.1.107
When “spave” key pressed
boradcast “Send roda”
On Scratch rpi2:
When I receive roda
repeat 10 turn 15 degrees
Should I activate Scratch rpi2 somehow to turn it to listening mode?
rpi2 needs to be running ScratchGPIO 🙂
Still not working 🙁
rpi1 with ScratchGPIOdev
rpi2 with ScratchGPIO
🙁 try this.
Run normal Scratch
File-open and load in rsc
The Remote Sensor Connection box should come up
type in your receiving script
See what happens
I have found a fault in the dev version which only shows up on new installs – I will fix and get back to you 🙂 Sorry about this but that is why it is called dev version 🙂
I think I have fixed it now 🙂
redownload dev version on both rpi
run ScratchGPIO Dev on both RPi
it should work now 🙂
Finally I got it working 🙂 Thank You!!!
Listen, I know this is not the subject, but… have you ever tried to control an Ultrasonic Sensor with Scratch? I think its possible. Is this ScracthGPIO Dev prepared for it?
Once again, it Works!!
Now I’m gonna try to interact with 3 RPI and then I let you know how it goes 🙂
Great – thnaks for persevering 🙂
Ultrasonics has been around for a while
Link only tested with one other computer at a time – let me know how 3 Pi go
So just to let you know 🙂
It works with 3 PI. I can exchange “messages” between them.
By the way, I’ve made a simple test with a Stepper motor connected to a Pibrella and it worked ok 🙂
Now I would like a last try – with the Ultrasonic Sensor, but I only found a schema with a breadboard and some resistors. I wonder if there’s a chance to connect it directly to the Pibrella. What do you think?
I tried with the single pin wiring setup and failed but it might be worth seeing if normal 2 pin can be made to work-let me think 🙂
I’ve already connected the Ultrasonic Sensor with a breathboard to the RPI through a Pibrella board.
On Scratch I’ve found the “distance sensor value” Sensing option, but it returns always zero 🙁
Same with me – I think the protection on the inputs prevents single pin use – might be worth trying someone’s python code that uses both pins separately
My problem is how should I communicate between two RPIs, one with Scratch and other with Python 🙁
It would be more easy with all steps achieved using only Scratch.
use https://github.com/pilliq/scratchpy in your python code?
I’ve found some coding in Python to broadcast to Scratch and learn from it.
I’ve made some adjustments and now I can broadcast to Scratch and sequence the other RPIs on Scratch. Basically I read some sensor values, send them to Scratch by broadcast and then it interacts with 3 other RPIs 🙂
“Please remember my target audience are 7-11 year olds and their teachers …”
RFC: Whilst your ScratchGPIO is an utterly and unalloyed-ly brilliant project , if that is your actual target audience then either a) the rate of change of your API needs to moderate, or b) the documentation needs to march in lockstep with changes to the API.
Otherwise your target audience is likely to get left behind.
I am really bad at documention but I’d had an offer of some help recently 🙂
I think if there had been any co-ordination AT ALL between the Foundation and its open-source software developers, then the huge gap in having working software that has occured since Christmas might have been minimised.
But NO-ONE told ANYBODY ANYTHING (inc me 🙂
But you point is well made and ScratchGPIO6 was my “vista” version
Hopefully V7 will be stable for a year but if the Foundation pull any more big suprises without any warning – I think quite a number of us will be packing up and going home 🙁
All is not well at all in the community 🙁