Skip to content
Rick Waldron edited this page Apr 24, 2015 · 31 revisions

The Gyro class constructs objects that represent a single Gyro sensor attached to the physical board.

We currently support two kinds of Gyros:

  • Analog (Like the Tinkerkit 2-Axis Gyro)
  • MPU6050

This list will continue to be updated as more Gyro devices are confirmed.

Parameters

  • General Options

    Property Type Value(s) Description Default Required
    controller string ANALOG, MPU6050 The Name of the controller to use "ANALOG" no
  • Analog Options (controller: "ANALOG")

    Property Type Value(s) Description Default Required
    pins Array of Strings ["A*"] The String analog pins that X, Y, and Z (optional) are attached to none yes
    sensitivity Number Varies by device. For Tinkerkit, use Gyro.TK_4X or Gyro.TK_1X This value can be identified in the device’s datasheet. none yes
    resolution Number Varies by device This value can be identified in the device’s datasheet 4.88 no
  • MPU6050 Options (controller: "MPU6050")

    Property Type Value(s) Description Default Required
    sensitivity Number LSB/DegreesPerSecond The sensitivity of the device. The MPU-6050 is currently configured at +/- 250 degrees per second 131 no

Shape

{ 
  id: A user definable id value. Defaults to a generated uid
  pins: The pins defined for X, Y, and Z.
  isCalibrated: The calibration state of the device. READONLY
  pitch: An object containing values for the pitch rate and angle. READONLY
  roll: An object containing values for the roll rate and angle. READONLY
  yaw: An object containing values for the yaw rate and angle. READONLY
  rate: And object containing the rate values of X, Y, and Z. READONLY
  x: Value of x axis. READONLY
  y: Value of y axis. READONLY
  z: Value of z axis. READONLY
}

Component Initialization

Analog

// Analog Gyro:
// 
//   - attach X and Y to "A0" and "A1" respectively
//   - Use the LPR5150AL 4X sensitivity rating
//
new five.Gyro({
  pins: ["A0", "A1"],
  sensitivity: 0.67, // optional
  resolution: 4.88   // optional
});

lpr5150l

MPU6050

// Create an MPU-6050 Gyro object:
//
//  - attach SDA and SCL to the I2C pins on your board (A4 and A5 for the Uno)
//  - specify the MPU6050 controller
new five.Gyro({
  controller: "MPU6050",
  sensitivity: 131 // optional
});

MPU6050

Usage

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

board.on("ready", function() {
  var gyro = new five.Gyro({
    controller: "MPU6050"
  });

  gyro.on("change", function() {
    console.log("gyro");
    console.log("  x            : ", this.x);
    console.log("  y            : ", this.y);
    console.log("  z            : ", this.z);
    console.log("  pitch        : ", this.pitch);
    console.log("  roll         : ", this.roll);
    console.log("  yaw          : ", this.yaw);
    console.log("  rate         : ", this.rate);
    console.log("  isCalibrated : ", this.isCalibrated);
    console.log("--------------------------------------");
  });
});

API

  • recalibrate() Tell the device to recalibrate

Events

  • change The "change" event is emitted whenever the value of the gyro changes more then the threshold value allows.

  • data The "data" event is fired as frequently as the user defined freq will allow in milliseconds. ("data" replaced the "read" event)

Examples

Clone this wiki locally