Statistics
| Branch: | Revision:

adafruit_bno055 / examples / sensorapi / sensorapi.ino @ 48741e1f

History | View | Annotate | Download (3.911 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.3V 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
#define BNO055_SAMPLERATE_DELAY_MS (500)
32
   
33
Adafruit_BNO055 bno = Adafruit_BNO055(55);
34

    
35
/**************************************************************************/
36
/*
37
    Displays some basic information on this sensor from the unified
38
    sensor API sensor_t type (see Adafruit_Sensor for more information)
39
*/
40
/**************************************************************************/
41
void displaySensorDetails(void)
42
{
43
  sensor_t sensor;
44
  bno.getSensor(&sensor);
45
  Serial.println("------------------------------------");
46
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
47
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
48
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
49
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
50
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
51
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");  
52
  Serial.println("------------------------------------");
53
  Serial.println("");
54
  delay(500);
55
}
56

    
57
/**************************************************************************/
58
/*
59
    Arduino setup function (automatically called at startup)
60
*/
61
/**************************************************************************/
62
void setup(void) 
63
{
64
  Serial.begin(9600);
65
  Serial.println("Orientation Sensor Test"); Serial.println("");
66
  
67
  /* Initialise the sensor */
68
  if(!bno.begin())
69
  {
70
    /* There was a problem detecting the BNO055 ... check your connections */
71
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
72
    while(1);
73
  }
74
  
75
  delay(1000);
76
    
77
  /* Display some basic information on this sensor */
78
  displaySensorDetails();
79
  
80
  /* Display system info (optional) */
81
  bno.displaySystemStatus();
82
  Serial.println("");
83
  
84
  /* Display chip revision details (optional) */
85
  bno.displayRevInfo();
86
  Serial.println("");
87
}
88

    
89
/**************************************************************************/
90
/*
91
    Arduino loop function, called once 'setup' is complete (your own code
92
    should go here)
93
*/
94
/**************************************************************************/
95
void loop(void) 
96
{
97
  // Possible vector values can be:
98
  // - VECTOR_ACCELEROMETER
99
  // - VECTOR_MAGNETOMETER
100
  // - VECTOR_GYROSCOPE
101
  // - VECTOR_EULER
102
  // - VECTOR_LINEARACCEL
103
  // - VECTOR_GRAVITY
104
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
105
  Serial.print("X: ");
106
  Serial.println((int)euler.x(), DEC);
107
  Serial.print("Y: ");
108
  Serial.println((int)euler.y(), DEC);
109
  Serial.print("Z: ");
110
  Serial.println((int)euler.z(), DEC);
111
  Serial.println("");
112

    
113
  imu::Quaternion quat = bno.getQuat();
114
  Serial.print("qW: ");
115
  Serial.println((int)quat.w(), DEC);
116
  Serial.print("qX: ");
117
  Serial.println((int)quat.x(), DEC);
118
  Serial.print("qY: ");
119
  Serial.println((int)quat.y(), DEC);
120
  Serial.print("qZ: ");
121
  Serial.println((int)quat.z(), DEC);
122
  Serial.println("");
123
  
124
  delay(BNO055_SAMPLERATE_DELAY_MS);
125
}