Shop OBEX P1 Docs P2 Docs Learn Events
Open Propeller Project #5: MIT's Scratch and Propeller Multicore — Parallax Forums

Open Propeller Project #5: MIT's Scratch and Propeller Multicore

Ken GraceyKen Gracey Posts: 7,392
edited 2014-04-02 18:00 in Propeller 1
OPP-ScratchExplore.png

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?
It may be too early to get started if they haven't released the Scratch 2.0 Extensions and documentation yet, but they're coming "in April".

Who's in on the Scratch effort with us?

Your support is appreciated more than you can imagine.

Sincerely,

Ken Gracey

600 x 250 - 101K
«13

Comments

  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2014-03-27 01:01
    I think a better choice would be to use Google's Blockly. It's designed to let you build code with blocks and then generate source code in a "target" language. You can also extend it with more block types.

    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.
  • RaymanRayman Posts: 14,641
    edited 2014-03-27 03:24
    Blockly does look pretty good. I think I read before that it is based on Scratch...
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2014-03-27 09:55
    Blockly could be another fine alternative for our needs. I came across an Arduino example in which Blockly generated the code, produced a file, and the user copied it into the Arduino IDE. Therefore it could also be done for Propeller, but I wonder about actually launching a full download.

    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 AbshierJohn Abshier Posts: 1,116
    edited 2014-03-27 10:43
    What about Hanno's 12Blocks?

    John Abshier
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2014-03-27 10:54
    What about Hanno's 12Blocks?

    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
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2014-03-27 11:08
    Blockly is written in javascript, it's meant to be integrated into a web application, so it should run on most platforms that have a browser that supports javascript.

    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.
  • mindrobotsmindrobots Posts: 6,506
    edited 2014-03-27 11:41
    Roy Eltham wrote: »
    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? :innocent:)
  • iammegatroniammegatron Posts: 40
    edited 2014-03-27 12:04
    It's interesting that the earlier scratch (1.4 -) was based on smalltalk/squeak. They moved to flash probably due to web browser support.

    With squeak virtual machine running on top of Javascript, I wonder when scratch will return to its squeak origin.
  • allenselisallenselis Posts: 1
    edited 2014-03-27 19:33
    Have a look at the Aseba language. It has a graphical editor that dynamically writes text code in a facing window. It works very nicely-and would be great to have the same tool for a Scratch-to-C course.

    best,

    Allen
  • RaymanRayman Posts: 14,641
    edited 2014-03-28 13:56
    Spent an hour playing around with Blockly...
    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...
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2014-03-28 14:06
    Rayman wrote: »
    Spent an hour playing around with Blockly...

    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
  • JonnyMacJonnyMac Posts: 9,102
    edited 2014-03-29 06:49
    Very cool, Ray. Interesting that the "block" for doing loops is "repeat __ times" -- the block already matches Spin syntax.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-30 11:52
    Blockly code generator for spin will be super easy to implement - just look at the BlocklDuino example.
    https://code.google.com/p/blockly/

    I dislike all the little extra blocks in the user interface.
  • RaymanRayman Posts: 14,641
    edited 2014-03-30 16:45
    Well, I've noticed that the more advanced a code is, the more obfuscated it becomes...
    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...
  • Heater.Heater. Posts: 21,230
    edited 2014-03-31 00:07
    Rayman,

    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 !
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2014-03-31 01:36
    Rayman,
    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.
  • Heater.Heater. Posts: 21,230
    edited 2014-03-31 01:48
    Roy,
    Going down the path of running JS on P1 is worthless.
    Which isn't to say that there aren't those of us who will give it a try :)

    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.
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 07:59
    I think I just found the generator files I was looking for. Don't know how I missed them earlier...

    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?
  • Heater.Heater. Posts: 21,230
    edited 2014-03-31 08:06
    Chrome has a serial port interface but only for Chrome Apps not regular web pages.

    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.
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 08:14
    That would be a neat trick. It would be cool if Blockly could program a Propeller directly. Would that Chrome app work in Linux, OSX, and Windows too?

    I just saw how you can create an ActiveX program to send serial data, but I think that would only work on Windows...
  • Heater.Heater. Posts: 21,230
    edited 2014-03-31 08:32
    It would be a neat trick. We managed to get the C++ openspin compiler converted to JS and working in the browser very well so I have hope we can do it for the loader.

    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.
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 08:43
    I was just reading that Chrome Apps don't work from within a browser, they work as if they were a stand alone application, is this right?

    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...
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 09:48
    Just figured out how to "compile" Blockly... Also, I made a copy of the JavaScript generator files and did a global replace of "Blockly.Javascript" with "Blockly.Spin" and it seemed to work and created the "spin_compressed.js" file needed.

    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).
  • dgatelydgately Posts: 1,630
    edited 2014-03-31 10:13
    Heater. wrote: »
    As far as I know Chrome Apps work on Windows and Mac

    Yes, Chrome Apps work on Mac! I'm running the Chrome Espruino Web App on Mac OS X...


    dgately
  • dgatelydgately Posts: 1,630
    edited 2014-03-31 10:15
    Rayman wrote: »
    I made a copy of the JavaScript generator files and did a global replace of "Blockly.Javascript" with "Blockly.Spin" and it seemed to work.

    Ray, you might want to make a copy of the python generator as the syntax should look a lot more like spin, no?


    dgately
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 10:52
    dgately, actually, now that you mention it... With the indenting and all, python might be a much better starting point...
  • Heater.Heater. Posts: 21,230
    edited 2014-03-31 14:01
    Ray,
    I was just reading that Chrome Apps don't work from within a browser, they work as if they were a stand alone application, is this right?
    Well, they work as separate windows in a Chrome browser. You can also run Chrome in "application mode" where it runs your Chrome app in a window on the desktop.

    Chrome apps do not work in any other browser.
  • RaymanRayman Posts: 14,641
    edited 2014-03-31 16:39
    Ok, if it runs inside the Chrome browser, that sounds good. I don't think too many people would have a problem installing Chrome, even on a PC.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2014-03-31 17:22
    I use Chrome always, but having it be a requirement means not working on iOS (iPad) which is likely a desirable thing for education if not a requirement. So, we'll want a solution for other than Chrome as well...

    Chrome does cover Windows, Linux, Mac, and Android (although I doubt the same serial solution works on android as others).
  • rosco_pcrosco_pc Posts: 464
    edited 2014-03-31 20:24
    dgately wrote: »
    Ray, you might want to make a copy of the python generator as the syntax should look a lot more like spin, no?


    dgately

    And have a look at BlocklyDuino. They've added some nice blocks that will be useful on the propeller as well
Sign In or Register to comment.