Physical Computing: 2

Physical Computing: 2

Physical Computing: 2

Physical Computing: 2

Slides are here:
http://mhellar.github.io/physcomp2/1


Grab the code here:
https://bit.ly/2sfx2Bm

    Topics for This Week:

  • Raspberry Pi Discussion
  • Serial Port Module Revisited
  • The Johnny Five Library
  • Creating a Twitter Lamp
  • Create and Twitter Button
  • API to LCD

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

Upload the Arduino sketch in hc-04-code/hc-04 and then check the output in the serial monitor

Open hc04_p5js in a text editor and the terminal. Change the port. NPM install. Make slight change to Arduino code. Node app.js and open localhost:3000 in your browser

ADXL354 accelerometer

An accelerometer is an electromechanical device that will measure acceleration forces. These forces may be static, like the constant force of gravity pulling at your feet, or they could be dynamic - caused by moving or vibrating the accelerometer.By measuring the amount of static acceleration due to gravity, you can find out the angle the device is tilted at with respect to the earth. By sensing the amount of dynamic acceleration, you can analyze the way the device is moving.

ADXL354 accelerometer

  • Connect
  • GND to GND
  • 3v to 3v
  • SCL to A5
  • SDA to A4
  • Open the Library Manager in Arduino
  • Install Adafruit ADXL Library
  • Install Adafruit Universal Sensor Library
  • Install ArduinoJSON Library
  • Run Sensortest from the Examples
  • Before going further lets a take looks at Arduino JSON
  • Upload JsonGeneratorExample
  • Open the serial monitor at 9600 BAUD
  • From arduino upload adxl345_json_serial.ino
  • This adds ArduinoJSON to the Sensortest
  • cd adxl_threejs_serial & open in text editor
  • Edit port setting on line 8 of index.js
  • NPM install & node index.js & open localhost:3000
  • Fun with shaders
  • cd adxl_threejs_serial_shader & open in text editor
  • Edit port setting on line 8 of index.js
  • NPM install & node index.js & open localhost:3000

Johnny-Five is the original JavaScript Robotics programming framework. Released by Bocoup in 2012, Johnny-Five is maintained by a community of passionate software developers and hardware engineers. Over 75 developers have made contributions towards building a robust, extensible and composable ecosystem.

Starting a new Node app

  • Create a new folder named, 'J5_led_1'
  • Open the terminal
  • type 'cd' & space
  • drag your folder to the terminal and hit return
  • Now we are in our new folder in the terminal
  • Type 'npm init' & hit return
  • fill out the questions
  • drag your folder onto Sublime Text
  • type 'npm install johnny-five --save
  • Have a look at the package.json file that was generated
  • This stores metadata about our app

contents of package.json


{
  "name": "J5_led_1",
  "version": "1.0.0",
  "description": "A Johnny Five LED app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "johnny-five": "^0.8.106"
  }
}

create a new file, enter the following code and save as index.js in your new folder

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var led = new five.Led(6);
  led.blink(500);
});
  • !!! Upload firmata to arduino !!!
  • run 'node index.js' at the terminal

try a pulse

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var led = new five.Led(6);
led.pulse(500);
});

Led Animations


var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var led = new five.Led(6);
led.pulse({
  easing: "linear",
  duration: 3000,
  cuePoints: [0, 0.2, 0.4, 0.6, 0.8, 1],
  keyFrames: [0, 10, 0, 50, 0, 255],
  onstop: function() {
    console.log("Animation stopped");
  }
});
});

Reference


LED API
Animation API
Full API

Project: Twitter Lamp

Make this circuit

Go Here:


https://apps.twitter.com/

create a new app

Gather tokens and keys



Update code in code/twitter-ard/app.js


var client = new Twitter({
    consumer_key: 'Enter Here',
    consumer_secret: 'Enter Here',
    access_token_key: 'Enter Here',
    access_token_secret: 'Enter Here'
})

From the terminal:


'cd twitter-ard'


'node app.js'

From the terminal:


'cd twitter-ard-location'


'node app.js'

Twitter API Reference


Here

Project: Twitter Button

Update code in code/twitter-ard/app.js


var client = new Twitter({
    consumer_key: 'Enter Here',
    consumer_secret: 'Enter Here',
    access_token_key: 'Enter Here',
    access_token_secret: 'Enter Here'
})

From the terminal:


'cd twitter-button'


'node app.js'

Let's hook up the Liquid Crystal Display


Detailed Reference

Johnny Five Examples

Upload Firmata to Arduino

code7/j5_lcd_weather


node app.js

code7/j5_lcd_bart


node app.js