Page 1 of 1

Broadcast to Python

Posted: Sun Nov 15, 2015 9:05 pm
by jon wise
I would like my Scratch program to broadcast messages to a Python program. I am running the up-to-date version of Scratch on Jessie but no success so far. Any help would be appreciated.

Re: Broadcast to Python

Posted: Sun Nov 15, 2015 9:53 pm
by ghp
Hello,
you need to enable remote sensor connections. In 'sensing', sensor values, rightclick and enable. Be sure to have only one scratch with enabled remote protocol enabled around.
To check the output, open a telnet session 'telnet localhost 42001', you should see broadcasts there (but do not enter any values in telnet for this setup, as it would confuse the protocol).
There is some information in http://wiki.scratch.mit.edu/wiki/Python.
Good luck,
Gerhard

Re: Broadcast to Python

Posted: Mon Nov 16, 2015 1:59 pm
by jon wise
Thank you, it is now working.
Is it possible to enable remote sensor connections automatically at start up? I am planning to use this in school and it would be neater to avoid that right-clicking.

Re: Broadcast to Python

Posted: Mon Nov 16, 2015 2:45 pm
by ghp
Hello,
this setting is stored with the project. The only flaw is that the 'remote sensor connection is enabled'-popup is shown at each start.
We use similiar setup in a school, and the kids get used to enable this in new projects.
What are you planning to do with the python code ?

Regards,
Gerhard

Re: Broadcast to Python

Posted: Tue Nov 17, 2015 8:49 am
by jon wise
The Python is driving stepper motors to power a battery driven 'car'. Scratch was found to be too slow to run the motors directly. The Raspberry Pi is running headless and providing a WiFi host so it can be controlled by a laptop without needing access to the school network. The laptop runs Scratch on the Pi using ssh -X.

Re: Broadcast to Python

Posted: Tue Nov 17, 2015 7:56 pm
by timrowledge
Is a Pi able to provide sufficient current for this? You might be better off using a driver board, a couple of which are supported under the GPIOServer right now. With sufficient persuasion I could add the stepper motor support they claim to offer.

Another option that might be even better long-term is an add-on that provides both electronic side drivers and software side drivers, so that the Pi need only send an occasional do-this-do-that command.

If Scratch running on the Pi is really too slow for your needs, consider running Scratch on your laptop and ScratchGPIO only on the Pi.

Re: Broadcast to Python

Posted: Wed Nov 18, 2015 6:28 pm
by jon wise
If I run Scratch on the laptop, how do I set up scratch to broadcast to a url other than localhost?

Re: Broadcast to Python

Posted: Thu Nov 19, 2015 8:04 pm
by ghp
Hello,
I was curious to see how fast various approaches to drive steppers are. DMA as a fast reference pattern, python, my scratchClient-framework with scratch and the new build in GPIOServer.
Results are in http://heppg.de/ikg/wordpress/?p=710 with some charts.

Summary: python is quite close to perfection, GPIO server is 12 times slower and scratch with scratchClient is 40 times slower.
A good reason to use a more complex python module, doing the steps low level and being controlled by scratch with high level commands. scratchClient has a module like this on board.

Regards,
Gerhard

Re: Broadcast to Python

Posted: Thu Nov 19, 2015 8:05 pm
by ghp
For the scratch-scratch-communication, look for the mesh-connections http://wiki.scratch.mit.edu/wiki/Mesh
I

Re: Broadcast to Python

Posted: Thu Nov 19, 2015 8:39 pm
by timrowledge
jon wise wrote:If I run Scratch on the laptop, how do I set up scratch to broadcast to a url other than localhost?
No need to set any IP etc for broadcasting since it.. broadcasts. What you *do* need is the IP number of the Pi running the Scratch so the clients can be connected and know what to listen for. Now, there is currently a bug that makes that more annoying than it should be; a while back something was changed in the Debian world (from which Rasbpian is built) whereby the old api for finding out the IP number was deliberately messed up. Since I didn't know about this until too late, the current Scratch will tell you the IP is 127.0.1.1, which is not very helpful. It's fixed for the upcoming release, by the way.

So, you'd need to manually use something like ifconfig to find your Pi's IP. You'll get a longish listing of gibberish but you need to look out for either 'eth0' or 'walnut' and there should be 'init addr: 192.168.1.42' or similar.