MicroBlocks on Beagleconnect Freedom

Hello everyone. I have been recently working on porting MicroBlocks to Beagleconnect Freedom. This also involved work improving Arduino module for Zephyr since MicroBlocks uses Arduino APIs. I will go over using MicroBlocks on beagleconnect freedom.

What is MicroBlocks?

MicroBlocks is a free, Scratch-like blocks programming language for learning physical computing with educational microcontroller boards. It allows complete beginners to get started quickly, from children as young as nine years old up through adults of all ages.

However, MicroBlocks isn’t just for beginners. It can be used to learn electronics, instrument science experiments, automate your home, and much more.

Technical Details

Let us first review the technical details of how all of this works. Beagleconnect Freedom already has Zephyr support. However, MicroBlocks uses Arduino APIs, and migrating everything to Zephyr APIs would take a lot of work. Additionally, the final goal is to have everything merged upstream, and thus, it is better to have as little maintenance burden as possible.

I am using Arduino Core API module for Zephyr, which implements Arduino APIs on top of Zephyr. Adding support for Beagleconnect Freedom was pretty painless since all it amounts to is a device tree overlay (board porting instructions). I had to add some missing APIs, but the process was pretty painless. Some missing APIs have already been merged, while others have active PRs.

Prebuilt Images

The latest MicroBlocks images for BeagleConnect Freedom are available here. This demo was made using zephyr-microblocks-rc1 image.

  1. Download MicroBlocks Image
cd ~
wget https://files.beagle.cc/file/beagleboard-public-2021/images/zephyr-microblocks-rc1.zip
  1. Extract Image
unzip -j zephyr-microblocks-rc1.zip

Skip to the flashing instructions to flash the image to Beagleconnect Freedom.

Building MicroBlocks Firmware

The latest MicroBlocks images for Beagleconnect Freedom are available in the CI. I will now go over building the images locally for those interested.

Install dependencies

Install dependencies present in Getting Started with Zephyr.

Setup Zephyr Sdk

Setup Zephyr Sdk by following instructions in Getting Started with Zephyr.

Build MicroBlocks Image

  1. Clone smallvm fork.
git clone https://openbeagle.org/ayush1325/smallvm.git -b zephyr ~/smallvm
cd ~/smallvm/zephyr
  1. Build MicroBlocks Image for Beagleconnect Freedom.
make beagleconnect_freedom
cp ~/smallvm/zephyr/build/beagleconnect_freedom/zephyr/zephyr.bin ~/zephyr.bin

Flash Image

  1. Install cc1352-flasher.
pip install cc1352-flasher
  1. Find Beagleconnect Freedom Port. It is /dev/ttyACM* on Linux. It can be checked using the following command:
 udevadm info /dev/ttyACM0 | grep "BeagleConnect"
E: ID_MODEL=BeagleConnect
  1. Flash Image.
cc1352_flasher --bcf ~/zephyr.bin -p '/dev/ttyACM0'

Run MicroBlocks ide

  1. Download MicroBlocks standalone ide. The browser version of ide does not support manually selecting ports.

  2. MicroBlocks ide should automatically detect Beagleconnect Freedom. It might take upto a minute.

It is also possible to manually select beagleconnect freedom tty by enabling settings->show advanced blocks in case you have lot of usb devices connected.

Demo

Just running blink example on beagleconnect freedom

Future

The PRs for all the required changes are already open for Arduino module for Zephyr and Zephyr. I will also try to get support merged to upstream MicroBlocks which should allow much easier porting of MicroBlocks to Zephyr supported boards in the future.

I will also be writing more posts regarding Arduino API support for beagleconnect freedom, which is already in a pretty good state.

Conclusion

There are still a lot of bugs, so feel free to open issues. I will also write more articles regarding Arduino API support for Beagleconnect Freedom.

Consider supporting me if you like my work.

Helpful Links