Setting up the environment

Before you can make things do interesting stuff, you need to setup your lab environment. I’ve chosen this collection of technologies based on my own skill set and the needs of various projects.

Operating System:

Linux (Debian/Ubuntu) running on Raspberry Pi

To begin with, I decided to use the Raspberry Pi as my primary “thing” server because it runs Linux and has GPIO pins that can be used with future projects. I then decided to install a special ROM that has NodeJS built in called TheThingBox, which is optimized for use with Node-Red.

Node-Red is an Internet of Things project developed by IBM that makes writing and connecting to APIs really easy. It also has direct access to the Arduino and Raspberry Pi pins. Although most of my projects will be written directly in Javascript, this Node app makes testing and research really easy.

Microcontrollers:

I have a collection of microcontrollers that will be used in various projects. In most situations, these can be used interchangeably, but pay attention to the GPIO numbers and type (PWM/analog/digitial).

  • ARDUINOMEGA 2560
  • Provides 70 GPIO pins!
  • Dedicated PWM IC which is great for servos.

 

ARDUINO UNO+ (CLONE)
  • Provides 14 GPIO pins.
  • Basic Arduino.. but costs under £6. Great for use with a dedicate motor shield, or riskier experiments (robotic submarine?)
  • Requires special USB driver on Mac/Windows. Works perfectly with RPi/Linux.

RASPBERRY PI
  • Provides 17 GPIO pins.
  • Runs Linux, so tons of options at the OS level.
  • Not good for PWM or low latency operations.

Development Environment:

The common language for these microcontroller projects is either Python for Raspberry Pi or Arduino “sketches”, which is arguably a C++ syntax compiled to machine code. Since I was more familiar with web languages and since my goal is to easily speak with other web services, NodeJS with a robotics framework seemed more interesting/useful to me. There are two popular frameworks at this time, Johnny-five and CylonJS.

  • Johhny-Five.io
    • The original robotics framework provides an easy to use API to control lights, servos, sensors etc., using familiar JavaScript syntax.
    • Multiple device types supported.
    • There is a good book to help explore the capabilities called “Make: Javascript Robotics“. I read the book which helped shape many of my own projects.
  • CylonJS
    • A newer robotics framework that can control tons of devices easily with the same code. Think “army of drones”. That being said, the code structure is a little awkward at times and I had trouble with support for various components/drivers/shields. With a solid community, this could be a really great option.
    • Has built-in helper functions and simplified nodes for rapid development, such as timers and web socket/API handlers.

Because both frameworks seem promising, many of my projects will be written in either one or both. Doing this also helps me understand exactly what is going on, versus just copy/pasting code I found scattered on the Internet.

Steps to get started:

  • The Arduino will be configured as a slave to the host computer running NodeJs (Raspberry Pi). In order for this to work, you will need to select the StandardFirmata sketch from the examples provided with the Arduino IDE and upload it to your Arduino.
  • Connect the Arduino to the Raspberry Pi via USB cable.
    • This is required for power and all logic.
  • Connect to Raspberry Pi (or Linux shell) via SSH
$ ssh root@192.168.0.15    (This will be unique to your system)
$ password: raspberry
  • Create your project
    • Assuming NodeJS is already installed. If not, either use the TheThingBox image on your RPI or install NodeJS on your preferred system.
$ mkdir IoL
$ cd IoL
  • Initialize the folder by running “npm init”. This will create a package.json file, which defines the project and keeps record of installed node modules.
$ npm init
  • Install the “johhn-five” node module, which is key to accessing the GPIO pins using the javascript language.
$ npm install johnny-five --save
  • Create the application file.
$ nano helloworld.js
  • Place the following code in your “helloworld.js” file.
var five = require("johnny-five");

var board = new five.Board();

board.on("ready", function() {

     var led = new five.Led(13);

led.blink(500);

});
  • Save and run your code.
node helloworld.js
  • You should now see the built-in LED light on your Arduino blinking!

Arduino-LED-Overview

Now that we have a working environment, the fun begins!