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

We currently support two kinds of Gyros:

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

Parameters

  • General Options

    PropertyTypeValue/DescriptionDefaultRequired
    controllerstring"ANALOG", "MPU6050". The Name of the controller to use"ANALOG"no

  • Analog Options (controller: "ANALOG")

    PropertyTypeValue/DescriptionDefaultRequired
    pinsArray of Strings["A*"]. The String analog pins that X, Y, and Z (optional) are attached toyes
    sensitivityNumberVaries by device. For Tinkerkit, use Gyro.TK_4X or Gyro.TK_1X. This value can be identified in the device's datasheet.yes
    resolutionNumberVaries by device. This value can be identified in the device's datasheet4.88no

  • MPU6050 Options (controller: "MPU6050")

    PropertyTypeValue/DescriptionDefaultRequired
    sensitivityNumberLSB/DegreesPerSecond. The sensitivity of the device. The MPU-6050 is currently configured at +/- 250 degrees per second131no

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinsThe pins defined for X, Y, and Z.No
isCalibratedThe calibration state of the device.Yes
pitchAn object containing values for the pitch rate and angle.Yes
rollAn object containing values for the roll rate and angle.Yes
yawAn object containing values for the yaw rate and angle.Yes
rateAnd object containing the rate values of X, Y, and Z.Yes
xValue of x axis.Yes
yValue of y axis.Yes
zValue of z axis.Yes

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

BNO055

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

imu-bno055.png

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

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub