1 | /****************************************************************************
|
---|
2 | * Copyright (C) 2011 - 2014 Bosch Sensortec GmbH
|
---|
3 | *
|
---|
4 | * Euler.ino
|
---|
5 | * Date: 2014/09/09
|
---|
6 | * Revision: 3.0 $
|
---|
7 | *
|
---|
8 | * Usage: Example code to stream Euler data
|
---|
9 | *
|
---|
10 | ****************************************************************************
|
---|
11 | /***************************************************************************
|
---|
12 | * License:
|
---|
13 | *
|
---|
14 | * Redistribution and use in source and binary forms, with or without
|
---|
15 | * modification, are permitted provided that the following conditions are met:
|
---|
16 | *
|
---|
17 | * Redistributions of source code must retain the above copyright
|
---|
18 | * notice, this list of conditions and the following disclaimer.
|
---|
19 | *
|
---|
20 | * Redistributions in binary form must reproduce the above copyright
|
---|
21 | * notice, this list of conditions and the following disclaimer in the
|
---|
22 | * documentation and/or other materials provided with the distribution.
|
---|
23 | *
|
---|
24 | * Neither the name of the copyright holder nor the names of the
|
---|
25 | * contributors may be used to endorse or promote products derived from
|
---|
26 | * this software without specific prior written permission.
|
---|
27 | *
|
---|
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
30 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
31 | * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
---|
32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
33 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
37 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
---|
38 | *
|
---|
39 | * The information provided is believed to be accurate and reliable.
|
---|
40 | * The copyright holder assumes no responsibility for the consequences of use
|
---|
41 | * of such information nor for any infringement of patents or
|
---|
42 | * other rights of third parties which may result from its use.
|
---|
43 | * No license is granted by implication or otherwise under any patent or
|
---|
44 | * patent rights of the copyright holder.
|
---|
45 | */
|
---|
46 |
|
---|
47 | #include "NAxisMotion.h" //Contains the bridge code between the API and the Arduino Environment
|
---|
48 | #include <Wire.h>
|
---|
49 |
|
---|
50 | NAxisMotion mySensor; //Object that for the sensor
|
---|
51 | unsigned long lastStreamTime = 0; //To store the last streamed time stamp
|
---|
52 | const int streamPeriod = 20; //To stream at 50Hz without using additional timers (time period(ms) =1000/frequency(Hz))
|
---|
53 |
|
---|
54 | void setup() //This code is executed once
|
---|
55 | {
|
---|
56 | //Peripheral Initialization
|
---|
57 | Serial.begin(115200); //Initialize the Serial Port to view information on the Serial Monitor
|
---|
58 | I2C.begin(); //Initialize I2C communication to the let the library communicate with the sensor.
|
---|
59 | //Sensor Initialization
|
---|
60 | mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library
|
---|
61 | mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired
|
---|
62 | mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions
|
---|
63 | //Setting to MANUAL requires fewer reads to the sensor
|
---|
64 | }
|
---|
65 |
|
---|
66 | void loop() //This code is looped forever
|
---|
67 | {
|
---|
68 | if ((millis() - lastStreamTime) >= streamPeriod)
|
---|
69 | {
|
---|
70 | lastStreamTime = millis();
|
---|
71 | mySensor.updateEuler(); //Update the Euler data into the structure of the object
|
---|
72 | mySensor.updateCalibStatus(); //Update the Calibration Status
|
---|
73 |
|
---|
74 | Serial.print("Time: ");
|
---|
75 | Serial.print(lastStreamTime);
|
---|
76 | Serial.print("ms ");
|
---|
77 |
|
---|
78 | Serial.print(" H: ");
|
---|
79 | Serial.print(mySensor.readEulerHeading()); //Heading data
|
---|
80 | Serial.print("deg ");
|
---|
81 |
|
---|
82 | Serial.print(" R: ");
|
---|
83 | Serial.print(mySensor.readEulerRoll()); //Roll data
|
---|
84 | Serial.print("deg");
|
---|
85 |
|
---|
86 | Serial.print(" P: ");
|
---|
87 | Serial.print(mySensor.readEulerPitch()); //Pitch data
|
---|
88 | Serial.print("deg ");
|
---|
89 |
|
---|
90 | Serial.print(" A: ");
|
---|
91 | Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3)
|
---|
92 |
|
---|
93 | Serial.print(" M: ");
|
---|
94 | Serial.print(mySensor.readMagCalibStatus()); //Magnetometer Calibration Status (0 - 3)
|
---|
95 |
|
---|
96 | Serial.print(" G: ");
|
---|
97 | Serial.print(mySensor.readGyroCalibStatus()); //Gyroscope Calibration Status (0 - 3)
|
---|
98 |
|
---|
99 | Serial.print(" S: ");
|
---|
100 | Serial.print(mySensor.readSystemCalibStatus()); //System Calibration Status (0 - 3)
|
---|
101 |
|
---|
102 | Serial.println();
|
---|
103 | }
|
---|
104 | }
|
---|