Coming soon: MicroBlocks 3.0 pilot (using morphic!)

Coming Soon: MicroBlocks 3.0 Pilot Release

For the past six months, the MicroBlocks team has been working on a major rewrite of the MicroBlocks editor – and it is almost ready to be released as a pilot release! For a sneak peek, open the URL below.

https://microblocks.fun/run-pilot/purejs.html

MicroBlocks 3.0 (details)

We’re still putting the finishing touches on MicroBlocks 3.0 so the alpha version still has a few rough edges. But you’ll immediately notice how much faster it is than the current pilot release. The increased speed is one of the biggest benefits of the rewrite. The new version also includes improvements we’ve wanted to make for some time such as:

  1. Automatic backup to the browser’s local storage as you work so if anything goes wrong – or you accidentally close the MicroBlocks tab – you can recover your work.

  2. MicroBlocks now offers to install MicroBlocks if the board doesn’t respond, a boon to folks with brand-new boards, or boards that have an Arduino, MicroPython, or Makecode project installed.

  3. ESP32 firmware installs continue even when you switch to another tab.

Those are only a few of the improvements we’ve already made, and there are more in the works.

What do you mean, “major rewrite”?

When MicroBlocks started in 2017, it was built on a language called GP Blocks, which had its own libraries and graphics system. Initially, MicroBlocks was a stand-alone application that had to be downloaded and installed because browsers did yet support WebUSB or WebBluetooth. When those features were added to the Chromium browser, MicroBlocks was ported to operate in the browser as a web application. To enable that, the GP system was compiled using the Emscripten C++ compiler.

However, GP Blocks was becoming difficult to maintain. There were four variations: stand-alone apps for Windows, MacOS, and Linux as well as the web app. In addition, GP Blocks is, frankly, a poorly documented, non-mainstream language, so it was difficult for anyone outside of the immediate team to contribute to the MicroBlocks code. Furthermore, GP is much slower than native Javascript so things became sluggish when working with large numbers of scripts.

This past summer, we began the transition away from GP Blocks by migrating the UI to Javascript and CSS. That was MicroBlocks 2.5, released in July. However, the blocks editor and all of the core functionality (the “engine”) were still implemented in GP.

The upcoming MicroBlocks 3.0 release will complete the migration. Everything will be implemented in Javascript and CSS, with a fond farewell to GP Blocks. The new MicroBlocks blocks engine is built on the mature blocks and morphic systems from Snap! – with heartfelt thanks to @jens for his amazing work.

From the user standpoint, MicroBlocks 3.0 will look and feel the same as MicroBlocks 2.5, only much, much faster. All the libraries and example projects are the same as before and the blocks will look the same. No changes will be needed to existing projects, libraries, or learning materials.

I want to acknowledge Sam McHardy for his huge contributions to this transition. I did not think we’d be finished with the transition until next summer. Then Sam jumped in and things started to move quickly. Sam has contributed hundreds of pull requests and run extensive tests comparing the pure Javascript system to the GP system to make sure the new system is 100% backwards compatible and that no bugs have crept in. (In fact, Sam also found and fixed a number of bugs in the GP system.)

Thank you, Sam!

Was just testing it out (wel, without no microblocks thing) and I was wondering; will you expose the Morphic dev mode like the shift-click feature on the Snap! logo?

No, as far as I know that won’t be exposed but @bromagosa could tell more about that. MicroBlocks is no Snap! mod, we use parts of the morphic system, like the blocks system.

i have a micro:bit, does the site automaticially give the hex for the microblocks app on the board when you run? or is there somewhere else it can be installed?
and a way to emu/simulate a board would be cool, the micro:bit site does that though all the programs must be compiled before sending to the board. i suppose microblocks would send the commands to the board lively-programming-style while it runs? if thats the case, there should be a way to compile if never mind, havent checked the settings - “boardie” is a virtual board, but i dont see a way to compile the project. i suppose you’d have to keep the site open when you want the program to run, i guess? not too convenient.

