1+ #include < LSM6DS3.h>
2+ #include < Wire.h>
3+
4+ // Create a instance of class LSM6DS3
5+ LSM6DS3 myIMU (I2C_MODE, 0x6A ); // I2C device address 0x6A
6+
7+ void setup ( void ) {
8+ // Over-ride default settings if desired
9+ myIMU.settings .gyroEnabled = 1 ; // Can be 0 or 1
10+ myIMU.settings .gyroRange = 2000 ; // Max deg/s. Can be: 125, 245, 500, 1000, 2000
11+ myIMU.settings .gyroSampleRate = 833 ; // Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
12+ myIMU.settings .gyroBandWidth = 200 ; // Hz. Can be: 50, 100, 200, 400;
13+ myIMU.settings .gyroFifoEnabled = 1 ; // Set to include gyro in FIFO
14+ myIMU.settings .gyroFifoDecimation = 1 ; // set 1 for on /1
15+
16+ myIMU.settings .accelEnabled = 1 ;
17+ myIMU.settings .accelRange = 16 ; // Max G force readable. Can be: 2, 4, 8, 16
18+ myIMU.settings .accelSampleRate = 833 ; // Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
19+ myIMU.settings .accelBandWidth = 200 ; // Hz. Can be: 50, 100, 200, 400;
20+ myIMU.settings .accelFifoEnabled = 1 ; // Set to include accelerometer in the FIFO
21+ myIMU.settings .accelFifoDecimation = 1 ; // set 1 for on /1
22+ myIMU.settings .tempEnabled = 1 ;
23+
24+ // Non-basic mode settings
25+ myIMU.settings .commMode = 1 ;
26+
27+ myIMU.settings .timestampEnabled =1 ; // 1: enable timestamp ; 0: disable timestamp
28+ myIMU.settings .timestampFifoEnabled =1 ;// 1: enable write timestamp into fifo ; 0: disable
29+ myIMU.settings .timestampResolution =1 ; // 1: Set timestamp resolution ; 0: 6.4ms 1: 25us
30+
31+ // FIFO control settings
32+ myIMU.settings .fifoThreshold = 100 ; // Can be 0 to 4096 (16 bit bytes)
33+ myIMU.settings .fifoSampleRate = 50 ; // Hz. Can be: 10, 25, 50, 100, 200, 400, 800, 1600, 3300, 6600
34+ myIMU.settings .fifoModeWord = 6 ; // FIFO mode.
35+ // FIFO mode. Can be:
36+ // 0 (Bypass mode, FIFO off)
37+ // 1 (Stop when full)
38+ // 3 (Continuous during trigger)
39+ // 4 (Bypass until trigger)
40+ // 6 (Continous mode)
41+
42+
43+ Serial.begin (57600 ); // start serial for output
44+ delay (1000 ); // relax...
45+ Serial.println (" Processor came out of reset.\n " );
46+
47+ // Call .begin() to configure the IMUs
48+ if ( myIMU.begin () != 0 )
49+ {
50+ Serial.println (" Problem starting the sensor with CS @ Pin 10." );
51+ }
52+ else
53+ {
54+ Serial.println (" Sensor with CS @ Pin 10 started." );
55+ }
56+
57+ Serial.print (" Configuring FIFO with no error checking..." );
58+ myIMU.fifoBegin ();
59+ Serial.print (" Done!\n " );
60+
61+ Serial.print (" Clearing out the FIFO..." );
62+ myIMU.fifoClear ();
63+ Serial.print (" Done!\n " );
64+
65+ }
66+
67+
68+ void loop ()
69+ {
70+ float temp; // This is to hold read data
71+ uint16_t tempUnsigned;
72+
73+ while ( ( myIMU.fifoGetStatus () & 0x8000 ) == 0 ) {}; // Wait for watermark
74+
75+ // Now loop until FIFO is empty. NOTE: As the FIFO is only 8 bits wide,
76+ // the channels must be synchronized to a known position for the data to align
77+ // properly. Emptying the fifo is one way of doing this (this example)
78+ while ( ( myIMU.fifoGetStatus () & 0x1000 ) == 0 ) {
79+
80+ temp = myIMU.calcGyro (myIMU.fifoRead ());
81+ Serial.print (temp);
82+ Serial.print (" ," );
83+
84+ temp = myIMU.calcGyro (myIMU.fifoRead ());
85+ Serial.print (temp);
86+ Serial.print (" ," );
87+
88+ temp = myIMU.calcGyro (myIMU.fifoRead ());
89+ Serial.print (temp);
90+ Serial.print (" ," );
91+
92+ temp = myIMU.calcAccel (myIMU.fifoRead ());
93+ Serial.print (temp);
94+ Serial.print (" ," );
95+
96+ temp = myIMU.calcAccel (myIMU.fifoRead ());
97+ Serial.print (temp);
98+ Serial.print (" ," );
99+
100+ temp = myIMU.calcAccel (myIMU.fifoRead ());
101+ Serial.print (temp);
102+
103+ // The third dataset corresponds to external sensor data.
104+ // You need to read the third dataset first before you can read the timestamp data.
105+ // Therefore, you can ignore this dataset.
106+ uint16_t thirdData = myIMU.fifoTimestamp ();
107+
108+ // The third dataset
109+ // timestamp in fifo
110+ uint32_t fifoTimestamp = myIMU.fifoTimestamp ();
111+ Serial.print (" ," );
112+ Serial.print (" FIFO time: " );
113+ Serial.print (fifoTimestamp);
114+ Serial.print (" \n " );
115+
116+ delay (10 ); // Wait for the serial buffer to clear (~50 bytes worth of time @ 57600baud)
117+
118+ }
119+
120+ tempUnsigned = myIMU.fifoGetStatus ();
121+ Serial.print (" \n Fifo Status 1 and 2 (16 bits): 0x" );
122+ Serial.println (tempUnsigned, HEX);
123+ Serial.print (" \n " );
124+
125+ }
0 commit comments