First Look: Javascript Microcontrollers for Web Developers

Arduino Computers & Mobile Connected Home Raspberry Pi
First Look: Javascript Microcontrollers for Web Developers
The Tessel board (left) and the Espruino board (right)
The Tessel board (left) and the Espruino board (right)

The Espruino has shipped to its Kickstarter backers, and Tessel is on schedule to ship by May, and we’re about to get our hands on pre-production Tessel hardware and you can expect an in-depth review soon.

Despite the explosion of new boards coming to the market—and because of the community that’s grown up around them—I’d without hesitation recommend the Arduino, if you need an 8-bit micro-controller board, or the Raspberry Pi if you need a single-board computer running Linux.

It’s those communities that make the Arduino and the Raspberry Pi so useful, any problem you might come across it’s likely that someone else has come across it already and the solution, or at least the key to the solution, is already waiting for you and is just a Google search away.

Logically then, the only way for a new board to succeed is to either take over one of those existing communities, create its own community, or co-op a community that already exists but isn’t tied to an existing micro controller.

Right now there are two new micro-controller boards seeking funding—one on Kickstarter, and the other on Dragon Innovation’s new crowdfunding platform—that are slightly different. These boards aren’t just yet another Arduino clone, or yet another possible “Raspberry Pi killer.” These two boards, the Tessel from and the Espruino from Pur3, intend to take the path least travelled and co-op an existing community not traditionally associated with the maker community.

Aimed squarely in the gap between the Arduino at the low end, and the Raspberry Pi at the high end, both these boards use Javascript as their programming language, and both use it as close to the metal as possible. This is hardware hacking for web programmers, and it’ll be interesting to see if their arrival will bring the Javascript community with them when they arrive.

It’ll be the end of the month before the crowdfunding efforts for these boards close out, although both have already doubled their funding targets, and the start of next year before the maker-in-the-street will see final production hardware. However one of the advantages of working for Make is that sometimes you get to try hardware before other people, and I have pre-production prototypes of both the Tessel and the Espruino boards sitting on my desk right now—one of twelve in the case of the Tessel, and one of just two in the case of the Espruino.

The Tessel

The Tessel from was one of the eight products which launched the new Dragon Innovation crowdfunding platform last week, and the first to reach its funding goal. The Tessel is aimed on high end of the gap between the Arduino and the Raspberry Pi, squarely at Internet-connected applications targeting physical devices, and has WiFi built-in. That means not only that the board is always online, allowing it to be used as both as a server and a client, but you have the ability to remotely deploy your code onto the board via the network.

As well as standard GPIO bank at one end—which includes SPI, I2C, and UART capability as well as 6 General Purpose Input/Output pins, 6 Analog to Digital Converters, a 5V pin, a 3.3V pin, and a ground pin—the board supports a module system, making it easier to add capabilities to a project without soldering. There are two types of module, both have the same connector. Class A modules—a Relay, Temp/Humidity, Servo, Accelerometer and micro-SD Card board—and slightly more expensive Class B modules—RFID, Bluetooth LE, GPS and Audio boards.

My pre-production Tessel came with a Servo Module, which requires a second power supply dedicated to the servos.

The Tessel board with a Servo Module driving a standard servo.

The code to drive the servo module is pretty simple,

var servo = require('servo-pca9685');

// Initialize the servo.

// Port A, servo 1, calibrate min/max PWM of 4-15
var cs61 = servo.port('A').connect(1, 4, 15);

