adafruit_bno055 / examples / sensorapi / sensorapi.ino @ 8ac2d6f6
History | View | Annotate | Download (4.171 KB)
1 | 4bc1c0c1 | 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 | 8ac2d6f6 | Kevin Townsend | |
9 | 4bc1c0c1 | 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 | 8ac2d6f6 | Kevin Townsend | |
18 | 4bc1c0c1 | Kevin Townsend | Connections |
19 | =========== |
||
20 | Connect SCL to analog 5 |
||
21 | Connect SDA to analog 4 |
||
22 | c4f272e1 | ladyada | Connect VDD to 3-5V DC |
23 | 4bc1c0c1 | Kevin Townsend | Connect GROUND to common ground |
24 | 8ac2d6f6 | Kevin Townsend | |
25 | 4bc1c0c1 | Kevin Townsend | History |
26 | ======= |
||
27 | 2015/MAR/03 - First release (KTOWN) |
||
28 | */ |
||
29 | |||
30 | /* Set the delay between fresh samples */ |
||
31 | c4f272e1 | ladyada | #define BNO055_SAMPLERATE_DELAY_MS (100) |
32 | 8ac2d6f6 | Kevin Townsend | |
33 | 4bc1c0c1 | Kevin Townsend | 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 | 8ac2d6f6 | Kevin Townsend | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" xxx"); |
52 | 4bc1c0c1 | Kevin Townsend | Serial.println("------------------------------------"); |
53 | Serial.println(""); |
||
54 | delay(500); |
||
55 | } |
||
56 | |||
57 | /**************************************************************************/ |
||
58 | /* |
||
59 | 8ac2d6f6 | Kevin Townsend | Display some basic info about the sensor status |
60 | */ |
||
61 | /**************************************************************************/ |
||
62 | void displaySensorStatus(void) |
||
63 | { |
||
64 | /* Get the system status values (mostly for debugging purposes) */ |
||
65 | uint8_t system_status, self_test_results, system_error; |
||
66 | system_status = self_test_results = system_error = 0; |
||
67 | bno.getSystemStatus(&system_status, &self_test_results, &system_error); |
||
68 | |||
69 | /* Display the results in the Serial Monitor */ |
||
70 | Serial.print("System Status: 0x"); |
||
71 | Serial.println(system_status, HEX); |
||
72 | Serial.print("Self Test: 0x"); |
||
73 | Serial.println(self_test_results, HEX); |
||
74 | Serial.print("System Error: 0x"); |
||
75 | Serial.println(system_error, HEX); |
||
76 | Serial.println(""); |
||
77 | delay(500); |
||
78 | } |
||
79 | |||
80 | /**************************************************************************/ |
||
81 | /* |
||
82 | 4bc1c0c1 | Kevin Townsend | Arduino setup function (automatically called at startup) |
83 | */ |
||
84 | /**************************************************************************/ |
||
85 | 8ac2d6f6 | Kevin Townsend | void setup(void) |
86 | 4bc1c0c1 | Kevin Townsend | { |
87 | Serial.begin(9600); |
||
88 | Serial.println("Orientation Sensor Test"); Serial.println(""); |
||
89 | 8ac2d6f6 | Kevin Townsend | |
90 | 4bc1c0c1 | Kevin Townsend | /* Initialise the sensor */ |
91 | if(!bno.begin()) |
||
92 | { |
||
93 | /* There was a problem detecting the BNO055 ... check your connections */ |
||
94 | Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); |
||
95 | while(1); |
||
96 | } |
||
97 | 8ac2d6f6 | Kevin Townsend | |
98 | 4bc1c0c1 | Kevin Townsend | delay(1000); |
99 | 8ac2d6f6 | Kevin Townsend | |
100 | 4bc1c0c1 | Kevin Townsend | /* Display some basic information on this sensor */ |
101 | displaySensorDetails(); |
||
102 | 67f3cff5 | Kevin Townsend | |
103 | 8ac2d6f6 | Kevin Townsend | /* Optional: Display current status */ |
104 | // displaySensorStatus(); |
||
105 | |||
106 | c4f272e1 | ladyada | bno.setExtCrystalUse(true); |
107 | 4bc1c0c1 | Kevin Townsend | } |
108 | |||
109 | /**************************************************************************/ |
||
110 | /* |
||
111 | Arduino loop function, called once 'setup' is complete (your own code |
||
112 | should go here) |
||
113 | */ |
||
114 | /**************************************************************************/ |
||
115 | 8ac2d6f6 | Kevin Townsend | void loop(void) |
116 | 4bc1c0c1 | Kevin Townsend | { |
117 | 8ac2d6f6 | Kevin Townsend | /* Get a new sensor event */ |
118 | sensors_event_t event; |
||
119 | fcd68623 | Kevin Townsend | bno.getEvent(&event); |
120 | 8ac2d6f6 | Kevin Townsend | |
121 | fcd68623 | Kevin Townsend | /* Display the floating point data */ |
122 | 4bc1c0c1 | Kevin Townsend | Serial.print("X: "); |
123 | c4f272e1 | ladyada | Serial.print(event.orientation.x, 4); |
124 | Serial.print("\tY: "); |
||
125 | Serial.print(event.orientation.y, 4); |
||
126 | Serial.print("\tZ: "); |
||
127 | Serial.print(event.orientation.z, 4); |
||
128 | 48741e1f | Kevin Townsend | Serial.println(""); |
129 | 8ac2d6f6 | Kevin Townsend | |
130 | 4bc1c0c1 | Kevin Townsend | delay(BNO055_SAMPLERATE_DELAY_MS); |
131 | 48741e1f | Kevin Townsend | } |