-
Notifications
You must be signed in to change notification settings - Fork 12
/
InertialSensors.ino
67 lines (56 loc) · 1.72 KB
/
InertialSensors.ino
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
// This example reads the raw values from the LSM6DS33
// accelerometer and gyro and prints those raw values to the
// serial monitor.
//
// The accelerometer readings can be converted to units of g
// using the conversion factors specified in the "Mechanical
// characteristics" table in the LSM6DS33 datasheet. We use a
// full scale (FS) setting of +/- 16 g, so the conversion factor
// is 0.488 mg/LSB (least-significant bit). A raw reading of
// 2048 would correspond to 1 g.
//
// The gyro readings can be converted to degrees per second (dps)
// using the "Mechanical characteristics" table in the LSM6DS33
// datasheet. We use a full scale (FS) of +/- 1000 dps so the
// conversion factor is 35 mdps/LSB. A raw reading of 2571
// would correspond to 90 dps.
//
// To run this sketch, you will need to install the LSM6 library:
//
// https://github.com/pololu/lsm6-arduino
#include <Wire.h>
#include <Romi32U4.h>
#include <LSM6.h>
LSM6 imu;
char report[120];
void setup()
{
Wire.begin();
if (!imu.init())
{
// Failed to detect the LSM6.
ledRed(1);
while(1)
{
Serial.println(F("Failed to detect the LSM6."));
delay(100);
}
}
imu.enableDefault();
// Set the gyro full scale to 1000 dps because the default
// value is too low, and leave the other settings the same.
imu.writeReg(LSM6::CTRL2_G, 0b10001000);
// Set the accelerometer full scale to 16 g because the default
// value is too low, and leave the other settings the same.
imu.writeReg(LSM6::CTRL1_XL, 0b10000100);
}
void loop()
{
imu.read();
snprintf_P(report, sizeof(report),
PSTR("A: %6d %6d %6d G: %6d %6d %6d"),
imu.a.x, imu.a.y, imu.a.z,
imu.g.x, imu.g.y, imu.g.z);
Serial.println(report);
delay(100);
}