[Microbit-Python] Blockly to MicroPython - is it possible?

Andrew Ferguson andrewferguson500 at gmail.com
Sun Mar 13 10:16:38 EDT 2016


So based on Carlos' earlier idea for a converter from Blockly to Python, I
thought I'd have a go at doing this, just to see if it was possible. I've
done something similar before (Scratch 2.0 to C / Pawn for the Pleo
Dinosaur robot - side note, do any schools apart from mine have these?).
That was fairly easy*: Scratch 2 uses JSON in a intuitive way.

Blockly is proving to be a lot less intuitive. See the following snippet
from a simple example from the website:

<xml xmlns="http://www.w3.org/1999/xhtml">
    <block type="device_button_event" x="69" y="38">
        <field name="NAME">A</field>
        <statement name="HANDLER">
            <block type="variables_set">
                <field name="VAR">answer</field>
                <value name="VALUE">
                    <block type="device_random">
                        <field name="limit">3</field>
                    </block>
                </value>
                <next>
                    <block type="controls_if">
                        <mutation elseif="1" else="1"></mutation>
                        <value name="IF0">


At first I assumed that each 'block' was contained in a 'block' tag, with
one tag for each block. That appears to be the case sometimes, but not
always. Observe how the "device_random" block is self contained but the
"variables_set" block continues down into the "controls_if" block!

In addition, Blockly supports concurrently running scripts, while I suspect
MicroPython does not (or does it - would be fantastic if it does!). If my
suspicion is correct, this would mean that a script in Blockly that has a
group of blocks in a "forever" loop and another group of blocks in a "when
button pressed" block, would not be possible to convert to MicroPython. Any
way round this?

Oh, and the Blockly editor seems to have stopped working in Chromium (at
least it has on my computer with very outdated version - but it worked
yesterday). Clicking "Compile" makes the logo rotate forever (I waited 55
minutes) and nothing else happens. Has there been a recent update?
(Chromium has no Java / Flash support, so that could be the cause).

Looking forward to trying out some stuff on a real MicroBit when it arrives!

Andrew


*Fairly easy until I realised their development tools were all closed under
an NDA, so I had to rewrite and reverse engineer a *lot* to get the basics
working.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/microbit/attachments/20160313/bd7d415b/attachment.html>


More information about the Microbit mailing list