Checking the gyroscope MPU-6050

The gyroscope is essential for the achievement of a more or less humanoid robot ... It is used to find the incline of the robot, or any of its parts, in response to a command, or under the effect of an outer thrust.
After you've ordered this part (it is not present in Arduino kits) you have to verify that it works perfectly ...

Parts

Regarding the gyroscope and accelerometer, four ports are of interest to us for now:

  1. VCC: Linked to the power.
  2. GND: Linked to ground.
  3. SCL (Serial Clock): Speed, linked to an analog port.
  4. SDA (Serial Data): Angle, linked to an analog port.

SCL and SDA combined send a signal representing the horizontal and vertical incline and speed.

Circuit assembly

Test de montage d'un gyroscope

 

Test du gyroscope MPU-6050

JavaScript source code

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

console.log("start...")

board.on("ready", function() {
  console.log("ready...")
  var gyro = new five.Gyro({
    pins: ["I0", "I1"],
    sensitivity: 0.67 
  });
  gyro.on("change", function(err, data) {
    console.log("X raw: %d rate: %d  Y raw: %d rate: %d", this.x, this.rate.x, this.y, this.rate.y);
  });
});

The values I0 and I1 represent the digital ports A0 and A1, for reasons internal to the JF framework.

This program displays raw values, uninteresting in themselves, but the goal here is just to get these values. it will take a bigger code to interpret them ... The subject of another article.

Download the source code. It is the file gyro.js.

Troubleshooting

An interrupt is triggered in the framework and it displays an error message

This certainly comes from a bad connection of wires that make the MPU-6050 part is not recognized by the hardware and therefore the five.gyro object can not be created.
Try to achieve a more secure mounting using pins to better secure the MPU-6050 on the breadboard. This component is to be welded, this problem will then disappear ...

Nothing happens

After the message "Ready..." is displayed nothing happens. This is actually rather a good sign, you have just to tilt the breadboard in one direction or the other to enable the gyroscope and to values (around 170) be displayed after some delay...