-
-
Save anonymous/a50f608c807a8c86fd786420ee19b916 to your computer and use it in GitHub Desktop.
MPU9250.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MPU9250.h" | |
// an MPU9250 object with the MPU-9250 sensor on Teensy Chip Select pin 10 | |
MPU9250 IMU(10); | |
float ax, ay, az, gx, gy, gz, hx, hy, hz, t; | |
int beginStatus, setFiltStatus; | |
volatile int i = 0; | |
void setup() { | |
// serial to display data | |
Serial.begin(115200); | |
delay(1000); | |
Serial.println("Starting..."); | |
// start communication with IMU and | |
// set the accelerometer and gyro ranges. | |
// ACCELEROMETER 2G 4G 8G 16G | |
// GYRO 250DPS 500DPS 1000DPS 2000DPS | |
beginStatus = IMU.begin(ACCEL_RANGE_4G,GYRO_RANGE_250DPS); | |
if(beginStatus < 0) { | |
delay(1000); | |
Serial.println("IMU initialization unsuccessful"); | |
Serial.println("Check IMU wiring or try cycling power"); | |
while(1) | |
{ | |
Serial.print("Failure: "); | |
Serial.println(beginStatus); | |
}; | |
} | |
// set up the IMU DLPF, data output rate, | |
// and interrupt. DLPF set to 41 Hz, | |
// data output rate set to 100 Hz, and | |
// MPU-9250 generated interrupt attached | |
// to Teensy pin 2 | |
setFiltStatus = IMU.setFilt(DLPF_BANDWIDTH_41HZ,9); | |
if(setFiltStatus < 0) { | |
delay(1000); | |
Serial.println("Filter initialization unsuccessful"); | |
while(1) | |
{ | |
Serial.println("Failure2!"); | |
}; | |
} | |
pinMode(2,INPUT); | |
attachInterrupt(2,getIMU,RISING); | |
} | |
void loop() | |
{ | |
Serial.println("Hi!"); | |
} | |
void getIMU(){ | |
// get the accel (m/s/s), gyro (rad/s), and magnetometer (uT), and temperature (C) data | |
IMU.getMotion10(&ax, &ay, &az, &gx, &gy, &gz, &hx, &hy, &hz, &t); | |
i++; | |
// print the results every 10 frames | |
if(i > 9){ | |
printData(); | |
i = 0; | |
} | |
} | |
void printData(){ | |
// print the data | |
Serial.print(ax,6); | |
Serial.print("\t"); | |
Serial.print(ay,6); | |
Serial.print("\t"); | |
Serial.print(az,6); | |
Serial.print("\t"); | |
Serial.print(gx,6); | |
Serial.print("\t"); | |
Serial.print(gy,6); | |
Serial.print("\t"); | |
Serial.print(gz,6); | |
Serial.print("\t"); | |
Serial.print(hx,6); | |
Serial.print("\t"); | |
Serial.print(hy,6); | |
Serial.print("\t"); | |
Serial.print(hz,6); | |
Serial.print("\t"); | |
Serial.println(t,6); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment