JavaScript on Microcontrollers

A presentation at FOSDEM in February 2020 in Brussels, Belgium by Niels Leenheer

Slide 1

Slide 1

JavaScript on Microcontrollers

Slide 2

Slide 2

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.

Slide 3

Slide 3

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

Slide 4

Slide 4

I tweet at @html5test

Slide 5

Slide 5

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

Slide 6

Slide 6

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

Slide 7

Slide 7

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.

Slide 8

Slide 8

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.

Slide 9

Slide 9

This is all fine and well, but…..

Slide 10

Slide 10

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.

Slide 11

Slide 11

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.

Slide 12

Slide 12

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.

Slide 13

Slide 13

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

Slide 14

Slide 14

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

Slide 15

Slide 15

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.

Slide 16

Slide 16

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.

Slide 17

Slide 17

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.

Slide 18

Slide 18

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.

Slide 19

Slide 19

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.

Slide 20

Slide 20

Time for the demo’s. I hope…

Slide 21

Slide 21

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.

Slide 22

Slide 22

#1 Connected lightbulb

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

Slide 26

Slide 26

Slide 27

Slide 27

Slide 28

Slide 28

Slide 29

Slide 29

#2 Remote controlled car

Slide 30

Slide 30

Slide 31

Slide 31

Slide 32

Slide 32

Slide 33

Slide 33

Slide 34

Slide 34

Slide 35

Slide 35

Slide 36

Slide 36

Lasers!

Slide 37

Slide 37

Lasers!

Slide 38

Slide 38

Lasers!

Slide 39

Slide 39

Slide 40

Slide 40

Slide 41

Slide 41