Skip to content

Instantly share code, notes, and snippets.

@nebrius
Last active February 22, 2018 22:12
Show Gist options
  • Save nebrius/7aaee16ee7249df29cdb6e315887fc36 to your computer and use it in GitHub Desktop.
Save nebrius/7aaee16ee7249df29cdb6e315887fc36 to your computer and use it in GitHub Desktop.
Node.js + Raspberry Pi = Love IBM Index Talk Notes

Hardware list:

  • Ethernet cable
  • Thunderbolt ethernet adapter
  • USB power adapter
  • MiFi USB cable inverter for powering RPi
  • 2 x Micro USB B cables
  • 2 x Micro SD Cards
  • 2 x SD Card adapters
  • 2 x Raspberry Pi (2s)
  • Webcam
  • Webcam stand thing
  • Laptop
  • Laptop power adapter

Talk steps:

Flash the image

  • Switch to Chrome
  • Show off where to download image
  • Show off installation guide
  • Switch to terminal
  • diskutil list - note 8gb disk
  • diskutil unmountDisk /dev/disk3
  • Show off sudo dd bs=1m if=2017-11-29-raspbian-stretch.img of=/dev/rdisk3 conv=sync (already have this done)
  • Write lite version to SD card (about 2:20)
  • cd /Volumes/boot
  • touch ssh
  • cd ..
  • diskutil unmountDisk /dev/disk3

Connect to the RPi

  • Switch to the webcam
  • Connect Raspberry Pi to ethernet to laptop
  • Insert SD card once done writing
  • Plug in power
  • Switch to System Preferences
  • Enable internet sharing from Wifi to Thunderbolt
  • Wait for activity LED to stop flashing (about 1:20)
  • Plug in ethernet cable to RPi
  • Switch to a terminal
  • cat /var/db/dhcpd_leases
  • ssh pi@ip-from-above

Base configuration

  • passwd for security
  • sudo apt-get update
  • Show off sudo apt-get upgrade but don't actually run
  • sudo apt-get install git
  • sudo dpkg-reconfigure tzdata to set timezone
    • Select Pacific-new as timezone

Install Node.js

  • Talk about how apt-get repo sucks
  • Talk about LTS vs latest
  • curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  • sudo apt-get install nodejs
  • node -v
  • npm -v

Setup Johnny-Five

  • mkdir index
  • cd index
  • npm install johnny-five raspi-io (about 3:30)
  • Switch to Chrome
  • Go to johnny-five.io and talk about J5
  • Go to https://github.com/nebrius/raspi-io and talk about Raspi IO
  • Go to pin naming wiki article and talk about pin naming
  • Switch to terminal
  • Explain why have to reboot
  • sudo reboot
  • Log back in once up

Write LED hello world

const five = require('johnny-five');
const Raspi = require('raspi-io');

const board = new Five.board({
  io: new Raspi()
});

board.on('ready', () => {
  const led = new five.Led('P1-12');
  led.blink();
});

On laptop:

rsync -avz -e ssh *.js pi@192.168.2.2:/home/pi/index

On RPi:

sudo node --inspect-brk=192.168.2.2:9229 led.js
  • Change blink to pulse and talk about how J5 handles GPIO vs PWM under the hood for you

Bonus steps

  • Software PWM and Raspi IO constructor options
  • Show off button
const five = require('johnny-five');
const Raspi = require('raspi-io');

const board = new five.Board({
  io: new Raspi()
});

board.on('ready', () => {
  const led = new five.Led('P1-12');
  const button = new five.Button('P1-38');
  button.on('press', () => led.toggle());
});
  • Show off temperature sensor
const five = require('johnny-five');
const Raspi = require('raspi-io');

const board = new five.Board({
  io: new Raspi()
});

board.on('ready', () => {
  const thermometer = new five.Thermometer({
    controller: "MCP9808"
  });

  thermometer.on("change", () => {
    console.log("Thermometer");
    console.log("  celsius      : ", thermometer.celsius);
    console.log("  fahrenheit   : ", thermometer.fahrenheit);
    console.log("  kelvin       : ", thermometer.kelvin);
    console.log("--------------------------------------");
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment