One of the fun things about “old school” computers is that it was fairly easy to get kids into programming them. The old Basic interpreters were pretty forgiving, and you could do some clever things easily with very little theory or setup. These days, you are more likely to sneak kids into programming via Scratch — a system for setting up programs via blocks in a GUI. Again, you can get simple results simply. With Scratch or Basic, complex things have a way of turning out complex, but that’s to be expected. If you want to try a Scratch-inspired take on microcontroller programming, check out MicroBlocks. It will work with several common boards, including the micro:bit and the Raspberry Pi Pico. You can use it in a browser or download versions for Linux, Windows, Mac, or even Chromebooks.
You can see a video below about the micro:bit version from a year ago. The tool is advancing, so you’ll find many new features compared to the video, but it will still give you an idea of what’s happening.
We were impressed with the range of blocks and libraries including like I2C, SPI, and NeoPixel. You can graph data easily. We were unable, sadly, to make the browser version work with an ESP32 S3 module we had sitting on the desk. The tutorials have videos and snippets of graphical “code” you can drag directly into the IDE.
We aren’t sure if it was a configuration issue or if the S3 isn’t supported. Or it could have been simple operator error. The web page says it can be “tricky” to get the initial firmware on the ESP32, and — for us — it was apparently too tricky. We even grabbed some firmware images from GitHub and flashed them. We also tried building the smallvm component from scratch, but getting it to build for the S3 took some modifications and uncovered some typos in the code base. It did work in the end and it worked as advertised for a “stock” ESP32 development board.
We get it. You don’t want to shower kids with cryptic error messages. However, there didn’t seem to be many options for troubleshooting or for a teacher or coach to just flash the image in some regular way. There was a GUI — we think — to flash the base firmware on GitHub but with little documentation.
But if you have a supported board, it looks great. We know that block programming isn’t the language of choice for most Hackaday readers. But if you are looking for a gateway drug for a friend or a child, this could well be it.
You shouldn’t write kernel modules in Scratch, either, but people have. If you’d rather stick with Python, you can do that, too.
18 thoughts on “Scratch Your Itch To Program A Microcontroller”
Scratch has some Arduino extensions to begin with.
And mblock.cc which is clone of Scratch in addition to their robots support, has a ton of microcontroller extensions.
What about an artist who needs a specific microcontroller function that is simple but just works? Or someone who wants to use an AI based microcontroller for their specific use but does not even program at all? Or even just an adult who is new to programming? Or a visual learner? Or someone that does program but wants to create a fairly simple overall program quicker than they could physically type it all out by just dragging a few things around instead of writing code to get something at least testable?
Would be nice if it could also build in some error checking at least which this seems to lack at the moment.
Anyway, every time you see one of these apps or programs posted here, it seems like there are always assumptions made about how the target audience is always a minor who has never programmed before or is still learning.
Not everyone who is good with things like hardware is also good at software programming and not everyone who is an adult, let alone a programmer knows how to program multiple higher level languages.
I studied electrical engineering, so I greatly appreciate getting things done without getting stuck in the software. MicroBlocks is my fave microcontroller tool (I volunteer to teach it as well). If a board isn’t supported by MicroBlocks then I wouldn’t want it. ;)
It’s a dream come true for Makers of any age who just want to build and create things or instrument the world with sensors to understand things better. I used MicroBlocks to build a “smart Christmas tree” for my granddaughter and she loved to push buttons to change ornament LED colors and patterns.
There’s even “boardie” available now if you don’t have real hardware, to get a taste. But we do recommend using real hardware. Just try it. :)
AI at this stage can only write very basic code for a few select microcontrollers. From what I have seen it can’t handle much that you wouldn’t find a tutorial for and even then it can have mistakes.
It really doesn’t take much to learn enough Arduino to write the type of programs you are on about and current AIs can’t really write complex code for microcontrollers. So anything complex, like art projects tend to get, with loads of motors or leds, aren’t well suited to be written by an AI. Current AI also doesn’t seem to be much good at writing code to use things that aren’t built into the microcontroller like sensors or other peripherals.
Just using an AI to write code also doesn’t really teach you anything, creating it using a blocky language like scratch or even something like node-red is better since you actually have to think about what you are doing and learn something. AI at this stage will not replace programmers, if an artist has a complex program they need written they will still need to get someone else to write it.
Try CodeSkool https://ide.codeskool.cc, which is Scratch based web software, that supports not only robotics, but ESP32Camera for AI and ML.
> We know that block programming isn’t the language of choice for most Hackaday readers
Well, I was taught “structured programming” with blocks like Scratch uses drawn at the blackboard, back in the 90s at a community college.
We had if, while…do, do…while,for,switch case,input and output blocks. The only one missing was “evil” go-to
So I was very pleased surprised when I saw my kids using Scratch some years ago. Same blocky programming approach, however made easier for them
Taught by c/c++ ‘educated’ teachers?
Taught by good faith C/C++ teachers, that intended new programmers not falling in the bad habit of messy/hard to follow code.
Decades later I learnt by experience that a goto here or there (i.e. during error checking part of a function) may indeed help making precisely that goal:not messy code.
And I appreciate having such teachers at that time.
Great to see this article about MicroBlocks on Hackaday!
A distinguishing feature of MicroBlocks is liveness: the fact that blocks and scripts can be run immediately as you work, right on the microcontroller. You don’t need to compile and download your program to test it; just click on a block or script and it runs. Liveness helps beginners, especially young ones, get results right away and it helps them stay engaged as they work. Liveness also makes it easy for more experienced users to quickly build understanding about sensors and other devices.
Unlike some live systems — such as the Scratch extensions for microcontrollers — MicroBlocks programs execute right on the microcontroller. Once programmed, you can disconnect the microcontroller from the laptop, plug in a battery, and the program runs autonomously. That’s great for both fun things (e.g. light-up clothing and jewelry) and useful things (IoT applications). My seventeen-unit condo building’s heating system is controlled by an ESP32 programmed in MicroBlocks.
MicroBlocks has full support for a handful of boards used in K-12 education around the world, such as the micro:bit and Raspberry Pi Pico. The firmware for those boards can be installed directly from the MicroBlocks editor (webapp or downloaded app) without additional tools. However, for users willing to download the free PlatformIO command line tools, MicroBlocks can be installed on over 40 boards. (See https://bitbucket.org/john_maloney/smallvm/src/master/). Adding a new board starts by adding a fews lines to the platformio.ini file and running PlatformIO to compile and install.
MicroBlocks has not yet been tested on an ESP32-S3 but it has been tested by a community member on a Lolin S2 mini.
MicroBlocks includes libraries for the DFRobot HuskyLens and the Elecfreaks Smart AI Lens, products that combine a camera with a dedicated vision recognition system.
MicroBlocks is a non-profit with an educational mission. The software and associated educational materials are free and open-source. We hope you find it useful.
Yes I did get the S3 running although I wasn’t sure I did it right. And I don’t think I got all the reserved pins correct? But it wasn’t that hard to do, but probably harder than your target audience is willing to do lol
Great that you got MicroBlocks running on the S3. Congratulations on being the first person to port MicroBlocks to a RISC-V processor. :-)
Once you’ve got the basics working for a new board, a few tweaks to the source code (mostly in ioPrims.cpp) are needed to define the pin mapping, including the user LED, user buttons (if any), and any built-in features such as a speaker, NeoPixels, etc.
You’re right, porting MicroBlocks to a new board is not something we expect anyone in our target audience to do.
However, once support for a new board has been added to the code base, folks who are comfortable with the command line — including many Hackaday readers — can build and install the MicroBlocks virtual machine on over 30 “community supported” boards. Those boards are in addition to the ~10 fully supported boards on which precompiled firmware be installed directly from the MicroBlocks editor.
Although the primary target audience of MicroBlocks is younger learners and their teachers, we also have a smaller secondary audience of technical users who find MicroBlocks useful for rapid prototyping, exploring new sensors and other hardware, and general tinkering. Many of our community supported boards were contributed by folks in that group.
FYI, I’m the lead developer of MicroBlocks. I hope people find it useful and fun!
No software module >one page of code for compliance with Boeing hardware engineers’ software standards?
Each module SHALL
1 perform a simple intended function.
2 avoid performing any adverse or benign unintended functions.
2 provides adequate warning in event of failure.
Software engineering vs computer programming?
Next you are going to complain that Thomas the Tank Engine doesn’t meet FTA rail safety standards?
It’s for kids, learning the ABC of programming: if-then-else, loops, variables, etc. The English literature course comes later.
It’s good to see some Squeak still lives even if it might be living in the tunnels and burrows underneath a pleasant colorful world above ground.
It should be made clear to newcomers in the MCU world that, in order to code using C, a lot of the time there’s not one IDE that does all for you. You have to install and organize a series of tools. Then to find out out that this version is not compatible with the other version, that this tool has a certain incompatibility with the new version of the other but if you install the previous it is ok. That you have to be familiar with the usage of these tools. Then to realize that, if u want to use a display, you have to build the driver under the same path where a hundred parameters might have an issue. The “then” being days browsing forums.
Low-cost boards sometimes may contain high human-hour costs.
It is understandable why a lot not-young would prefer this simplistic tool which executes code in the board within minutes, having also a portable version.
Yes, count me in. I can create and explore way more with MicroBlocks (since it’s so portable to many boards) than I can with any other physical computing tool I’ve tried.
Nice to see MCU tools akin to Apple Swift Playgrounds and MIT App Inventor for mobile devices. Hopefully Scratch based tools provide developers the option to export of projects to more traditional development environments.
Actually I represent the type of user described by Alc in the comment above this one. Why fumble and bumble with the hoards of tools out there (except maybe PlatformIO that rocks!) when someone else will do that for you and deliver a playground of a hardware-abstracted and super-intuitive method to be creative? In this fast-growing space of physical computing (including most of IoT), you can participate whether young or old or in between. The need to “export” something from MicroBlocks back into the old cumbersome ways is not for me. If MicroBlocks wanted to attract industry prototypers or serious scientists instead of young learners, it could just change the “wallpaper” of the MicroBlocks IDE design and make it look like a metallic “low code” environment (i.e., user-friendly functions/libraries that are human-readable for first-timers). I’d actually love to see someone do that so we could begin to reduce the stigma that we should be going back to using less-friendly bare-metal tools. Yes, someone has to do the hard work of building a virtual machine for a new MCU/board in order for MicroBlocks to work, but fortunately, it doesn’t have to be me. I encourage both creative and super technical folks to try MicroBlocks!
Please be kind and respectful to help make the comments section excellent. (Comment Policy)