The JavaScript blog.


resources hardware libraries node browser

Myo.js, JavaScript.com

Posted on .



Myo from Thalmic Labs is a gesture control armband that's described as a "wearable presentation remote". Paul Bernhardt from Thalmic Labs sent me myo.js (GitHub: thalmiclabs/myo.js, License: BSD 3-Clause, npm: myo), a JavaScript library for interacting with the device. It uses WebSockets to talk to Myo Connect, which runs on your desktop.

The API is based around events. Here's a quick example:

myMyo.on('gyroscope', function(data) {  
  if (data.x > 100){
    alert('Woah now!')

It also supports "poses", for example: myMyo.on('thumb_to_pinky', cb).

The API is pretty well documented, with method documentation and examples in the readme. There's also a blog post that introduces Myo.js.



Code School, the web-based subscription tutorial site, has recently launched javascript.com. It has an interactive tutorial, a blog, and resources to help beginners.

Naturally it promotes Code School (owned by Pluralsight), but it's nice to see something useful and well designed there. It used to have a very dated internet.com page, so Code School's page is a step up.


libraries node modules hardware iojs error-handling

Node Roundup: io.js, npm and jQuery, error-system

Posted on .


Last Friday, io.js 1.5.0 was released, which is another major milestone for the project. It introduces a new Buffer.prototype.indexOf method, which is like Array.prototype.indexOf. This is implemented in node_buffer.cc, and works with strings and numbers.

Last week Rodd Vagg posted a comment about io.js on DailyJS to say that the ARMv8 support is separate to the earlier Node support for ARMv6 and 7, and it actually sounds quite significant. According to last week's release notes, Linaro has contributed hardware to help io.js with ARMv8:

this is an entirely new architecture from ARM that adds 64-bit support which they are heavily pursuing the server market with. io.js (Node) + ARMv8 on the server is an amazing opportunity and ARM have been lending their support to the io.js project to make this work.

64bit ARM means more RAM in Android phones and tablets, which is great. But what about servers -- are we going to be able to use low-powered clusters of powerful ARM machines? Linaro has details on its ARM servers, and has an application form for people to request access to try them out. Linaro says it's planning to use servers are based on Opteron A1100 Cortex-A57, and X-Gene.

The best place to read more about the latest io.js release is the io.js Week of March 6th post on Medium. Which reminds me, there's an @iojs Medium account which is definitely worth following.

npm and jQuery

The npm weekly update points to yet another npm and jQuery plugin article. This one talks about how to make your own jQuery plugins make better use of npm. This includes referencing stylesheets in package.json and CommonJS compatibility.


Something I like to do in my Node-based web apps is include an errors.js file that subclasses Error with constructors named after HTTP errors. It makes it easier for me to pass the right error into next (in Express/Connect) so the error gets passed along to a centralised error handler. The way I do it is basic old skool JavaScript, so I've been looking for ways to improve it

Fomichev Kirill noticed Rod Vagg created node-errno. Rodd's module includes errors for libuv and Node, so you can check error codes with expressions like require('errno').code.ENOTEMPTY. You can also use it as a command-line tool for checking Node errors, and it has an API for making custom errors. The custom errors include the call stack, and it allows error hierarchies to be created.

Inspired by this, Fomichev made error-system (GitHub: fanatid/error-system, License: MIT, npm: error-system). It's similar to Rodd's module, but is designed specifically for creating custom errors. If you were making a web application, you could make a class for request errors like this:

var errorSystem = require('error-system')  
var RequestError = errorSystem.createError('RequestError', 'Code: {0} (url: {1})')  

This is exactly what I wanted when I made my original errors.js file. I particularly like the numbered arguments in Fomichev's module because it cuts down the amount of boilerplate when compared to my solution.


hardware hacking kickstarter

JavaScript on a USB Stick

Posted on .

Espruino Pico

Kris Bright sent in the Espruino Pico Kickstarter campaign, which is a new version of Espruino designed to run on smaller hardware. It will use a slightly modified version of the Espruino software, and they have prototype hardware so you should factor that in if you're thinking about pledging support.

This project is currently fully funded -- the goal was £15,000 but they've got £21,073 at the time of writing.

One novel feature of the Pico is it works with a standard USB port, so you can run JavaScript on it without any soldering or breadboards. And because the hardware is smaller it should use less power: the creators have claimed 10 years on a single AA-sized 3v lithium battery.

If you pledge £79 or more, then you'll receive a "Geek's Toy Kit". This should include some cool modules that are compatible with the Espruino Pico, like an LCD screen.

I've got an Espruino and the thing that's most fun about it is getting code to work with sensors and hardware like motors and screens, so if you're interested in the Pico I recommend either plumping for the Geek's Toy Kit or finding out how to use your own electronics with it.


node hardware

Node Hardware Hacking with Tessel

Posted on .

Node-compatible hardware.

Imagine being able to run npm install gprs to add GPRS tracking support to a hardware project... Well, now you can with Tessel!

The idea behind hardware platforms like Tessel is to make it easier for software developers to interface with hardware. This is ideal if you've ever thought it would be nice to hook up a movement sensor to a camera to take a photo whenever your dog or cat moves.

Microcontrollers are chips that contain a processor, memory, and I/O. You can hook them up to sensors for input, and things like servos and speakers for output. Unfortunately microcontrollers have limitations -- once you start adding the amount of RAM and processing power required for a high-level language like JavaScript then the costs add up. Also, while they can be programmed, most of them aren't trivial to program -- some have to be flashed with special hardware.

This is why Arduino was such a big deal: it made it easier for programmers and non-technical tinkerers to upload code to a microcontroller using a computer and USB cable.

Tessel and Espruino have iterated on Arduino by using slightly more powerful hardware to allow JavaScript to run. Espruino's strength is it uses a specialised version of JavaScript that means it can use cheaper, low-powered hardware.

On the other hand, Tessel has built-in Wi-Fi and an ARM Cortex-M3 microcontroller. Because it's so powerful, it can run thousands of standard Node modules straight from npm. And even better, Tessel has a wide selection of hardware modules, including:

  • Accelerometer
  • Audio (MP3/AAC/WMA/MIDI/FLAC/Ogg Vorbis)
  • Bluetooth LE
  • Camera
  • MicroSD
  • Relay (for controlling higher-powered devices)
  • Servo

Naturally all of these toys come at a price: Tessel with a single module costs $99. You can also buy Tessel with all available modules for $599.

I have an Espruino, but I don't have a Tessel yet. I like the idea of using npm install with Tessel, but Espruino is already easy to connect to sensors and other hardware, particularly for those with Arduino experience.

My recommendation is to try Tessel if you're perplexed by hardware but good at Node, and have some free time and cash.


node modules hardware gbnc

Espruino: JavaScript Hardware Hacking

Posted on .


Espruino is a cheap and tiny microcontroller that can be scripted with JavaScript. That means you can use JavaScript and an Arduino-inspired API to communicate with sensors, motors, and LCD displays. Rather than using Arduino's Processing-derived IDE, or Node modules to communicate with Arduino, you can use something designed with JavaScript in mind from the ground up.

There's an official Espruino board, but there are also compatible boards that you can use. The Espruino firmware can be installed on the other boards manually, so if you've already dabbled with microcontrollers you should be able to get a compatible board loaded up and ready to run. The Espruino hardware reference has more details.

The Raspberry Pi has some IO pins (the GPIO connector), but microcontroller-based boards like the Espruino use much less power. That means you could leave a board running on batteries for a significant amount of time.

The project was successfully funded on Kickstarter, where they raised £100,710.

If you want to flash a compatible microcontroller check out Espruino's downloads page. If you want to see the source, go to espruino / Espruino. It contains a JavaScript lexer and parser, because the author (Gordon Williams) found V8 and SpiderMonkey used too much RAM to run on the chips he wanted to target. Have a look at the C source code if you're interested in seeing how it works.