JavaScript on Microcontrollers

Hi, I’m Niels. And today we’re going to talk about JavaScript on Microcontrollers. Usually this talk is about 45 minutes and we have just 25 minutes. So either I have to talk really really fast. Or cut out some stuff. So I’ve remove all the jokes and funny things. And we’re left with the boring stuff. But don’t worry. This is meat of the talk. The good stuff. I promise.

Anyway, I am a Mozilla Tech Speaker, Google Developer Expert.

I tweet at @html5test

And I love electronics. When I was a teenager I had this cardboard electronics set with all kinds of different components…

And you could connect them together with clipping wires between some springs. You could build a radio or even a transmit morse code.

And this is what I have now. Still some components to connect together with some wires. But the components have become much more advanced. Instead of transistors and diodes and resistors, we now play with microcontrollers and all kinds of sensors. And everything works together.

But I am a web developer by trade. I program in JavaScript. So what if we could JavaScript on Microcontrollers? And not only that, what if we could leverage the browser to connect to these microcontrollers and let them extend each others capabilities.

This is all fine and well, but…..

Microcontrollers are slow. They are really slow. And when I say slow, that really does not convey the idea how slow they actually are. They are slooooooooow. Take for example the slowest computer you can buy today. The Raspberry Pi.

This is the Zero W, which is slow. But it still is a great little computer. It runs Linux, can use Node.js and even run a full browser like Chrome or Firefox. But this is a computer. It is not a microcontroller.

This is a microbit. It is a little board created for schoolchildren. And it runs at just 16 MHz and has only 16 KB of RAM. It is slow. But it is not even by far the slowest microcontroller you can find. But it is fast enough to run JavaScript.

To put it in to context. The Raspberry Pi is 60 times faster than a Microbit.

And it has way more memory. So the microbit is on a completely different level. But running JavaScript on microcontrollers is actually really briliant.

Microcontrollers are very power efficient. I can run JavaScript on a tiny little Bluetooth enabled board and power it using a coin cell battery. And it can run for months. Slow is a good thing, because when we make things faster, they usually require more power.

And microcontrollers are fast enough. Yes they are slow, but we only have to solve very small problems. Microcontrollers are fast enough for everything I am going to show today. You can’t run React on it though. But yeah. I would not run React anywhere anyway.

So let’s take a look at how we can get JavaScript on our microcontrollers. There is actually an open source project that allows us do do this.

Espruino - created by Gordon Williams. You can also buy hardware with Espruino already installed. Gordon is here with a stand in the AW building, so check it out. But there are also has versions that you can flash yourself on your own hardware, like on a ESP32 or ESP8266.

And it is an interpreter that supports most of JavaScript, even some ES6 features like arrow functions and so. And it even have REPL functionality. So connect to your computer using a USB cable or using Bluetooth and you can execute commands on the microcontroller just like you would in the console of a browser.

Time for the demo’s. I hope…

But I do have some warnings to give. This is cutting-edge stuff. Hardware demo’s with experimental technology. And most of it using Bluetooth, a wireless connection…. And Bluetooth uses the same frequency as WiFi, so with a room full of WiFi devices there is lots of opportunity for interference. So this is moment I get nervous.

#1 Connected lightbulb

#2 Remote controlled car

Lasers!

Lasers!

Lasers!