This is the first tutorial in a new series geared towards Arduino programming on Node.js, using the Johnny-Five framework.
At the end of the first article, I showed a simple program that would strobe an LED at the default rate of 100ms per phase. It’s pretty safe to assume that all starter kits come with LEDs. As the tutorials progress, I will introduce more diverse hardware — so you’ll need a few supplies to keep pace. I recommend investing in either of the following start kits:
The Ultimate Microcontroller Pack or the Inventor’s Kit for Arduino both come with everything you’ll need for almost all of the tutorials, however in some cases, they will need to be supplemented with additional parts. For a complete list of the parts I’ve used so far, check out the Johnny-Five Parts List.
First, set up the hardware using this schematic as your guide:
Connect the following…
Assuming you’re using the actual repo, open up
eg/servo.js, or follow along here…
If you run this now, you’ll notice that it creates a REPL session - you can access the
board object directly from here.
Next, let’s add a
Servo object and inject into the REPL:
And that’s it!
node eg/servo.js1 and try out some of the following commands from the REPL:
Note: There is a known issue in where the Firmata protocol layer has issues freeing itself on the serial line which results in the program hanging in the ready state. For now,
^C to kill the hanging program and simply run it again.