1 /*
2 * ======== imuLoop ========
3 * This sketch simply reads the Zumo IMU sensors at 20Hz and prints
4 * the current value once per second to the UART.
5 */
7 #include <Wire.h>
9 #include "L3G.h"
10 #include "LSM303.h"
12 /* Pololu IMU data instance objects */
13 LSM303 imuCompass; /* acceleration and magnetometer */
14 L3G imuGyro; /* gyro data */
16 /*
17 * ======== imuSetup ========
18 */
19 void imuSetup()
20 {
21 Serial.begin(9600);
22 Serial.println("imuSetup ...");
23 Wire.begin();
25 /* initialize Zumo accelerometer and magnetometer */
26 imuCompass.init();
27 imuCompass.enableDefault();
29 /* initialize Zumo gyro */
30 if (!imuGyro.init()) {
31 Serial.print("Failed to autodetect gyro type!");
32 delay(1000);
33 }
34 imuGyro.enableDefault();
35 Serial.println("imuSetup done.");
36 }
38 /*
39 * ======== imuLoop ========
40 */
41 void imuLoop()
42 {
43 /* update IMU data every 50 ms (200 Hz) */
44 imuGyro.read();
45 imuCompass.read();
46 delay(50);
47 }