From CampJS VIII, Melbourne 4 - 7 August 2017
This session will show you how to take your robotics and IoT dreams and make them reality through the magic of JavaScript, including:
selecting hardware and developing circuits,
overview of some of the different options for developing programs to read from sensors and control actuators for robotics and IoT projects using JS,
connecting your device and getting it talking with other devices and services
8. Connect to the Raspberry Pi
• Rpi uses mDNS so connect to the Pi over SSH:
• ssh pi@raspberrypi.local
• Default password is raspberry
• (Make sure you change this)
• Raspbian comes with node.js installed but if you are using something
else, install node
• Then use npm to install the dependencies:
• npm install serialport
• npm install johnny-five raspi-io
14. LED
• Create an Led instance
// attach LED on pin 7
const led = new five.Led('P1-7');
// call strobe function to blink once per second
led.strobe(1000);
• We can change the parameter to the strobe function to change the speed: This
input value is provided in milliseconds
15. LED blink program
const raspi = require('raspi-io');
const five = require('johnny-five');
const board = new five.Board({
io: new raspi()
});
board.on('ready', () => {
// LED attached to RPi pin 7 (GPIO4)
const led = new five.Led('P1-7');
led.strobe(500);
});
16. Inputs - Sensors
• Environmental conditions (e.g. temperature, humidity)
• Magnetic (e.g. hall effect sensor)
• Light (e.g. photo resistor)
• Sound (e.g. microphone, piezo)
• Movement / position (e.g. accelerometer, tilt switch)
• User Input (e.g. button)
20. Digital vs Analog
• Digital
• discrete values (0 or 1)
• Examples: tilt sensor, push button
• Analog
• continuous values
• typically values for analog sensors are constrained within a range e.g. 0 – 255,
0 – 1023
• Example: photo resistor
• Some components support both digital and analog