Instructables

Javascript robotics and browser-based Arduino control

Picture of Javascript robotics and browser-based Arduino control
Use your JavaScript and web development knowledge to control Arduino projects and even robots (node + robots = nodebots)!

This is made easy with node.js, Firmata and Johnny-Five. Let's get started!

Johnny-Five logo by Mike Sgier. Arduino photo CC-BY Raeky.
 
Remove these adsRemove these ads by Signing Up

Step 1: Install node.js

Picture of Install node.js
Node.js is a javascript runtime based on Chrome's V8 engine. If you haven't used it before, node lets you run Javascript code on the server-side, it's designed around non-blocking I/O and asynchronous events. Node includes modules for accessing the filesystem, a web server, sockets and other basic tasks.

Download and install the node for your platform. Source and binaries are available for Windows, OS X and Linux.

http://nodejs.org/download/

If you're using Ubuntu/Debian, you can use apt-get install nodejs (not node). If you're using a distro's package manager, make sure your node version is recent!

node --version
v0.10.26

Step 2: Install johnny-five

Picture of Install johnny-five
install.png
npm.png
Johnny-Five is an Arduino control framework for Node. It works with Firmata firmware to enable you to do things like blink lights and control servos.

Create a folder for your project and use Node's package manager, npm, to install johnny-five.

At the command line use npm install as follows:

npm install johnny-five


If you'd like to create a web interface you'll need socket.io too:

npm install socket.io
 

Step 3: Upload Firmata to your Arduino

Firmata is a protocol for communicating with microcontrollers via a host computer. There are interface libraries available in Python, Processing, Javascript, Ruby and many other languages. Firmata sketches are included with the Arduino IDE.
  1. Download and open the Arduino IDE
  2. Go to File -> Examples -> Firmata -> StandardFirmata
  3. Upload Firmata to your Arduino board
jelimoore4 months ago

I cannot get it to work when I specify a board like so:

board = new five.Board({ port: "/dev/tty.usbmodem1431”});

My Terminal says:

/path/to/file/but/this/isn't/it/ledtest.js:3

board = new five.Board({ port: "/dev/tty.usbmodem1431”});

^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected token ILLEGAL

at Module._compile (module.js:439:25)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:312:12)

at Function.Module.runMain (module.js:497:10)

at startup (node.js:119:16)

at node.js:906:3

danasf (author)  jelimoore4 months ago

Hello, check your trailing quotation mark, it's curly, I think that may be tripping things up!

board = new five.Board({ port: "/dev/tty.usbmodem1431"});