Interfacing to external programs

Request a new command, feature, or improvement

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Interfacing to external programs

Post by SimpleSi » Jul 2nd, '17, 21:33

Hi
I've done a lot of stuff over the years in getting Scratch/BYOB controlling the pins on the Raspberry Pi thru a python handler that listens/responds to Scratch 1.4 type broadcast/sensor-update msgs.

So when we get a version of GP that runs natively on the Pi - it would be really nice if there was a method that was at least as good as the old 1.4 facility, to help do this.

Having the broadcast send out 1.4 type broadcast msgs would be perfect of course :)

Today, I've managed to make a very simple "cloud server" listener on a Pi ( having modified CloudDataServer.gp to point to the Pi ip address) as a proof of concept and I'm looking forward to the native Pi binary coming out soon to see if it will work natively.

regards Simon
SimpleScratch on ScratchForums/ @cymplecy Twitter

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Interfacing to external programs

Post by JohnM » Jul 2nd, '17, 23:40

Nice to meet you, SimpleSi.

You've already discovered that the CloudData server is written in GP itself. The server pointed to by the cloud data blocks runs on a DigitalOcean server (only $5/month!). As you probably discovered, you can run GP headless by invoking it from the command line, and you've seen that the protocol used by the CloudData server is a simple binary message protocol implemented in 'messageServer.gp'.

Earlier today I pushed a new version of GP (v068) with a RaspberryPI executable. It should not need any non-standard libraries because I statically linked in libraries like SDL2, but it's possible I missed some dependency. Let me know it works for you.

I haven't explored how to access pins in the Raspberry Pi. Sounds like there is a Python API for that? GP can talk to a serial port, if that's of any use. However, since you've already got a server that understands the old Scratch 1.4 mesh networking protocol and talks to the pins, I agree it's probably easiest to have GP talk to that. I don't think it would be too difficult for someone like to you implement the Scratch protocol in GP, perhaps after studying the messageServer code as a model for how to use GP's socket API. Let me know if you need any help or advice.

Will you be at the Scratch conference in Bordeaux by any chance?

-- John

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: Interfacing to external programs

Post by SimpleSi » Jul 3rd, '17, 08:00

Thanks for the info - I'll look into your suggestions :)

Won't be going to Bordeaux unfortunately :(

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: Interfacing to external programs

Post by JohnM » Jul 9th, '17, 01:13

I understand the the IO pins on the Raspberry Pi can be controlled by writing to certain files. If that's the case, GP can control them directly, since GP has file read and write commands. (They are in the "Words" category.)

If you need to read and write binary data to work with the I/O pins, that's possible by might require using some normally hidden features. If you need help with this, let me know. I'll be busy preparing for and attending the Scratch conference the next two weeks, so I can't dig in and help, but I can at least point you in the right directions...

Post Reply