-
Notifications
You must be signed in to change notification settings - Fork 1
/
ITG3200.h
167 lines (129 loc) · 4.44 KB
/
ITG3200.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
-------------------------------------------------------------------------------
ITG3200.h
ITG3200 Project
CLASS NAME:
ITG3200
DESCRIPTION:
This class is used to interface the Arduino with the ITG3200 digital
gyro sensor.
FILES:
ITG3200.h
ITG3200.cpp
DEPENDENCIES:
Arduino.h
Wire.h
CONSTRUCTORS:
ITG3200();
METHODS:
void initialize();
Initializes the device. Must be done before device can be used.
Note: A 4 second (20 sample) calibration is done with this
function.
int x();
Get x-axis output value.
int y();
Get x-axis output value.
int z();
Get x-axis output value.
void calibrate(int nSamples);
Calibrate the device using a certain number of nSamples. Each
sample takes 0.2 seconds for calibration. The device should remain
completely motionless during calibration.
nSamples - Number of nSamples to use.
int calX();
Get x-axis calibration value.
int calY();
Get y-axis calibration value.
int calZ();
Get z-axis calibration value.
NOTES:
EXAMPLES:
Example 1: Initializing sensor and printing x, y, and z values.
----------------------------------------------------------------------------
#include <Arduino.h>
#include <ITG3200.h>
ITG3200 itg;
void setup() {
Serial.begin(9600);
itg.initialize();
Serial.println(itg.x());
Serial.println(itg.y());
Serial.println(itg.z());
}
----------------------------------------------------------------------------
VERSIONS:
1.0 - 1/12/12 - Rowland O'Flaherty (rowlandoflaherty.com)
-------------------------------------------------------------------------------
*/
#ifndef _ITG3200_h_
#define _ITG3200_h_
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <Arduino.h>
class ITG3200 {
public:
//--------------------------------------------------------------------------
// Constants, Enums, and Types
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Lifecycle
//--------------------------------------------------------------------------
// Constructors
ITG3200();
// Destructor
virtual ~ITG3200();
// Copy constructor
ITG3200(const ITG3200& srcObj);
//--------------------------------------------------------------------------
// Overloaded Operators
//--------------------------------------------------------------------------
// Assignment operator
const ITG3200& operator=(const ITG3200& rhsObj);
//--------------------------------------------------------------------------
// Public Member Functions
//--------------------------------------------------------------------------
void initialize();
int x();
int y();
int z();
void calibrate(int nSamples);
int calX() { return _calX;}
int calY() { return _calY;}
int calZ() { return _calZ;}
private:
//--------------------------------------------------------------------------
// Lifecycle
//--------------------------------------------------------------------------
void copyHelper(const ITG3200& srcObj);
//--------------------------------------------------------------------------
// Private Member Functions
//--------------------------------------------------------------------------
byte readByte(byte address);
void writeByte(byte address, byte value);
//--------------------------------------------------------------------------
// Private Member Variables
//--------------------------------------------------------------------------
// Device constant
static const byte _ITG3200Address = 0x69; // I2C address of ITG3200
// Register address
static const char _SMPLRTDIV= 0x15;
static const char _DLPF = 0x16;
static const char _xH = 0x1D;
static const char _xL = 0x1E;
static const char _yH = 0x1F;
static const char _yL = 0x20;
static const char _zH = 0x21;
static const char _zL = 0x22;
static const char _DLPF0 = (0<<0);
static const char _DLPF1 = (1<<1);
static const char _DLPF2 = (0<<2);
static const char _FS0 = (1<<3);
static const char _FS1 = (1<<4);
// Calibration variables
int _calX;
int _calY;
int _calZ;
};
#endif