Statistics
| Branch: | Revision:

adafruit_bno055 / examples / read_all_data / read_all_data.ino @ 7faf77c3

History | View | Annotate | Download (2.863 KB)

1
#include <Wire.h>
2
#include <Adafruit_Sensor.h>
3
#include <Adafruit_BNO055.h>
4
#include <utility/imumaths.h>
5

    
6
/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
7
   which provides a common 'type' for sensor data and some helper functions.
8

    
9
   To use this driver you will also need to download the Adafruit_Sensor
10
   library and include it in your libraries folder.
11

    
12
   You should also assign a unique ID to this sensor for use with
13
   the Adafruit Sensor API so that you can identify this particular
14
   sensor in any data logs, etc.  To assign a unique ID, simply
15
   provide an appropriate value in the constructor below (12345
16
   is used by default in this example).
17

    
18
   Connections
19
   ===========
20
   Connect SCL to analog 5
21
   Connect SDA to analog 4
22
   Connect VDD to 3.3-5V DC
23
   Connect GROUND to common ground
24

    
25
   History
26
   =======
27
   2015/MAR/03  - First release (KTOWN)
28
*/
29

    
30
/* Set the delay between fresh samples */
31
uint16_t BNO055_SAMPLERATE_DELAY_MS = 100;
32

    
33
Adafruit_BNO055 bno = Adafruit_BNO055(55);
34

    
35
void setup(void)
36
{
37
  Serial.begin(115200);
38
  Serial.println("Orientation Sensor Test"); Serial.println("");
39

    
40
  /* Initialise the sensor */
41
  if (!bno.begin())
42
  {
43
    /* There was a problem detecting the BNO055 ... check your connections */
44
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
45
    while (1);
46
  }
47

    
48
  delay(1000);
49
}
50

    
51
void loop(void)
52
{
53
  //could add VECTOR_ACCELEROMETER, VECTOR_MAGNETOMETER,VECTOR_GRAVITY...
54
  sensors_event_t orientationData , angVelocityData , linearAccelData;
55
  bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
56
  bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
57
  bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);
58

    
59
  printEvent(&orientationData);
60
  printEvent(&angVelocityData);
61
  printEvent(&linearAccelData);
62

    
63
  int8_t boardTemp = bno.getTemp();
64
  Serial.print(F("temperature: "));
65
  Serial.println(boardTemp);
66

    
67

    
68
  delay(BNO055_SAMPLERATE_DELAY_MS);
69
}
70

    
71
void printEvent(sensors_event_t* event) {
72
  Serial.println();
73
  Serial.print(event->type);
74
  double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem
75
  if (event->type == SENSOR_TYPE_ACCELEROMETER) {
76
    x = event->acceleration.x;
77
    y = event->acceleration.y;
78
    z = event->acceleration.z;
79
  }
80
  else if (event->type == SENSOR_TYPE_ORIENTATION) {
81
    x = event->orientation.x;
82
    y = event->orientation.y;
83
    z = event->orientation.z;
84
  }
85
  else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) {
86
    x = event->magnetic.x;
87
    y = event->magnetic.y;
88
    z = event->magnetic.z;
89
  }
90
  else if ((event->type == SENSOR_TYPE_GYROSCOPE) || (event->type == SENSOR_TYPE_ROTATION_VECTOR)) {
91
    x = event->gyro.x;
92
    y = event->gyro.y;
93
    z = event->gyro.z;
94
  }
95

    
96
  Serial.print(": x= ");
97
  Serial.print(x);
98
  Serial.print(" | y= ");
99
  Serial.print(y);
100
  Serial.print(" | z= ");
101
  Serial.println(z);
102
}
103

    
104