Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aresnick/1c2911b7a6c2dfecd463823e6253a96d to your computer and use it in GitHub Desktop.
Save aresnick/1c2911b7a6c2dfecd463823e6253a96d to your computer and use it in GitHub Desktop.

Setting up Arduinos for usage with johnny-five

πŸ—Ί Overview

Roughly, we're going to program the Arduino so that it can speak Firmata. Firmata will let our computer talk to the Arduino over USB. There is a JavaScript library called johnny-five which lets us control a wide variety of microcontrollers (including the Arduino) using the Firmata protocol. After teaching the Arduino Firmata, we're going to install johnny-five on our computer and get a simple, blinking LED working on the Arduino.

🎬🎬🎬

Installation

Setting up your Arduino

  1. ⬇ Download and install the Arduino IDE if you don't have it already. You can read more about the Mac directions here and the Windows directions here.
  2. Open the Arduino, and under Tools, make sure that the right Board is selected (likely the Uno).
  3. Also under Tools, make sure the right Port is selected.
  4. Then, open the Firmata project. To do this, navigate to File > Examples > Firmata > StandardFirmataPlus.
  5. Click the compile and upload button (the right arrow ➑ next to the check mark) at the top of the IDE.
  6. Once that is done (without errors, which will appear in orange in the black console at the bottom of your IDE), your Arduino can speak Firmata!

Setting up your computer

  1. Install node.js. On a Mac, do this by installing Homebrew and running brew install node. On a Windows machine, download and run the LTS Windows installer
  2. Run npm install -g johnny-five in your πŸ’» terminal. On a Windows machine, you should be able to do this at your command prompt.
  3. Paste the following code into a file named blink.js
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var led = new five.Led(13);
  led.blink(500);
});
  1. Now, navigate to the πŸ“ directory containing blink.js in your terminal (or command prompt, on a Windows machine).
  2. In that πŸ“ directory, run node blink.js. This should connect to your board and cause the on-board LED πŸ’‘ (next to pin 13) to blink every half-second. If this works, you're done! Congratulations! πŸ’―πŸŽ‰πŸ‘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment