Getting started with Espruino, a JavaScript interpreter for microcontrollers



If you’ve used microcontrollers like the Arduino before, you might be used to pushing compiled code onto the device and then just hoping it does what it’s supposed to. The chip is literally a black box: If you don’t add print statements (or they don’t get a chance to execute), you’ll have no idea what your code is doing (or even if it’s doing anything at all).

In a lot of cases, you can add external debugging hardware to get more of an idea what’s going on in the microcontroller, but it’s not ideal—especially as Linux support is often quite limited. It’d be a lot better if everything you needed was built into the device.

Pico pinned

That’s what Espruino is all about. It’s an open source and open hardware JavaScript interpreter that runs on the microcontroller itself. You simply plug it in and it appears as a USB serial port. You can then connect to that with any terminal application and get a REPL, where you can write, modify, and even debug your code by stepping through line by line. Any JavaScript code sent to the serial port will be executed. Simply write echo “digitalWrite(LED1,1)” > /dev/ttyACM0 to light an on-board LED. If you want to have a big warning light when your build fails, it’s easy with something like make;echo “digitalWrite(BIG_SIREN,$?)” > /dev/ttyACM0

While you can program with Espruino straight from a terminal, there are better tools available. These include a syntax highlighted text editor that runs in Google Chrome and a command-line application that uses Node.js. Both of these tools scan your source code for mentions of libraries that don’t come pre-installed on Espruino and automatically upload them onto the microcontroller alongside your code.

On the website, there’s a huge amount of documentation, libraries, and example code for connecting to and making all kinds of things. All the documentation is generated from GitHub, so it’s easy for users to help to improve it. The firmware will run on a wide variety of boards, but I sell boards like the Espruino Pico that have it pre-installed. Money from the sales allows me to work full-time on Espruino, improving it and helping support users.

3 Espruino projects

Here are some examples of things you can make with Espruino. All of these projects can be put together for less than $40 each:

Battery charger: With an Espruino Pico, a display, a breadboard, and some resistors, you can make a battery charger. It trickle charges batteries, but can also discharge batteries down to a known voltage and record how much charge they produce.

battery charger with Espruino

Wire Loop Game: With an Espruino Pico, a breadboard, and a bit of wire, you can make simple wire loop game that will play a sound when you lose and keeping track of your score.

Pico Wire Loop Game

Home computer: The Espruino is not just a basic language interpreter. It’s possible to make a complete ’80s-style home PC with it! Cheap 4×4 keypads are connected together to make a keyboard, and the Pico’s ability to output monochrome VGA is used to reproduce its REPL and make a completely self-contained computer—all in under 100 lines of JavaScript!

Espruino wired up

home computer with Espruino

If you want to find out more about Espruino or try it out yourself, there is firmware available for many different microcontroller boards.



Source link

,

Leave a Reply