Revision fcd68623

View differences:

Adafruit_BNO055.cpp
306 306
}
307 307

  
308 308
/**************************************************************************/
309
/*
310
    Prints a float or double with the specified number of decimal places.
311

  
312
    'precision' should be 1 followed by a zero for every decimal place
313
    desired, so '100' will produce two decimal places:
314

  
315
    print_double(3.1415, 100); // Output = 3.14
316
*/
317
/**************************************************************************/
318
void Adafruit_BNO055::printDouble(double val, unsigned int precision)
319
{
320
  /* Print the integer portion */
321
  Serial.print (int(val));
322
  Serial.print(".");
323
  
324
  /* Print the fraction portion */
325
  unsigned int frac;
326
  if(val >= 0)
327
  {
328
    frac = (val - int(val)) * precision;
329
  }
330
  else
331
  {
332
    frac = (int(val)- val ) * precision;
333
  }
334
  Serial.println(frac,DEC) ;
335
}
336

  
337
/**************************************************************************/
309 338
/*!
310 339
    @brief  Provides the sensor_t data for this sensor
311 340
*/
......
334 363
/**************************************************************************/
335 364
bool Adafruit_BNO055::getEvent(sensors_event_t *event)
336 365
{
337
  float orientation;
338

  
339 366
  /* Clear the event */
340 367
  memset(event, 0, sizeof(sensors_event_t));
341 368

  
342 369
  event->version   = sizeof(sensors_event_t);
343 370
  event->sensor_id = _sensorID;
344 371
  event->type      = SENSOR_TYPE_ORIENTATION;
345
  event->timestamp = 0;
346
  /* 
347
  getPressure(&pressure_kPa);
348
  event->pressure = pressure_kPa / 100.0F;
349
  */
350
  
372
  event->timestamp = millis();
373

  
374
  /* Get a Euler angle sample for orientation */
375
  imu::Vector<3> euler = getVector(Adafruit_BNO055::VECTOR_EULER);
376
  event->orientation.x = euler.x();
377
  event->orientation.y = euler.y();
378
  event->orientation.z = euler.z();
379

  
351 380
  return true;
352 381
}
353 382

  
Adafruit_BNO055.h
246 246
    void  displayRevInfo      ( void );
247 247
    void  getSystemStatus     ( adafruit_bno055_system_status_t* );
248 248
    void  displaySystemStatus ( void );
249
    void  printDouble         ( double val, unsigned int precision );
249 250
    
250 251
    imu::Vector<3>  getVector ( adafruit_vector_type_t vector_type );
251 252
    imu::Quaternion getQuat   ( void );
examples/rawdata/rawdata.ino
1
#include <Wire.h>
2
#include <Adafruit_Sensor.h>
3
#include <Adafruit_BNO055.h>
4
#include <utility/imumaths.h>
5

  
6
/* This driver reads raw data from the BNO055
7

  
8
   Connections
9
   ===========
10
   Connect SCL to analog 5
11
   Connect SDA to analog 4
12
   Connect VDD to 3.3V DC
13
   Connect GROUND to common ground
14
    
15
   History
16
   =======
17
   2015/MAR/03  - First release (KTOWN)
18
*/
19

  
20
/* Set the delay between fresh samples */
21
#define BNO055_SAMPLERATE_DELAY_MS (500)
22
   
