Open Propeller Project #5: MIT's Scratch and Propeller Multicore
Ken Gracey
Posts: 7,392
Open Propeller Project #5: Explore the Possibilities of MIT's Scratch 2.0 Extensions
We would like to develop a graphical programming interface for the Propeller
Graphical programming is very popular with our educational customers and we are continually reminded that we need to develop some type of MIT Scratch support for the Propeller. Why would you care about the funny cat carrying the Propeller Activity Board? First, you're a Propeller programmer and you understand what could be accomplished with our multicore architecture. And we all have a responsibility to share our interests and capabilities with future programmers.
This is your chance to contribute to the Parallax community through an important educational project. If we can achieve this goal, we will have a Scratch-supported, American-made hardware choice for STEM education. And you know we've got all hardware we need in the shield-free Propeller Activity Board at $49, so let's make this happen!
Open Propeller Project #5 is initially about exploration, discussion, and hopefully examples. We don't know what's possible and we don't have a set of specifications for our goal [yet]. Just like the iPad to ActivityBot effort lead to a bigger project of actually downloading code from iOS to Propeller over WiFi, this one could have a similar outcome. It could even become as big as Open Propeller Project #3, which is bringing open source Spin support to several operating systems!
We'll learn together, share what we develop, and maybe formalize our goals to take Scratch support for the Propeller to the next level. Maybe we'd build this into Learn.parallax.com, use it as the S3 robot programming interface, and who knows what else?
A few starting points:
http://scratch.mit.edu
http://wiki.scratch.mit.edu/wiki/Scratch_Extension_Protocol_(2.0)
http://wiki.scratch.mit.edu/w/images/ExtensionsDoc.HTTP-9-11.pdf
Let's start by doing a bit of research, experimenting and hopefully showing some of the possibilities with a real example. Maybe these questions will be answered along the way:
- Could the tool support multicore, having parallel program paths with shared memory?
- Programming blocks be used for sensors, like a Ping))), accelerometer, compass, etc.
- Invoke a command-line interface to the Spin or C compiler? Or is it really more appropriate to configure the Propeller from Scratch to do pre-defined functions?
- Suitability for an S3 Robot GUI?
- Ease of development?
Who's in on the Scratch effort with us?
Your support is appreciated more than you can imagine.
Sincerely,
Ken Gracey
Comments
Scratch is more it's own language. you wouldn't really use it to make Spin or C. You could extend it to output something that could drive an S2 given that the S2 had firmware loaded into it that could interpret the stuff Scratch communicates to it.
There's much more to learn, though. Any system we commit to must run on all operating systems and be able to communicate with our hardware. And whatever we produce has to be totally free.
Ken Gracey
John Abshier
It's a wonderful tool, but the educational community demands opens source (it is closed, for reasonable reasons) and free (it costs).
Ken Gracey
It's open source using the Apache License 2.0, which is similar to the MIT license.
It could likely be integrated into the work others have been doing with the web based spin editor/compiler (which is also javascript).
Talking to hardware is a going to be a platform specific thing solved in a case by case way. For Windows/Linux/Mac OSX, an exe tool could likely be used, such as propeller-load from the propgcc project. That could probably also cover Android with some work. For iOS perhaps the stuff Jeff Martin is working on?
Scratch 2.0 is a Flash program, so it's not going to work on iOS. Also, Flash is much more painful (in my experience) to work with. The older Scratch 1.4 is written in Squeak (which is a smalltalk variant), good luck with that one. :P
If Scratch is a requirement from your education customers, then you'll likely need to adjust what you want to get out of it. For example, if I understand it correctly, with Scratch you run your program in Scratch and then via the extensions it talks to the target (Activity board, or S3, or whatever). You don't write a program in Scratch, and then load that into the target and have the target run it. So you need to have continuous communication between your computer and the target, so wired or xbee. Scratch is a language, compiler, and runtime environment all in one.
One of the things I found was S4A (Scratch for Arduino), like Roy said, for that you basically have an agent program running on the Arduino that accepts commands from the Scratch interface, acts on them and then provides a reply. It uses the protocols set up with Scratch 2.0 to talk to extensions. Arduino has a similar agent (Firmata) which give s a very tight coupling with the Processing Language and allows you to manipulate the Arduino I/O through Processing (this would be cool for someone to port to the Propeller, by the way). Neither really have you programming the micro, it is always running it's little canned helper program looking for commands, processing them and sending replies back.
You need something like the S2 GUI or 12Blocks that actually generates source code for each block someone creates. Once you have that source code file, then processing it is the same as being done for the Web Based Development project (#3?): compile it, create a binary and somehow load it to the Propeller. I haven't looked at Blocky for a while but it might be better in that respect as a graphical programming front end...in addition to the points Roy brought up about Javascript versus Flash (Javascript good - Flash Bad!)
(Don't worry about Firmata, it's probably IMPOSSIBLE to port that to a Propeller...and who'd want to open the Propeller world up to Processing anyway? )
With squeak virtual machine running on top of Javascript, I wonder when scratch will return to its squeak origin.
best,
Allen
Tried to make it into a Windows executable, but couldn't get that to work.
Did figure out enough to install a page on my server that lets you assemble blocks and generate JavaScript:
http://www.rayslogic.com/Propeller/Programming/Blockly/BlocklyTest.htm (nothing really new here, just figuring out how their examples work...)
Maybe I'll see how hard it is to do Spin instead of JavaScript...
Great, Rayman! This marks the first bit of progress. Thankfully engineers can hardly resist taking a look at programming tools sometimes.
I think you're taking the first steps in figuring out the gotchas we might experience with a couple of these solutions.
Ken Gracey
https://code.google.com/p/blockly/
I dislike all the little extra blocks in the user interface.
I've spent several hours looking at the code, but still can't see how to make it generate Spin...
So, hopefully I'll figure that out, or look for some code that does javascript on a Propeller.
Building the code is interesting as it uses Google "closure", which I don't understand but looks interesting.
Somehow "closure" "compiles" javascript into a "compressed" javascript file.
Unobuscation looks tricky at this point, but hopefully, I'll figure it out...
JavaScript for micro-cotrollers is already done. Have a look at the Epruino http://www.espruino.com/ which was a kickstarter project: https://www.kickstarter.com/projects/gfw/espruino-javascript-for-things
The Espruino JavaScript interpreter has been open sourced and is available here: https://github.com/espruino/Espruino
Espruino already has a Blockly web programming IDE https://github.com/espruino/EspruinoWebIDE
Espruino is derived from the previous TinyJS https://github.com/gabonator/G42-tiny-js also by Gordon Williams.
TinyJS has been compiled for the Propeller. There is a thread about it some where on this forum. Sombody even got it to run I believe. Needs a big lot of external RAM.
We were looking forward to getting the Esruino code running on the P2. JS on the P1 will be horrible slow. Remember JS only has one number type and it's 64 bit floating point !
You need to look at the Language Generators. That's what we need to make a Spin flavor of... Going down the path of running JS on P1 is worthless.
The effort might have some value if the results are usable on the PII. But I fear that even the PII will be two slow to handle JS nicely.
Now, I think I just need to get a computer set up with python, the svn source, and closure source and should be all set...
BTW: I read somewhere that Chrome includes a serial port interface. Anyone know if that could be used to program the Propeller?
But that's OK because you can fetch a Chrome App from anywhere and install it into Chrome.
A Chrome app is a only a specially wrapped up web page basically. It's just that as an "app" the user is granting it some extra holes in the sand box to access such things as serial ports, local files and whatever.
For a while now it has been on my TODO list to build the loader from propgcc with Emscripten thus creating a JavaScript version. Thus providing a Propeller loader that will run in the browser.
I just saw how you can create an ActiveX program to send serial data, but I think that would only work on Windows...
As far as I know Chrome Apps work on Windows and Mac. Never used such a machine so I don't know for sure. Also good on Samsung Chrome Books.
Boo to Active X. Only works on legacy operating systems.
ActiveX would let it work from within the browser, but would be Windows only...
If it were to be a standalone app, looks like Qt Quick would be another option to work on all platforms...
So, maybe all that's left is to edit the generator files to make spin instead of javascript (well, I suppose that's the hard part).
Yes, Chrome Apps work on Mac! I'm running the Chrome Espruino Web App on Mac OS X...
dgately
Ray, you might want to make a copy of the python generator as the syntax should look a lot more like spin, no?
dgately
Chrome apps do not work in any other browser.
Chrome does cover Windows, Linux, Mac, and Android (although I doubt the same serial solution works on android as others).
And have a look at BlocklyDuino. They've added some nice blocks that will be useful on the propeller as well