adafruit_bno055 / examples / read_all_data / read_all_data.ino @ 5e9f001d
History | View | Annotate | Download (3.003 KB)
1 | 7faf77c3 | Jan Hoffmann | #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 | e5a77cdb | Gintaras | // 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 | 7faf77c3 | Jan Hoffmann | |
37 | void setup(void) |
||
38 | { |
||
39 | Serial.begin(115200); |
||
40 | Serial.println("Orientation Sensor Test"); Serial.println(""); |
||
41 | |||
42 | /* Initialise the sensor */ |
||
43 | if (!bno.begin()) |
||
44 | { |
||
45 | /* There was a problem detecting the BNO055 ... check your connections */ |
||
46 | Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); |
||
47 | while (1); |
||
48 | } |
||
49 | |||
50 | delay(1000); |
||
51 | } |
||
52 | |||
53 | void loop(void) |
||
54 | { |
||
55 | //could add VECTOR_ACCELEROMETER, VECTOR_MAGNETOMETER,VECTOR_GRAVITY... |
||
56 | sensors_event_t orientationData , angVelocityData , linearAccelData; |
||
57 | bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER); |
||
58 | bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE); |
||
59 | bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL); |
||
60 | |||
61 | printEvent(&orientationData); |
||
62 | printEvent(&angVelocityData); |
||
63 | printEvent(&linearAccelData); |
||
64 | |||
65 | int8_t boardTemp = bno.getTemp(); |
||
66 | Serial.print(F("temperature: ")); |
||
67 | Serial.println(boardTemp); |
||
68 | |||
69 | |||
70 | delay(BNO055_SAMPLERATE_DELAY_MS); |
||
71 | } |
||
72 | |||
73 | void printEvent(sensors_event_t* event) { |
||
74 | Serial.println(); |
||
75 | Serial.print(event->type); |
||
76 | double x = -1000000, y = -1000000 , z = -1000000; //dumb values, easy to spot problem |
||
77 | if (event->type == SENSOR_TYPE_ACCELEROMETER) { |
||
78 | x = event->acceleration.x; |
||
79 | y = event->acceleration.y; |
||
80 | z = event->acceleration.z; |
||
81 | } |
||
82 | else if (event->type == SENSOR_TYPE_ORIENTATION) { |
||
83 | x = event->orientation.x; |
||
84 | y = event->orientation.y; |
||
85 | z = event->orientation.z; |
||
86 | } |
||
87 | else if (event->type == SENSOR_TYPE_MAGNETIC_FIELD) { |
||
88 | x = event->magnetic.x; |
||
89 | y = event->magnetic.y; |
||
90 | z = event->magnetic.z; |
||
91 | } |
||
92 | else if ((event->type == SENSOR_TYPE_GYROSCOPE) || (event->type == SENSOR_TYPE_ROTATION_VECTOR)) { |
||
93 | x = event->gyro.x; |
||
94 | y = event->gyro.y; |
||
95 | z = event->gyro.z; |
||
96 | } |
||
97 | |||
98 | Serial.print(": x= "); |
||
99 | Serial.print(x); |
||
100 | Serial.print(" | y= "); |
||
101 | Serial.print(y); |
||
102 | Serial.print(" | z= "); |
||
103 | Serial.println(z); |
||
104 | } |
||
105 |