Statistics
| Branch: | Revision:

adafruit_bno055 / examples / bunny / bunny.ino @ master

History | View | Annotate | Download (4.2 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
#define BNO055_SAMPLERATE_DELAY_MS (100)
32

    
33
// Check I2C device address and correct line below (by default address is 0x29 or 0x28)
34
//                                   id, address
35
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
36

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

    
59
/**************************************************************************/
60
/*
61
    Arduino setup function (automatically called at startup)
62
*/
63
/**************************************************************************/
64
void setup(void)
65
{
66
  Serial.begin(115200);
67
  Serial.println("Orientation Sensor Test"); Serial.println("");
68

    
69
  /* Initialise the sensor */
70
  if(!bno.begin())
71
  {
72
    /* There was a problem detecting the BNO055 ... check your connections */
73
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
74
    while(1);
75
  }
76
   
77
  delay(1000);
78

    
79
  /* Use external crystal for better accuracy */
80
  bno.setExtCrystalUse(true);
81
   
82
  /* Display some basic information on this sensor */
83
  displaySensorDetails();
84
}
85

    
86
/**************************************************************************/
87
/*
88
    Arduino loop function, called once 'setup' is complete (your own code
89
    should go here)
90
*/
91
/**************************************************************************/
92
void loop(void)
93
{
94
  /* Get a new sensor event */
95
  sensors_event_t event;
96
  bno.getEvent(&event);
97

    
98
  /* Board layout:
99
         +----------+
100
         |         *| RST   PITCH  ROLL  HEADING
101
     ADR |*        *| SCL
102
     INT |*        *| SDA     ^            /->
103
     PS1 |*        *| GND     |            |
104
     PS0 |*        *| 3VO     Y    Z-->    \-X
105
         |         *| VIN
106
         +----------+
107
  */
108

    
109
  /* The processing sketch expects data as roll, pitch, heading */
110
  Serial.print(F("Orientation: "));
111
  Serial.print((float)event.orientation.x);
112
  Serial.print(F(" "));
113
  Serial.print((float)event.orientation.y);
114
  Serial.print(F(" "));
115
  Serial.print((float)event.orientation.z);
116
  Serial.println(F(""));
117

    
118
  /* Also send calibration data for each sensor. */
119
  uint8_t sys, gyro, accel, mag = 0;
120
  bno.getCalibration(&sys, &gyro, &accel, &mag);
121
  Serial.print(F("Calibration: "));
122
  Serial.print(sys, DEC);
123
  Serial.print(F(" "));
124
  Serial.print(gyro, DEC);
125
  Serial.print(F(" "));
126
  Serial.print(accel, DEC);
127
  Serial.print(F(" "));
128
  Serial.println(mag, DEC);
129

    
130
  delay(BNO055_SAMPLERATE_DELAY_MS);
131
}