Kaluma JavaScript runtime for RP2040 review

By Ben Everard. Posted

Programming languages are strange things. In a very real sense, they’re all exactly equivalent – you can write equivalent programs in just about any modern language. However, at the same time, they’re entirely different. Learning a programming language – not just the basics, but really taking the time to become fluent in it – affects the way you program, and even the way you think.

Kaluma is a port of JavaScript to RP2040-based devices (currently Pico and Pico W are supported).

It might seem a little strange to port JavaScript to a microcontroller. After all, this is a language that started out as a way to add widgets to webpages, and superficially, that’s got little in common with blinking LEDs and reading temperature sensors.

JavaScript programs tend to rely heavily on events. Let’s take a look at the example of blinking an LED. Using C or MicroPython, you’d typically do this using a loop and a delay, but let’s take a look at how it’s done in Kaluma:

<b>var led = 25;
pinMode(led, OUTPUT);
setInterval(() => {  digitalToggle(led);
}, 1000);</b>

As you can see, the setInterval function creates a repeating timer that runs every second and calls another function (in this case, the second function isn’t named and just contains one line of code: digitalToggle(led).

You can do this in C, or you can do it this way in MicroPython. But for most C or MicroPython programmers, it wouldn’t be the natural way of doing it. Which is the better way of blinking an LED? Well, that’s a can of worms that we’re not going to open. However, there are two key advantages of having JavaScript on a microcontroller. Firstly, it enables programmers who are most familiar with JavaScript (and other similar) languages to feel at home using microcontrollers. Secondly, it enables people using microcontrollers to gain experience doing things the JavaScript way while still feeling at home. Both of those things are unequivocally a good thing.

Exploring Kaluma

This doesn’t really say much about Kaluma itself, though, just the idea behind it – so let’s dive in and see what it’s like.

There are two parts to Kaluma: the firmware that runs on the device (which you can download from kalumajs.org) and the software that interacts with it (which you can install via Node.js). Both installed without problems for us.

With so many things that we look at, documentation is the difference between an OK product and a great product. After all, it doesn’t matter how well something could work if you can’t work out how to use it. We’ve been really impressed with Kaluma so far. It’s obviously a small product, so don’t expect the sheer volume of documentation that you might find with larger ones. However, the API is clearly detailed at kalumajs.org/docs, and there’s an eight-part series to get you started at kalumajs.org/docs/tutorials. This goes through the basics of connecting to common hardware in great detail and explains the technical details behind them.

This series is probably more suited to people who know JavaScript and need some help with the physical computing side than electronic engineers who need help getting to grips with JavaScript.

The main downside of Kaluma is the main downside of every new programming language for a microcontroller – hardware support. By this, we don’t mean the hardware on the Pico (or Pico W) boards, but any additional hardware your project needs. At the moment, there’s out-of-the-box support for a relatively small amount of hardware. There’s not even support for the almost ubiquitous WS2812 LEDs. That isn’t to say that you can’t use this hardware with Kaluma; you just have to be willing to work at a low level. You can use I2C, SPI, and even RP2’s PIO blocks to communicate with most things, but this means working at a low level.

Overall, we found it easy to get started with Kaluma. The software worked and the documentation was easy to follow. It won’t be for everyone, but it’s a welcome addition to the Raspberry Pi Pico family.



Documentation and tutorials make it easy to get started with this version of JavaScript.


From HackSpace magazine store


Subscribe to our newsletter