blob: 668cef1c52376058a5bbfe5b0c87546cda44e31f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "Arduino.h"
#include "GY521.h"
GY521 sensor(0x68);
void setup()
{
Serial.begin(9600);
// Wait for Serial because the Arduino Leonardo is weird
while (!Serial) {}
Wire.begin();
delay(100);
while (!sensor.wakeup())
{
Serial.print(millis());
Serial.println("Error: Could not connect to the GY521 sensor. Retrying after 2000 milliseconds...");
delay(2000);
}
sensor.setAccelSensitivity(2); // 8g
sensor.setGyroSensitivity(1); // 500 degrees/s
sensor.setThrottle();
Serial.println("start...");
// Calibration values
sensor.axe = 0.198;
sensor.aye = -0.018;
sensor.gxe = 0.780;
sensor.gye = -1.495;
}
void loop()
{
sensor.read();
float pitch = sensor.getPitch();
float roll = sensor.getRoll();
Serial.print("Pitch: ");
Serial.print(pitch, 3);
Serial.print(" Roll: ");
Serial.print(roll, 3);
Serial.println();
}
|