Iain
Published

Setting up the Raspberry Pi and Johnny-Five

A comprehensive guide to easily set up your Raspberry Pi, including SSH, Node.js, and Johnny-Five!

IntermediateProtip4 hours10,523
Setting up the Raspberry Pi and Johnny-Five

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
Note: If this is your first time setting up the Raspberry Pi, you may also need an HDMI cable, a keyboard, and a mouse. I also suggest you get an SD containing NOOBS, this will make installing Raspbian a sinch!
×1
LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
Any breadboard will do!
×1

Software apps and online services

Johnny-Five
Johnny-Five

Story

Read more

Schematics

Pi Test Circuit

Just a simple circuit to test the provided script on the Raspberry Pi using Johnny-Five.

Code

index.js

JavaScript
// Test file for using the Raspberry Pi and Johnny-Five
const five = require('johnny-five');
const raspi = require('raspi-io');

// Make a new `Board()` instance and use raspi-io
const board = new five.Board({
        io: new raspi(),
});

// Run Board
board.on('ready', function() {

        // LED Pin variable
        const led = new five.Led('P1-7');

        led.on();

        this.repl.inject({
                on: () => {
                        led.on();
                },

                off: () => {
                        led.stop().off();
                },

                strobe: () => {
                        led.stop().off();
                        led.strobe();
                },

                blink: () => {
                        led.stop().off();
                        led.blink(500);
                },
        });

        // When this script is stopped, turn the LED off
        // This is just for convenience
        this.on('exit', function() {
                led.stop().off();
        });

});

Credits

Iain

Iain

5 projects β€’ 71 followers
Hello! I'm Iain, a digital creator. I like making projects with code, art, and robots. Follow me for awesome projects and fun tidbits!

Comments