Porting SAM to Makecode – part 2

Environment setup and first build

It quickly became obvious that the web-based Makecode editor was too slow and restrictive to make any real progress.

Native development is possible via the PXT command line. However the instructions are full of pitfalls https://makecode.com/cli

Firstly dependencies

For a Ubuntu 22.04

sudo apt-get install \

  ninja-build \

   srecord \

   yotta \
   git \
   npm \


sudo npm install -g pxt

Next you need to initialise pxt

The instructions say

pxt target microbit

This sort of works, however it defaults pxt-microbit to 4.0.24. Which would be okay, however this is non-functional because the yotta registry it depends on has been removed back in 2021 (https://support.microbit.org/support/solutions/articles/19000123284-arm-yotta-registry-deprecation)

So I’ve found the following to work, 5.1.2 being the latest at time of writing.

npm install pxt-microbit@5.1.2

pxt target microbit

pxt install

Almost there, but build requires a default python, however recent distributions dropped that in favour of python2 or python3 explicitly

Could do with a simple symlink, but lets do it using update-alternatives.

sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3 1

Now onto building

A default pxt build will try and use the cloud compilation, which should work but takes several minutes

The official instructions say pxt buildlocal but this was removed, the new command is

pxt build --local

OK, so this tries to build with Docker, but the build fails because of the previously mentioned changes to yotta registry.

So how about


Almost… but build now fails with null pointer exception. Turns out you need to set a github token

export YOTTA_GITHUB_AUTHTOKEN=github_pat_<your token>

Putting it altogether

# one off setup
npm install pxt-microbit@5.1.2

pxt target microbit

pxt install

# build
export YOTTA_GITHUB_AUTHTOKEN=github_pat_<your token>
pxt build --local

It takes a while… and pulls down a staggering 27k files and 1.1GB but job done… we have a binary.hex

Copy the ./built/binary.hex to your device.