News: 1696416307

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Kaluma squeezes JavaScript onto the Raspberry Pi Pico

(2023/10/04)


Although JavaScript is responsible for some bloated Electron apps, apparently you can still usefully run it in 264kB of RAM.

The [1]Kaluma project has managed to embed a working JavaScript interpreter into the Raspberry Pi Pico, and other devices using the same CPU. The Pi Pico ships with 264kB of RAM and just 2MB of flash storage, but into that, Kaluma has managed to squeeze the ECMAscript 5.1-compliant [2]JerryScript runtime, complete with support for Node.js and the npm package manager.

The [3]new Raspberry Pi 5 – which, we can exclusively reveal today, does not cope well with having cola spilled over it so readers may not see a long-term test of the device – has hogged the headlines recently. In some small part, this is because of its in-house designed southbridge chip, confusingly named the [4]RP1 . The Pi 5 wasn't the first Pi model with an in-house chip on board, though. The [5]$4 Raspberry Pi Pico uses the company's home-made RP2040 processor, available for [6]70¢ in volume .

[7]

Despite its tiny specs, the Pi Pico has done rather well, partly because it didn't suffer too badly from the silicon chip shortages that caused problems for many other devices, including the bigger Pis, since the pandemic began. The Pico is a very limited device, which doesn't even have a built-in display output. The hacker community has taken this as a challenge, and come up with some impressive tech from the tiny device. The Reg FOSS Desk's personal favorite is turning Picos into [8]plug-compatible Transputer replacements .

[9]

[10]

It's easy to assume that to work with such a constrained device, you must use a low-level or constrained language. Out of the box, the Pi Pico supports C (arguably [11]not a low-level language any more ), and MicroPython, as [12]also used in the BBC Micro:Bit – which is about four times the price.

[13]Raspberry Pi 5 revealed, and it should satisfy your need for speed

[14]Tinker Tailor Soldier Pi? Asus's 'NUC-sized' SBC aims to out-Pi the Raspberry

[15]Raspberry Pi production rate rising to a million a month

[16]LattePanda's Sigma crams a 12-core Intel Raptor Lake CPU into an itty-bitty SBC

Kaluma's offering, though, seems remarkably capable. The company has a [17]showcase of projects built with it, a library of [18]code packages , [19]documentation , and a [20]forum on GitHub. It uses JerryScript, which is [21]also open source and well [22]documented – for an example, see its [23]API reference .

Although some terrible things have been done with it, we can't help but recall how Smalltalk and Croquet boffin David A Smith [24]told us :

JavaScript is an extraordinarily good, […] powerful language. Most people don't understand that: they think it's a toy language, but in fact, it's probably one of the best languages out there. The other thing is, it's had billions of dollars of investment to make it very, very, very fast and very efficient, and it runs everywhere.

Kaluma is the proof that this extends even further than you might think. And of course JavaScript also enjoys a wealth of support, documentation, and a large and active community. A Javascript-enabled $4 computer sounds excellent and highly encouraging for beginners at hardware development. ®

Get our [25]Tech Resources



[1] https://kalumajs.org/

[2] https://jerryscript.net/

[3] https://www.theregister.com/2023/09/28/raspberry_pi_5_revealed/

[4] https://community.element14.com/products/raspberry-pi/f/forum/53762/the-raspberry-pi-5-has-a-new-chip---the-rp1-has-a-secret

[5] https://www.theregister.com/2021/01/21/pi_pico/

[6] https://www.theregister.com/2022/01/17/raspberries_pi_direct_launch/

[7] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_offbeat/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2ZR2MJHFaZYedwohOt0hXuwAAAAE&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[8] https://www.theregister.com/2022/05/06/pi_pico_transputer_code/

[9] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_offbeat/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44ZR2MJHFaZYedwohOt0hXuwAAAAE&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[10] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_offbeat/front&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33ZR2MJHFaZYedwohOt0hXuwAAAAE&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[11] https://www.theregister.com/2022/03/23/c_not_a_language/

[12] https://www.theregister.com/2016/03/22/bbc_microbit_kids_computer_first_look/

[13] https://www.theregister.com/2023/09/28/raspberry_pi_5_revealed/

[14] https://www.theregister.com/2023/08/11/asus_nuc_tinker_3n/

[15] https://www.theregister.com/2023/06/05/raspberry_pi_shipments_rise/

[16] https://www.theregister.com/2023/04/28/lattepanda_sigma_sbc/

