Statistics
| Branch: | Revision:

adafruit_bno055 / examples / bunny / bunny.ino @ 3cae40b9

History | View | Annotate | Download (3.977 KB)

1 8cc46552 Kevin Townsend
#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 2fa9c672 Tony DiCola
9 8cc46552 Kevin Townsend
   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 2fa9c672 Tony DiCola
18 8cc46552 Kevin Townsend
   Connections
19
   ===========
20
   Connect SCL to analog 5
21
   Connect SDA to analog 4
22 c82fdc7d ladyada
   Connect VDD to 3.3-5V DC
23 8cc46552 Kevin Townsend
   Connect GROUND to common ground
24 2fa9c672 Tony DiCola
25 8cc46552 Kevin Townsend
   History
26
   =======
27
   2015/MAR/03  - First release (KTOWN)
28
*/
29
30
/* Set the delay between fresh samples */
31 c82fdc7d ladyada
#define BNO055_SAMPLERATE_DELAY_MS (100)
32 8cc46552 Kevin Townsend
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 2fa9c672 Tony DiCola
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");
52 8cc46552 Kevin Townsend
  Serial.println("------------------------------------");
53
  Serial.println("");
54
  delay(500);
55
}
56
57
/**************************************************************************/
58
/*
59
    Arduino setup function (automatically called at startup)
60
*/
61
/**************************************************************************/
62 2fa9c672 Tony DiCola
void setup(void)
63 8cc46552 Kevin Townsend
{
64
  Serial.begin(115200);
65
  Serial.println("Orientation Sensor Test"); Serial.println("");
66 2fa9c672 Tony DiCola
67 8cc46552 Kevin Townsend
  /* 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 2fa9c672 Tony DiCola
75 8cc46552 Kevin Townsend
  delay(1000);
76 2fa9c672 Tony DiCola
77 8cc46552 Kevin Townsend
  /* Display some basic information on this sensor */
78
  displaySensorDetails();
79
}
80
81
/**************************************************************************/
82
/*
83
    Arduino loop function, called once 'setup' is complete (your own code
84
    should go here)
85
*/
86
/**************************************************************************/
87 2fa9c672 Tony DiCola
void loop(void)
88 8cc46552 Kevin Townsend
{
89 2fa9c672 Tony DiCola
  /* Get a new sensor event */
90
  sensors_event_t event;
91 8cc46552 Kevin Townsend
  bno.getEvent(&event);
92 2fa9c672 Tony DiCola
93 8cc46552 Kevin Townsend
  /* Board layout:
94
         +----------+
95
         |         *| RST   PITCH  ROLL  HEADING
96 1f54374f Kevin Townsend
     ADR |*        *| SCL
97 dd57d4fa Kevin Townsend
     INT |*        *| SDA     ^            /->
98 2fa9c672 Tony DiCola
     PS1 |*        *| GND     |            |
99 dd57d4fa Kevin Townsend
     PS0 |*        *| 3VO     Y    Z-->    \-X
100 2fa9c672 Tony DiCola
         |         *| VIN
101 8cc46552 Kevin Townsend
         +----------+
102
  */
103
104
  /* The processing sketch expects data as roll, pitch, heading */
105
  Serial.print(F("Orientation: "));
106
  Serial.print((float)event.orientation.x);
107
  Serial.print(F(" "));
108
  Serial.print((float)event.orientation.y);
109
  Serial.print(F(" "));
110
  Serial.print((float)event.orientation.z);
111
  Serial.println(F(""));
112
113 2fa9c672 Tony DiCola
  /* Also send calibration data for each sensor. */
114
  uint8_t sys, gyro, accel, mag = 0;
115
  bno.getCalibration(&sys, &gyro, &accel, &mag);
116
  Serial.print(F("Calibration: "));
117
  Serial.print(sys, DEC);
118
  Serial.print(F(" "));
119
  Serial.print(gyro, DEC);
120
  Serial.print(F(" "));
121
  Serial.print(accel, DEC);
122
  Serial.print(F(" "));
123
  Serial.println(mag, DEC);
124
125 8cc46552 Kevin Townsend
  delay(BNO055_SAMPLERATE_DELAY_MS);
126 2fa9c672 Tony DiCola
}