jon wise
Posts: 49
Joined: Thu May 31, 2012 8:21 pm

Broadcast to Python

Sun Nov 15, 2015 9:05 pm

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.

ghp
Posts: 1555
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Broadcast to Python

Sun Nov 15, 2015 9:53 pm

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

jon wise
Posts: 49
Joined: Thu May 31, 2012 8:21 pm

Re: Broadcast to Python

Mon Nov 16, 2015 1:59 pm

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.

ghp
Posts: 1555
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Broadcast to Python

Mon Nov 16, 2015 2:45 pm

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

jon wise
Posts: 49
Joined: Thu May 31, 2012 8:21 pm

Re: Broadcast to Python

Tue Nov 17, 2015 8:49 am

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.

timrowledge
Posts: 1354
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Broadcast to Python

Tue Nov 17, 2015 7:56 pm

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.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

jon wise
Posts: 49
Joined: Thu May 31, 2012 8:21 pm

Re: Broadcast to Python

Wed Nov 18, 2015 6:28 pm

If I run Scratch on the laptop, how do I set up scratch to broadcast to a url other than localhost?

ghp
Posts: 1555
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Broadcast to Python

Thu Nov 19, 2015 8:04 pm

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

ghp
Posts: 1555
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Broadcast to Python

Thu Nov 19, 2015 8:05 pm

For the scratch-scratch-communication, look for the mesh-connections http://wiki.scratch.mit.edu/wiki/Mesh
I

timrowledge
Posts: 1354
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Broadcast to Python

Thu Nov 19, 2015 8:39 pm

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.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Return to “Scratch”