/Node_Bots

Exploring the world of nodebots. Starting with an led light flashing and working up to a phone.

Primary LanguageJavaScript

Exploring the world of nodebots

This repo is for those who are interested in getting started with NodeBots and don't know where to go. I'm here for you. 🤗 I've included the hardware I used, website links, and files to get you going.

Hardware List

Part Source Price
Arduino Uno Board Arduino Website $22
Freenove Starter Kit Freenove Starter Kit $34
MAX7219 Core Electronics $10

Some pre-work

  • I purchased an Arduino Website board online, and after realizing I had no way to plug it into my computer also bought a Freenove Starter Kit ($34) as well.
  • I familiarized myself with Arduino Uno projects to see what’s possible in general.
  • I attended a saturday’s hackers session at Connected Community Hackerspace where I learned the basics of Ohm’s Law (electricity) and saw people building and driving around machine learning car robots in python.
  • There I did the “hello world” of arduino boards and made an led light turn on through the circuit board
  • I’ve looked through the Arduino library for some examples of different projects to build but realized they’re in C++ and I’m wanting to use Node.js
  • Johnny-Five is the main site for documentation and community

How to start a NodeBot project

Node Setup

If you don't have Node installed, go to the Node.js site and grab the latest version.

Once you've gotten Node installed, the next step differs depending on if you're using Mac OS or Windows.

Hardware Setup

Insert the shorter end of your led light into "GND" (short for ground) and the longer end into "13".

Plug the arduino into the computer using the USB.

Firmware Setup

Download the Arduino IDE

Go to the Johnn-Five website. And follow their "Hello World!" steps. Step 2, setup your board, was tricky for me. I first went to this site that they refer you to(Firmata Arduino Github) but found this page on Instructables to download Standard-Firmata the screenshots easier to follow.

I also ran into issues with my OS not allowing me to install the test from an unidentified developer, so this site was helpful on unlocking me security settings. How to install programs from unidentified developers

Install node-gyp which "is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js." npm install -g node-gyp

Software Setup

Make a directory

Create a node project
node init

Install the Johnny-Five dependency
npm install johnny-five

Clone this repo into your directory of choice by typing the following: git clone git@github.com:nikkiricks/Node_Bots.git

Navigate into the folder, you're going to have to install your dependencies.
npm install

In your CLI type:
node blink.js

And watch that light blink! Congrats! 🎉

For other projects see the practice_files and reference the fritzing images on the Johnny-Five Examples pages

How to make a button controlled servo with a led-matrix condition

Familiarize yourself with the Johnny-Five servo docs and the led-matrix docs.

Insert the MAX7219 into the arduino board. Pay attention to where the "GND" "VCC" "CS" etc. are written as I noticed different boards had them in different places and if you're a newbie like me, you will follow the instructions without looking at what is what.

With the base understanding of ground and volt, wire both the servo and matrix through a breadboard:

Combine the code from the led-matrix docs and add it to the "up-button" conditional statement in the now.js file:

//for servo
const {Board, Servo} = require("johnny-five");
const keypress = require("keypress");
keypress(process.stdin);
const board = new Board();
//for matrix (may not need both?)
var five = require("johnny-five");
// is this a problem that there are two boards?
// var board = new five.Board();

board.on("ready", function() {
  // insert code for servo
  console.log("Use Up and Down arrows for CW and CCW respectively. Space to stop.");

  const servo = new Servo.Continuous(10);

  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  process.stdin.setRawMode(true);

  process.stdin.on("keypress", (ch, key) => {

    if (!key) {
      return;
    }

    if (key.name === "q") {
      console.log("Quitting");
      process.exit();
    } else if (key.name === "up") {
      console.log("CW");
      servo.cw();

      var matrix = new five.Led.Matrix({
        pins: {
          data: 2,
          clock: 3,
          cs: 4
        }
      });

      matrix.on();

      var msg = " NOW".split("");

      // Display each letter for 2 seconds
      function next() {
        var c;

        if (c = msg.shift()) {
          matrix.draw(c);
          setTimeout(next, 2000);
        }
      }

      next();
    } else if (key.name === "down") {
      console.log("CCW");
      servo.ccw();
    } else if (key.name === "space") {
      console.log("Stopping");
      servo.stop();
    }
  });
})

Links to more advanced projects

Resources