Running MicroBlocks on an 01_SPACE_C3_RGB (ESP32-C3FH4-RGB)

Back in the day, I got this board (found via Andy Piper’s repo working with the Arduino IDE

but, of course, I really wanted to program it using MicroBlocks 🙂

https://microblocks.fun

Unfortunately, the board wasn’t supported but recently I made a last-minute trip to FOSDEM 2024 where I met up with the MicroBlocks team and this spurred me on to giving this project a proper go

A MicroBlocks discord forum has been setup

https://discord.com/channels/1000653853491998760/1000653853491998762

and I used it to ask questions on how to make a custom MicroBlocks VM (Virtual Machine) to run on the board.

Compiling Virtual Machine for the ESP32-C3

So, I installed PlatformIO (just the command line version to keep things as simple as possible) and forked the MicroBlocks repository

https://bitbucket.org/john_maloney/smallvm/src/dev/

and downloaded it and created my own branch (based on dev branch) to play around with

There was an existing ESP32C3 board defined in the projects platformio.ini file

...

[env:esp32-c3]
platform = espressif32
board = esp32-c3-devkitc-02
board_build.partitions = no_ota.csv
build_flags = -D BLE_IDE
lib_deps =
paulstoffregen/OneWire
WebSockets
256dpi/MQTT
NimBLE-Arduino

but after building that and uploading it to the board by running

pio run -e esp32-c3 -t upload

it just locked up the MicroBlocks GUI IDE 🙁

But after discussions and help on the forum, changing it to

[env:esp32-c3]
platform = espressif32
board = lolin_c3_mini
board_build.partitions = no_ota.csv
;build_flags = -D BLE_IDE
lib_deps =
paulstoffregen/OneWire
WebSockets
256dpi/MQTT
NimBLE-Arduino

(i.e changing board definition to lolin c3 mini and disabling Bluetooth)

got it so it didn’t lock up and I could write a program using it 🙂

I then noticed that the WiFi wouldn’t work but another trip to the forum yielded a hint to reduce a memory size in the mem.c file

...
#elif defined(ESP32_S3) || defined(ESP32_C3)
#define OBJSTORE_BYTES 50000 // SimonW: was previously set to 800000
...

and voila – I had WiFi working on it 🙂

So, I finally got it displaying the current cheerlights colour using this script.

Note: This uses my own LAN MQTT broker but I echo the same data to a lot of public brokers so if you want to copy this – just checkout the cheerlights/# (or cymplecy/cheerlights/#) topics on them

And here is a video of it in action

Uploading the VM without having to compile it

If you have one of these boards and don’t want to goto the trouble of compiling it yourself you can do the following

Run MicroBlocks

Unplug your board, press Boot button and connect the USB, and then press Reset and release Reset, lastly release Boot

Select Upload from URL option from the settings cog and right-click and paste in

https://microblocks.fun/mbtest/tmp3/simon_firmware.bin

and select OK

The VM should download and then install onto your board – wait until it is finished and then press and release the Reset button once more

You should now having a working system

Upload the VM using esptool

If the Upload via URL doesn’t work for you and you don’t want to go to the effort of getting PlatformIO working on your system, here is the current version of this VM firmware https://github.com/cymplecy/fivebyfive/raw/microblocks/microblocks/firmware.bin that I have already compiled

To install this firmware, the board needs to have previously had an Arduino sketch uploaded to it (any sketch will do – choose the board type as LOLIN C3 MINI) to set up other software partitions on the board

Then install esptool:

https://docs.espressif.com/projects/esptool/en/latest/esp32

and in a terminal run

esptool.py --port /dev/ttyACM0 write_flash 0x10000 firmware.bin

(change your port to match the one used when you uploaded your Arduino sketch)

Leave a Reply

Your email address will not be published. Required fields are marked *