23
Adafruit_BNO055 bno = Adafruit_BNO055();
24

  
25
/**************************************************************************/
26
/*
27
    Arduino setup function (automatically called at startup)
28
*/
29
/**************************************************************************/
30
void setup(void) 
31
{
32
  Serial.begin(9600);
33
  Serial.println("Orientation Sensor Raw Data Test"); Serial.println("");
34
  
35
  /* Initialise the sensor */
36
  if(!bno.begin())
37
  {
38
    /* There was a problem detecting the BNO055 ... check your connections */
39
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
40
    while(1);
41
  }
42
  
43
  delay(1000);
44
    
45
  /* Display chip revision details (optional) */
46
  bno.displayRevInfo();
47
  Serial.println("");
48
}
49

  
50
/**************************************************************************/
51
/*
52
    Arduino loop function, called once 'setup' is complete (your own code
53
    should go here)
54
*/
55
/**************************************************************************/
56
void loop(void) 
57
{
58
  // Possible vector values can be:
59
  // - VECTOR_ACCELEROMETER - m/s^2
60
  // - VECTOR_MAGNETOMETER  - uT
61
  // - VECTOR_GYROSCOPE     - rad/s
62
  // - VECTOR_EULER         - degrees
63
  // - VECTOR_LINEARACCEL   - m/s^2
64
  // - VECTOR_GRAVITY       - m/s^2
65
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
66
  
67
  /* Display the floating point data */
68
  Serial.print("X: ");
69
  bno.printDouble(euler.x(), 1000);
70
  Serial.print("Y: ");
71
  bno.printDouble(euler.y(), 1000);
72
  Serial.print("Z: ");
73
  bno.printDouble(euler.z(), 1000);
74
  Serial.println("");
75

  
76
  /*
77
  // Quaternion data
78
  imu::Quaternion quat = bno.getQuat();
79
  Serial.print("qW: ");
80
  bno.printDouble(quat.w(), 1000);
81
  Serial.print("qX: ");
82
  bno.printDouble(quat.y(), 1000);
83
  Serial.print("qY: ");
84
  bno.printDouble(quat.x(), 1000);
85
  Serial.print("qZ: ");
86
  bno.printDouble(quat.z(), 1000);
87
  Serial.println("");
88
  */
89
  
90
  delay(BNO055_SAMPLERATE_DELAY_MS);
91
}
examples/sensorapi/sensorapi.ino
78 78
  displaySensorDetails();
79 79
  
80 80
  /* Display system info (optional) */
81
  bno.displaySystemStatus();
82
  Serial.println("");
81
  // bno.displaySystemStatus();
82
  // Serial.println("");
83 83
  
84 84
  /* Display chip revision details (optional) */
85
  bno.displayRevInfo();
86
  Serial.println("");
85
  // bno.displayRevInfo();
86
  // Serial.println("");
87 87
}
88 88

  
89 89
/**************************************************************************/
......
94 94
/**************************************************************************/
95 95
void loop(void) 
96 96
{
97
  // Possible vector values can be:
98
  // - VECTOR_ACCELEROMETER - m/s^2
99
  // - VECTOR_MAGNETOMETER  - uT
100
  // - VECTOR_GYROSCOPE     - rad/s
101
  // - VECTOR_EULER         - degrees
102
  // - VECTOR_LINEARACCEL   - m/s^2
103
  // - VECTOR_GRAVITY       - m/s^2
104
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
97
  /* Get a new sensor event */ 
98
  sensors_event_t event; 
99
  bno.getEvent(&event);
100
  
101
  /* Display the floating point data */
105 102
  Serial.print("X: ");
106
  Serial.println((int)euler.x(), DEC);
103
  bno.printDouble(event.orientation.x, 1000);
107 104
  Serial.print("Y: ");
108
  Serial.println((int)euler.y(), DEC);
105
  bno.printDouble(event.orientation.y, 1000);
109 106
  Serial.print("Z: ");
110
  Serial.println((int)euler.z(), DEC);
111
  Serial.println("");
112

  
113
  /*
114
  imu::Quaternion quat = bno.getQuat();
115
  Serial.print("qW: ");
116
  Serial.println((int)quat.w(), DEC);
117
  Serial.print("qX: ");
118
  Serial.println((int)quat.x(), DEC);
119
  Serial.print("qY: ");
120
  Serial.println((int)quat.y(), DEC);
121
  Serial.print("qZ: ");
122
  Serial.println((int)quat.z(), DEC);
107
  bno.printDouble(event.orientation.z, 1000);
123 108
  Serial.println("");
124
  /*
125 109
  
126 110
  delay(BNO055_SAMPLERATE_DELAY_MS);
127 111
}

Also available in: Unified diff