[17] https://kalumajs.org/showcase/

[18] https://kalumajs.org/packages/

[19] https://kalumajs.org/docs

[20] https://github.com/kaluma-project/kaluma/discussions

[21] https://github.com/jerryscript-project/jerryscript

[22] https://jerryscript.net/getting-started/

[23] https://jerryscript.net/api-reference/

[24] https://www.theregister.com/2023/03/23/croquet_for_unity/

[25] https://whitepapers.theregister.com/



Hmm.

Missing Semicolon

"JavaScript is an extraordinarily good language." - from the linked article.

It's certainly powerful, but powerful in the way a sack full of sharp powertools with the safety guards taken off is powerful. You can do a lot of things, but you are going to lose a finger or two in the process.

Utterly dynamic languages are great for geniuses who can hold the entire context of a codebase in their heads at once. Such demi-gods have no use for typing, or static inspection, or sane, predictable scope rules. Remember that the default scope for variables is global. Don't forget them 'var' declarators!

For the rest of us, anything really large is going to turn in to an unmaintainable [1]ball of mud way too fast, and exhibit unexpected bugs unless you can achieve 100% coverage auto-test cases.

[1] http://www.laputan.org/mud/mud.html#BigBallOfMud

Size

Caver_Dave

Wow, the standard must have changed somewhat.

At the end of last century I was a programmer for an Internet set-top-box manufacturer.

25Mhz Intel processor, 64M of RAM (half of which was the screen memory and couldn't be accessed by the processor for half the time while updating the screen). It had a fully compatible browser including a JavaScript interpreter (which I wrote) and an area for cookies, passwords, history, etc.

At least this is a story against the bloatware that is more common place.

Re: Size

Liam Proven

[Author here]

> 64M of RAM

You _did_ notice that the Pi Pico has, as I said, 264 *kilobytes* of RAM, not megabytes, right?

The last new computer I can think of offhand with so little RAM was the Amstrad PCW 8256 in 1985.

The Pi Pico has 3% more.

That's very nearly FORTY YEARS AGO, and good luck running Javascript on a PCW.

lostinspace

Using Javascript as a beginner language is fine for a while. All the curly brace languages are basically the same at a superficial level. The problem with Javascript is it's inheritance model is like no other common language. Most widely used languages have a concept of a class and an instance of that class. Javascript has a crazy prototype model, which is far more complex and hard to understand.

Python is a far better choice for a beginner.

Anonymous Coward

You're correct of course, but if you use strict mode, always use "let" instead of "var", if you use class { ... } and private member variables/functions, it looks a lot like Java. You don't have to indulge in the worst aspects of the language.There's still lots wrong - I think promises were botched, personally, the component library model (or models) are ridiculous, especially as ES6 modules still don't work brilliantly on the web. But I digress.

Re. python, any language that attaches semantics to something you can't see has an uphill battle with me, but I know it's popular so each to their own.

"JavaScript also enjoys a wealth of support, documentation"

Dan 55

Usually the more documentation you have the better, but [1]that's not true in JavaScript's case .

[1] https://devhumor.com/media/javascript-the-good-parts

Johannesburgel12

> The other thing is, it's had billions of dollars of investment to make it very, very, very fast and very efficient, and it runs everywhere.

Billions of dollars have been invested to make specific runtimes fast. JerryScript is not one of them. It's a pure interpreter without any JIT or anything, so this is among the slowest ways to execute JavaScript at all. And I'm not even talking about design decisions that are particularly stupid on microcontrollers, like the lack of integer datatypes.

Liam Proven

[Author here]

> It's a pure interpreter without any JIT or anything

Do you think they could fit a JIT into 264kB of RAM?

I can't think of many modern OSes that would fit into a quarter of a megabyte.

Even RISC OS Pico, the very cut-down RISC OS, was meant for a full-size RasPi.

https://www.riscosopen.org/wiki/documentation/show/Software%20information:%20RaspberryPi:%20RISC%20OS%20Pico%20RC5

However, note how fast BBC BASIC V was compared to Python:

https://weblambdazero.blogspot.com/2015/11/modern-micro-with-risc-os-pico.html

A "pure interpreter" does not necessarily mean slow.

I loved her with a love thirsty and desperate. I felt that we two might commit
some act so atrocious that the world, seeing us, would find it irresistible.
-- Gene Wolfe, "The Shadow of the Torturer"