cs61.on('connected', function () {
   var pos = 0;
   setInterval(function () {
      console.log("Deg rotation:", pos);

      // Increment by 45 deg
      pos += 45;
      if (pos > 180) {
         pos = 0;
   }, 1500);

The board leverages npm and the sprawling node.js community—just install the servo module using npm into your node.js installation and then push your code to the Tessel board using the Tessel npm package. But it’s not just their own infrastructure that makes use of npm, the board is going to be compatible with thousands of existing node.js modules available via npm.

The fact that it’s node.js compatible may be a big factor in the success of the Tessel board, the node community is large, enthusiastic and—as can be seen from efforts such as nodecopter and Johnny Five—already open to working with hardware. That’s a big win for the Tessel, they have an instant community behind them. That counts for a lot.

Talking with Tim Ryan

I talked with Tim Ryan, one of the co-founders of Technical Machine,

What’s the goal for the Tessel project?

Our goal is to make hardware development a natural proposition for software developers. A huge part is enabling web and mobile developers to be able to use their existing skillsets to control the physical world.

What’s the underlying architecture of the Tessel board?

In-house we’ve developed a JavaScript interpreter built around the Lua runtime that is compatible with the Node.js API. No native C++ modules, but control flow and HTTP modules easily. Our OS is effectively an event loop on the bare metal. High-speed signal control and response are controlled asynchronously. We have experiments controlling high-speed refresh LED matrices and SPI peripherals showing that it’s an affordable alternative to realtime code, while being much more intuitive to write.

For example, the majority of our peripheral (mostly SPI and I2C) code clocks in at about 50 or 100 lines of commented code. Our runtime even gives us the proposition of doing simulation right on your command line before you deploy code, giving web developers another familiar tool, automated testing. To get started with any module we manufacture is as simple as “npm install accelerometer-mma8542q” and requiring it in code. Our development and deployment expeirence is being designed to be just a few steps out of the box to having a working example—plug in library, download command line tool, deploy.

 Why Javascript?

For Tessel, we’re completely focused on making the same tools for web/mobile development work on embedded boards. Between Node’s package manager and APIs and your choice of IDE, the idea should be that those same skills and workflow of pushing to a server are those you use here. There’s a lot of collaboration involved in making new APIs “JavaScript-like”, so hopefully the next generation of Javascript boards can all use the same SPI libraries, for example.

You rolled your own Javascript stack, why was that?

Tessel definitely loses out on speed by not going with a contemporary JavaScript engine. But compared to Linux+V8—which needs 8-10mb startup memory—our memory overhead thanks to Lua is minimal, less than 70kb.

We’re not intending to compete with microprocessors like the Raspberry Pi,we’re more interested in development that scales down—not up—to less powerful boards and SoCs. There is room in the future for a $3 Cortex-M3 microprocessor that runs JavaScript because it’s a natural solution for Internet-connected or IO-heavy code, and that’s the story we want to get across to developers, that you’re enabling so much more than just an alternative to C.

What’s are your future plans?

Our roadmap is to start with Tessel—a “high-powered” device—and work toward less-powerful devices. We have the potential to target boards as small as Espruino with a much faster runtime, and we’re investing a lot of effort into making sure Tessel’s runtime is a option for any internet-conencted device. And long-term, “Tessel” will probably not remain a platform just for JavaScript, but an easy platform to push firmware from other languages—C/C++, Lua, Rust, Go, and logically even Python and Ruby. Our value is in easy workflow and libraries, not just JavaScript itself.

So we’re betting on JavaScript-enabled development boards just being the first step. In a year from now, the trend will be toward accessible embedded electronics that let you program in whatever language you want—so long as your answer is not “C”! Tessel is going to stay right on top of that trend.

The Espruino

Launched a few days ahead of the Tessel on Kickstarter, just at the end of August, the  Espruino board from Pur3 is significantly cheaper than the Tessel. At £19—that’s around $30—it’s actually less than half the price of the Tessel board. Of course the specification of the Espruino is much lower. Although they both have ARM Cortex-M3 processors, the Espruino has just 48KB of SRAM compared to the Tessel’s 32MB of SRAM. While the Tessel is aimed at the high end of the gap between the Arduino and the Raspberry Pi, the Espruino is aimed at the lower end, but it’s priced to match.

The Espruino is an interesting departure from most modern boards. Unlike the Tessel—or the Arduino—you don’t upload your code to the board. Instead you have an interactive interpreter. Plug the board into your Mac or PC, and connect to the board over the USB serial port, and you’ll be presented with an interactive console.

It let’s you iterate really quickly, and enjoying tinkering with the things you make. – Gordon Williams

You can use the interactive console in exactly the way you’d expect—and in a way that will be really familiar for those of us that grew up with computers running BASIC—just type your code at the prompt.

Since the Espruino is entirely event-based that means that you can write functions that you can modify and add to while they are running. With the Espruino you don’t upload code to the board, instead you interact with it.

YouTube player

For instance we can set up a simple function that will watch for the on-board button to be pressed,

setWatch(function() {
  if (!digitalRead(BTN)) return;
  var led=10;
  var flasher = setInterval(function() {
   if (led<=0) clearInterval(flasher);
  }, 200);
}, BTN, true);

Once set up this function will watch for the button press event in the background, and you’ll be returned to interactive prompt. Exactly as you’d expect.

The Espruino board flashing an LED after pushing a button

In the same way the Apple ][+, and to a lesser extent the TRS-80, ware familiar sights in US schools, in the UK during the 80’s and 90’s schools had the BBC Micro. It left a lasting legacy, and despite not being explicitly marketed towards education I think this board is a must have for schools, and to teach people programming.

The Espruino, perhaps even more so than the Raspberry Pi—another UK-based project aimed at schools and teaching children to program—is a worthy successor to the BBC Micro.

Talking with Gordon Williams

I talked with Gordon Williams, the creator of the Espruino, about the board and his Kickstarter campaign,

The Espurino has an interactive interpreter, why did you do things that way?

I really like C, but when you’re writing compiled code for microcontrollers there’s a real disconnect between you and the microcontroller – it’s running in a black box, and the only way you can interact with your software as it’s running is by adding yet more software (or maybe by using a debugger). As an example, I made a box to control the variable valve timing on my car’s engine, but 90 percent of the effort involved in that was actually in adding code so that I could check what it was doing and adjust values while the engine was running. If you have an interactive interpreter then that’s all done for you.

So I wanted a language that could be interpreted, inspected and modified on the fly, but that looked a lot like C – and I wanted to use something that already existed rather than just creating my own, like the Electric Imp guys have done with Squirrel. I’d implemented a small version of JavaScript, called TinyJS, for a previous project so it made a lot of sense to base Espruino on that. The decision to use an event-based model actually came because of JavaScript – and it just seemed to be a great fit.

Why is an event-based model better than the loop-based model that the Arduino and other controllers use?

Using an event-based model has several great advantages.t means different bits of code doing different jobs can run together without interfering, and you can edit code in-between processing of events, rather than having to break out of the main loop. It’s more intuitive because it mimics the way people naturally describe tasks in the real world, for instance “When it is dark, turn on the light” rather than,  “Is it dark? Is it dark? Is it dark? Yes. Turn on the light!” and it’s a good fit for the graphical programming environment because it’s more modular. Finally it cuts power consumption drastically, so it’s great for battery life.

You rolled your own Javascript stack, why was that?

Writing my own interpreter was really necessity rather than choice. If you look at the memory requirements of the main interpreters like V8—used by node.js—and SpiderMonkey, they’re pretty huge – in the region of megabytes. They also have hooks into the underlying operating systems, so trying to run them on a small devices such a micro-controller—with around ×1000 less RAM—without an operating system is nearly impossible.

The Espruino uses ARC rather than garbage collection, it just fits nicely with the way the interpreter works, and it makes almost every memory allocation/deallocation very fast—especially as all blocks are equal size.

It leads to an interesting point about these ARM microcontrollers. Espruino runs at 72Mhz with 48KB of RAM, so at a very rough estimate it can read every single byte of its memory in around 1ms. Compare this to a Raspberry Pi with 800Mhz and 512MB of RAM with a read time nearer 1 second—this means you have to think about how you handle data completely differently, and it’s one of the reasons that I couldn’t easily use an existing interpreter.

A lot of Kickstarter projects have problems scaling. If your project is a runaway success, are you ready?

Yes. I’ve got a production ready board that I can send to Seeed Studio, it’s ready to go. Over the last two months we have worked with Seeed to improve our design and, sourcing components from Seeed’s Open Parts Library, to ensure we are not compromising on quality. This has enabled us to produce the design for the current version of the Espruino Board. However if the project got significantly more funding than expected, it would be great to bring someone in to help with the tutorials and documentation side of the Kickstarter. I think it’s all about giving people places to start, like the electronic dice project on our Kickstarter page.

What are your future plans?

If we reach £50,000 on our current campaign we will be adding support for the CC3000 WiFi module into the Espruino board. We won’t be producing a WiFi shield—we’ve got to focus on Espruino itself—but we will be adding support for the CC3000 into the Espruino board’s software before it’s shipped out to you. This means you’ll be able to buy a pre-made module, plug it in, and have instant internet access. But I’m also tempted to build a “shield-shield” which would slip underneath the Espruino board to give it an Arduino-compatible pin out. Going forward I’m also interested in building a much smaller version of the Espruino board.

Do two boards make a trend?

The Javascript community already has an interest in hardware—you only have to look at nodecopter to see that—and the arrival of not one, but two boards, that are both Javascript native and event-based will be met with a lot of interest. The fortunate fact that the boards don’t really compete with each other, the Tessel targeting the high-end and the Espruino the lower end, probably means that both are going to find a niche—and that niche is going to be fairly extensive.

Two boards might not make a trend, but I won’t be surprised to see these two boards inspiring a new generation event-driven micro-controllers—so these two boards just might.


Discuss this article with the rest of the community on our Discord server!

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

View more articles by Alasdair Allan


Ready to dive into the realm of hands-on innovation? This collection serves as your passport to an exhilarating journey of cutting-edge tinkering and technological marvels, encompassing 15 indispensable books tailored for budding creators.