The STEMTera Breadboard and Johnny-Five's five.Leds
.
The STEMTera Breadboard is a nifty combination Ardunio (Uno R3) / breadboard. It has a Lego-compatible backside and it's available in black, white, and pink. When I got mine, of course the first thing I did was get it set up to run with Johnny Five.
Basic Functionality / Hello world
Making an LED blink is the Hello world!
of hardware. It's common to just use an Arduino's onboard LED on pin 13. Here's what you do to get up and running from scratch:
- Make sure Node, npm, Johnny-Five, and the Arduino app are all installed and updated.
- Connect the StemTera breadboard to your computer.
Protip: Be sure to use a USB mini cable that supports both charging and data transfer. I've been fooled more than once by a charging-only cable. When I tried using a charging-only cable to flash the Arduino, I'd see the "On" LED turn on, but the Arduino app didn't report the device on any port. I've since purged my supplies of any charging-only cables, hopefully.
- In the Arduino application, from the Tools menu, select Port and set it to whatever is newest (something like /dev/cu.usbmodem1441); the Arduino app should detect the port that your breadboard is connected to. Then from the Tools menu, set the Board to Arduino/Genuino Uno. Then from the File menu, choose Examples, then Firmata, and finally Standard Firmata. Then from the File menu, choose Upload. When the upload is successful, you can close the Arduino app.
- Open up your terminal / command line and create a new file called
blink.js
. Navigate to this file's location. Put this code in the file and then save it:var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { led = new five.Led(13); led.strobe( 1000 ); this.repl.inject({ // make led available as "led" in REPL led: led }); });
- From the command line, type
node blink.js
and then hit enter or return. - Your onboard LED should start blinking on and off every second - yay!
- In the new prompt from Node (called the REPL), you can interact with the board's LED. Try any one of these:
-
led.stop();
: The LED will stop what it's doing, and stay at it's current state. -
led.strobe(3000);
: The LED will blink on and off every 3 seconds. You can change the3000
to the number of milliseconds you want the LED to blink at. led.off();
led.on();
-
Red and Green LEDs
Now let's add external LEDs (and protective resistors of course). Build your circuit as shown here, using 2 330? resistors, two 3mm LEDs, and two jumper wires. This is the magic of the StemTERA breadboard - the circuit doesn't need to hop back and forth between the breadboard and the external Arduino.
Here's the code - store it in a file and run it as with the first block of code.
var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { // We can address them separately, or together in leds var red = new five.Led(6); var green = new five.Led(5); var leds = new five.Leds([red, green]); green.off(); red.on(); leds.blink(1000); this.repl.inject({ leds: leds // leds.stop() // Stop the strobing // leds.off // Turn them both off // leds.stop().off(); // Combine! }); });
You should see the red and green LEDs alternating between on and off every second, and only one of the LEDs will be on at a time.
The interesting thing about this code is that it uses the Leds class - which allows us to control all the LEDs at the same time. At first, the green LED is off, and the red one is on. Then we blink
the leds
class; flipping the on/off state of each LED at the same time. You could use this to easily control many more LEDs.
Permalink
Tags: code johnny-five maker node nodebots stemtera-breadboard