Cool!

This error occurred when I pushed “reset” on the boardie.

Thank you, I shared it with the developers. What browser are you using?

EDIT: I got the same error on Chrome as you have. FF gives also gives an error somewhat different from yours.

MicroBlocks is a live programming language. The main developer is John Maloney who worked on Scratch the first eleven years. You put a virtual machine on your microbit. Everytime you change something in the code it is on the microcontroller.

You don’t compile, you work live on the microcontroller of installing the vm and connecting to it. You can use the same code on a microbit, esp32, raspberry pi pico, etc, etc,

No, you don’t. The program is on the microcontroller. If you disconnect your USB or BLE connection, the board works standalone.

MicroBlocks and Snap! together are a powerhouse. There is a microblocks library in Snap!.

Here is a topic with small tutorials to try.

So the block program from the MicroBlocks app is actively stored on the board, is what you’re saying? Cool. What I meant with “the hex of the program” is where you install the VM to the micro:bit. I’d assume that’d be available on the site.

Press the gear icon and click “update firmware on board” then choose microbit in your case.

You could also drag and drop the hex from your file explorer.

Below a list for all the boards supported. Not every board accepts dragging and dropping.

The byte code is stored on the board. It can also be read back from the board if you would loose your project on your laptop.

In the past MicroBlocks only worked on Chrome and Edge because of the USB and BLE connecting. A while back FireFox finally made a WebSerial connection available.

Using a BLE connection means your microbit can be connected with MicroBlocks while programming. No need for a USB cable anymore.

Here is a blogpost about the difference between Scratch, MakeCode and MicroBlocks. It was made by a company we work with.

Remember every board that works with MicroBlocks and has a BLE or Wifi option can be controlled by Snap!

Already fixed:

On microblocks.fun, pressing Boardie’s RESET button in the pure JS IDE shows the uncaught-error dialog: “SecurityError: Failed to read a named property ‘document’ from ‘Window’: Blocked a frame with origin https://microblocks.fun from accessing a cross-origin frame” (Firefox says “Permission denied to access property document on cross-origin object”). Peter reported it in Chrome and Firefox.

On microblocks.fun Boardie runs from boardie.microblocks.fun, a different origin, and GP.boardie.reset reads the iframe’s document to paint the canvas black. The browser blocks that read, so it throws. The VM already clears Boardie’s screen whenever it resets, so the paint isn’t needed. This drops it.

The same function then sends start all with chunk index 0, and the VM has ignored a start all whose index isn’t 1 since the 16-bit/32-bit change in October 2024, so RESET hasn’t restarted the scripts on any host since then. The second commit sends 1, as the IDE’s own start all does, so RESET starts the “when started” scripts again as it was meant to.

To reproduce: open MicroBlocks , choose open Boardie from the connection menu, and press the round RESET button on the panel. The error dialog comes up. For the restart, run any project with a “when started” script that says a counter, press RESET, and the counter doesn’t come back. With this branch there’s no dialog, the screen goes black and the counter starts over from 1, both on microblocks.fun and when Boardie is on the same origin.

It affects only the RESET button. GP’s gpSupport.js has the same reset, so the GP web IDE on microblocks.fun throws too, just without a dialog. I’ve left gpSupport.js alone and only changed the port.

The new version has still to be deployed.

@petermathijssen I thought that Firefox didn’t support WebUSB?

My mistake. Firefox has supported WebSerial since v151 but it doesn’t support the more capable WebUSB API. I changed my post.

Sorry, I was rather confused when you mentioned WebUSB support. ;-)

No problem, it looks like the Firefox team is still strongly against supporting WebUSB, which they argue is a security risk.

For MicroBlocks it was a huge step that Firefox finally supported at least WebSerial. Last February when the team was in Brussels at FOSDEM we were still kind of complaining among ourselves and finally in May it was there. :grinning_face: