Setup Your Environment

Installing Node.js

OS X

To install Node on OS X, you can use Homebrew (brew install node), or download the package directly from the Node website.

Ubuntu

On Ubuntu, you can install Node via apt-get (sudo apt-get install nodejs), or via the instructions on the Joyent wiki page.

Windows

For a Windows machine, your best bet is to download a Node installer directly from the Node website.

How To Install Cylon.JS

To get Cylon.JS up and running, you'll need the necessary modules for your hardware.

For instance, if you're working with an Arduino, you'll most likely want the cylon-firmata module. Additionally, you'll need the cylon-gpio and cylon-i2c modules to communicate with hardware attached to the Arduino.

You can install these packages through NPM:

$ npm install cylon cylon-firmata cylon-gpio cylon-i2c

Writing And Running Cylon.JS Robots

With the Cylon modules installed, you're ready to start writing your own code. You can take a look at some of the examples below, or read the guide page on Working with Robots.

Additionally, if you want to find more examples of how to write robots with Cylon.JS, check out our Examples page.

To run your robots, just pass the script to the node binary:

$ node robot.js

Cylon.JS Code Examples

Hello

var Cylon = require('cylon');

Cylon.robot({
  work: function() {
    every((1).second(), function() {
      console.log("Hello, human!");
    });
  }
}).start();

Arduino - LED + Button

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }
  },

  devices: {
    led: { driver: 'led', pin: 13 },
    button: { driver: 'button', pin: 2 }
  },

  work: function(my) {
    my.button.on('push', function() {
      my.led.toggle()
    });
  }
}).start();

Multiple Arduinos

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    arduino_A: { adaptor: 'firmata', port: '/dev/ttyACM0' },
    arduino_B: { adaptor: 'firmata', port: '/dev/ttyACM1' }
  },

  devices: {
    led: { driver: 'led', pin: 13, connection: "arduino_A" },
    button: { driver: 'button', pin: 2, connection: "arduino_B" }
  },

  work: function(my) {
    my.button.on('push', function() {
      my.led.toggle()
    });
  }
}).start();

Parrot ARDrone 2.0

var Cylon = require('cylon');

Cylon.robot({
  connections: {
    ardrone: { adaptor: 'ardrone', port: '192.168.1.1' }
  },

  devices: {
    drone: { driver: 'ardrone' }
  },

  work: function(my) {
    my.drone.takeoff();

    after((10).seconds(), function() {
      my.drone.land();
    }

    after((15).seconds(), function() {
      my.drone.stop();
    }
  }
}).start();

CLI

To get access to a number of useful command-line tools, you should check out our helpful CLI tool, Gort.

$ gort
NAME:
  gort - Command Line Utility for RobotOps

USAGE:
  gort [global options] command [command options] [arguments...]

VERSION:
  0.3.0

AUTHOR:
  Author - <unknown@email>

COMMANDS:
  scan         Scan for connected devices on Serial, USB, or Bluetooth ports
  bluetooth    Pair, unpair & connect to bluetooth devices.
  arduino      Install avrdude, and upload HEX files to your Arduino
  spark        Upload sketches to your Spark
  digispark    Configure your Digispark microcontroller
  crazyflie    Configure your Crazyflie
  klaatu       barada nikto
  dronedrop    Install, uninstall, update and download dronedrop firmware
  help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
  --help, -h           show help
  --version, -v        print the versio

There's also a separate Cylon CLI tool, used to generate new adaptor modules.

Where Next?

Where do we go from here?

Well, if you're interested in seeing some more examples of Cylon.JS in action, check out our Examples page.

If you'd like to find out more about a specific platform, our Platforms page will point you in the right direction.

Instead, if you'd rather explore at your leisure, the sidebar should help you find what you're looking for.

If you have any questions, please don't hesitate to get in touch with us and we'll try to help as best we can.

Contributing

We welcome your contributions! If you want to make Cylon.JS even better (even fixing typos!), check out the GitHub page!

Have you noticed an error in our docs site? Think a paragraph could be worded better? Please send us an issue or pull request! The site has it's own GitHub page too!

Want to suggest a feature? Report a bug? Show us something cool you made? Just say hi? You can also get in touch with us directly on Twitter, or ping us on IRC.