SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
qmi8658_calibration_deprecated.ino
Go to the documentation of this file.
1
30#include <Arduino.h>
31#include <Wire.h>
32#include <SPI.h>
33#include "SensorQMI8658.hpp"
34#ifdef ARDUINO_T_BEAM_S3_SUPREME
35#include <XPowersAXP2101.tpp> //PMU Library https://github.com/lewisxhe/XPowersLib.git
36#endif
37
38
39// #define USE_I2C //Using the I2C interface
40
41#ifdef USE_I2C
42#ifndef SENSOR_SDA
43#define SENSOR_SDA 17
44#endif
45
46#ifndef SENSOR_SCL
47#define SENSOR_SCL 18
48#endif
49
50#else /*SPI interface*/
51
52#ifndef SPI_MOSI
53#define SPI_MOSI (35)
54#endif
55
56#ifndef SPI_SCK
57#define SPI_SCK (36)
58#endif
59
60#ifndef SPI_MISO
61#define SPI_MISO (37)
62#endif
63
64#endif /*USE_I2C*/
65
66#ifndef IMU_CS
67#define IMU_CS 34 // IMU CS PIN
68#endif
69
70#ifndef IMU_IRQ
71#define IMU_IRQ 33 // IMU INT PIN
72#endif
73
74#ifndef OLED_SDA
75#define OLED_SDA 22 // Display Wire SDA Pin
76#endif
77
78#ifndef OLED_SCL
79#define OLED_SCL 21 // Display Wire SCL Pin
80#endif
81
82
83
87
88
90{
91 // T_BEAM_S3_SUPREME The PMU voltage needs to be turned on to use the sensor
92#if defined(ARDUINO_T_BEAM_S3_SUPREME)
93 XPowersAXP2101 power;
94 power.begin(Wire1, AXP2101_SLAVE_ADDRESS, 42, 41);
95 power.disableALDO1();
96 power.disableALDO2();
97 delay(250);
98 power.setALDO1Voltage(3300); power.enableALDO1();
99 power.setALDO2Voltage(3300); power.enableALDO2();
100#endif
101}
102
103void setup()
104{
105 Serial.begin(115200);
106
107 while (!Serial);
108
109 delay(3000);
110
111 beginPower();
112
113
114 bool ret = false;
115#ifdef USE_I2C
116 ret = qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL);
117#else
118#if defined(SPI_MOSI) && defined(SPI_SCK) && defined(SPI_MISO)
119 ret = qmi.begin(SPI, IMU_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
120#else
121 ret = qmi.begin(SPI, IMU_CS);
122#endif
123#endif
124
125 if (!ret) {
126 Serial.println("Failed to find QMI8658 - check your wiring!");
127 while (1) {
128 delay(1000);
129 }
130 }
131
132 /* Get chip id*/
133 Serial.print("Device ID:");
134 Serial.println(qmi.getChipID(), HEX);
135
136 uint16_t gX_gain = 0, gY_gain = 0, gZ_gain = 0;
137
138 // Call internal calibration to calibrate the sensor
139 ret = false;
140
141 while (!ret) {
142
143 // Calibrate only once, do not obtain calibration value
144 // result = qmi.calibration();
145
146 // Get the calibration value after calibration
147 ret = qmi.calibration(&gX_gain, &gY_gain, &gZ_gain);
148 if (ret) {
149 Serial.println("All calibrations are completed");
150 break;
151 }
152 int i = 5;
153 while (i--) {
154 Serial.print("Calibration failed, please leave the sensor alone and keep quiet! , Will try again in ");
155 Serial.print(i);
156 Serial.println(" seconds");
157 }
158 }
159
160
161 // Save the calibration data to EEPROM or flash, and then write the calibration value directly to the next run
162 // Here only print
163 Serial.print("Calibration data ->");
164 Serial.print("Gyro-X gain : "); Serial.println(gX_gain);
165 Serial.print("Gyro-Y gain : "); Serial.println(gY_gain);
166 Serial.print("Gyro-Z gain : "); Serial.println(gZ_gain);
167
168 // The example only provides a method for writing calibration values
169 ret = qmi.writeCalibration(gX_gain, gY_gain, gZ_gain);
170 if (ret) {
171 Serial.println("Write calibrations successfully");
172 } else {
173 Serial.println("Write calibrations failed!");
174 }
175
176
178 /*
179 * ACC_RANGE_2G
180 * ACC_RANGE_4G
181 * ACC_RANGE_8G
182 * ACC_RANGE_16G
183 * */
185 /*
186 * ACC_ODR_1000H
187 * ACC_ODR_500Hz
188 * ACC_ODR_250Hz
189 * ACC_ODR_125Hz
190 * ACC_ODR_62_5Hz
191 * ACC_ODR_31_25Hz
192 * ACC_ODR_LOWPOWER_128Hz
193 * ACC_ODR_LOWPOWER_21Hz
194 * ACC_ODR_LOWPOWER_11Hz
195 * ACC_ODR_LOWPOWER_3H
196 * */
198 /*
199 * LPF_MODE_0 //2.66% of ODR
200 * LPF_MODE_1 //3.63% of ODR
201 * LPF_MODE_2 //5.39% of ODR
202 * LPF_MODE_3 //13.37% of ODR
203 * LPF_OFF // OFF Low-Pass Fitter
204 * */
206
207
208
209
211 /*
212 * GYR_RANGE_16DPS
213 * GYR_RANGE_32DPS
214 * GYR_RANGE_64DPS
215 * GYR_RANGE_128DPS
216 * GYR_RANGE_256DPS
217 * GYR_RANGE_512DPS
218 * GYR_RANGE_1024DPS
219 * */
221 /*
222 * GYR_ODR_7174_4Hz
223 * GYR_ODR_3587_2Hz
224 * GYR_ODR_1793_6Hz
225 * GYR_ODR_896_8Hz
226 * GYR_ODR_448_4Hz
227 * GYR_ODR_224_2Hz
228 * GYR_ODR_112_1Hz
229 * GYR_ODR_56_05Hz
230 * GYR_ODR_28_025H
231 * */
233 /*
234 * LPF_MODE_0 //2.66% of ODR
235 * LPF_MODE_1 //3.63% of ODR
236 * LPF_MODE_2 //5.39% of ODR
237 * LPF_MODE_3 //13.37% of ODR
238 * LPF_OFF // OFF Low-Pass Fitter
239 * */
241
242 /*
243 * If both the accelerometer and gyroscope sensors are turned on at the same time,
244 * the output frequency will be based on the gyroscope output frequency.
245 * The example configuration is 896.8HZ output frequency,
246 * so the acceleration output frequency is also limited to 896.8HZ
247 * */
250
251 // Print register configuration information
253
254 Serial.println("Read data now...");
255}
256
257
258void loop()
259{
260 if (qmi.getDataReady()) {
261 if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) {
262 Serial.print("ACCEL.x:");
263 Serial.print(acc.x);
264 Serial.print(",ACCEL.y:");
265 Serial.print(acc.y);
266 Serial.print(",ACCEL.z:");
267 Serial.print(acc.z);
268 Serial.println("");
269 }
270 if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) {
271 Serial.print("GYRO.x:");
272 Serial.print(gyr.x);
273 Serial.print(",GYRO.y:");
274 Serial.print(gyr.y);
275 Serial.print(",GYRO.z:");
276 Serial.print(gyr.z);
277 Serial.println("");
278 }
279 }
280 delay(100);
281}
282
283
284
#define SENSOR_SCL
#define SENSOR_SDA
bool begin(CommInterface interface, SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr=0)
Initialize the sensor using custom callback interface.
QMI8658 IMU sensor driver class.
bool getGyroscope(float &x, float &y, float &z)
Get the raw gyroscope data.
void dumpCtrlRegister()
Dump the control register values.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
bool configAccelerometer(AccelRange range, AccelODR odr, LpfMode lpfOdr=LPF_MODE_0)
Configure the accelerometer.
bool configGyroscope(GyroRange range, GyroODR odr, LpfMode lpfOdr=LPF_MODE_0)
Configure the gyroscope.
bool enableGyroscope()
Enable the gyroscope.
bool enableAccelerometer()
Enable the accelerometer.
bool getDataReady()
Check if new data is available.
bool writeCalibration(uint16_t gyro_x_gain, uint16_t gyro_y_gain, uint16_t gyro_z_gain)
Write previously saved gyro calibration gains.
bool calibration(uint16_t *gX_gain=NULL, uint16_t *gY_gain=NULL, uint16_t *gZ_gain=NULL)
Set Gyroscope calibration gains.
bool getAccelerometer(float &x, float &y, float &z)
Get the accelerometer data.
uint8_t i
SensorQMI8658 qmi