Setting up Arduinos for usage with johnny-five
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.
π¬π¬π¬
- β¬ 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.
- Open the Arduino, and under
Tools
, make sure that the rightBoard
is selected (likely the Uno). - Also under
Tools
, make sure the rightPort
is selected. - Then, open the Firmata project. To do this, navigate to
File > Examples > Firmata > StandardFirmataPlus
. - Click the compile and upload button (the right arrow β‘ next to the check mark) at the top of the IDE.
- 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!
- Install
node.js
. On a Mac, do this by installing Homebrew and runningbrew install node
. On a Windows machine, download and run the LTS Windows installer - Run
npm install -g johnny-five
in your π» terminal. On a Windows machine, you should be able to do this at your command prompt. - 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);
});
- Now, navigate to the π directory containing
blink.js
in your terminal (or command prompt, on a Windows machine). - 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! π―ππ