Running Node.js on Arduino Yun

Arduino Yun is a great device once you learn how to use it correctly. Microcontrollers like the Atmel-ICs used in all nearly all Arduino compatible devices haven’t a lot of power or memory to Internet-Traffic. Of course they can, there are libraries and modules out there that will transform your little Arduino in a full-fledged Internet of Things device, but you will not have a lot of fun running it.

I.e. a typically RESTFul Web service will deliver so much JSON-Code that even a slightly more complex response will blow the memory of your Arduino.

Arduino Yun, and a few others like DigiX (sold in Germany for example by cboden) or Udoo solve this problem by merging the best of both worlds onto one device. Imaging a Raspberry Pi with an Arduino. If you want to know more about the difference between those two I have a small introduction on both devices.

Arduino Yun packs a full-fledged rather powerful Linux-machine onto an Arduino Leonardo. A so-called bridge allows the Linux part to talk to the sketch, and the sketch is allowed to run the Linux shell. This way you can use everything that has ever been build for Linux, the whole Internet-Stack, and the Arduino Sketch controls all that.

The previous example of running a rather complex RESTFul-Webservice, the sketch would run a Python, PHP, Node.js-Script on the Linux side that will request the data, process them, and delivers back only the really useful things to the micro controller. This way memory is now blown.

Since the latest software-update for Yun (see here on how to update your Yun) you are allowed to run Node.js on the Linux side of your Yun. That way you have a very powerful combination as Node.js is basically exactly build for that: Handling events in a very easy and transparent way. I have never really loved to work in Python, so I have been very pleased to know that I can write my Arduino Internet of Things Code in JavaScript using Node.js.

Following the tutorial to install Node.js on your Yun, which you can find here I got some out of memory errors when installing packets using npm. To be precise:

FATAL ERROR: Evacuation Allocation failed - process out of memory

Searching for some help I found this forum post did help for me and others. I am not sure if the error might come back with larger packages, I have been able to install the Parse SDK after following these basic steps:

Access your Yun with ssh and enter this  in the command line when connection has been established:

nano /usr/bin/node

Edit the file to look like that:

#!/bin/sh
#NODE_PATH=/usr/lib/node_modules /usr/bin/nodejs --stack_size=1024 --max_old_space_size=20 --max_new_space_size=2048 --max_executable_size=5 --gc_global --gc_interval=100 $@
NODE_PATH=/usr/lib/node_modules /usr/bin/nodejs $@

Then retry your npm install command. It should work now.

By the way, if you get an terminal error when running nano in Mac OS X Lion and above:

Error opening terminal: xterm-256color.

Just follow these steps to fix it (on Mavericks I had to select the xterm option).

One thought on “Running Node.js on Arduino Yun

Leave a Reply

Your email address will not be published. Required fields are marked *