Created
April 26, 2019 08:22
-
-
Save paxbun/4d85dc1c3feefbb8955edb48301fb12e to your computer and use it in GitHub Desktop.
MPU9250 Arduino Test Code
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
/* | |
Library: https://github.com/bolderflight/MPU9250 | |
Ports | |
MPU9250 Arduino Mega | |
VCC 3.3V | |
GND GND | |
SCL SCL | |
SDA SDA | |
*/ | |
#include <MPU9250.h> | |
#define CHECK(expr) \ | |
{ \ | |
int status = (expr); \ | |
if (status < 0) \ | |
{ \ | |
Serial.print(#expr " failed with error "); \ | |
Serial.println(status); \ | |
return; \ | |
} \ | |
} | |
MPU9250 IMU(Wire, 0x68); | |
bool initialized = false; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println("Hello, world!"); | |
CHECK(IMU.begin()); | |
initialized = true; | |
} | |
void loop() | |
{ | |
if (!initialized) | |
return; | |
CHECK(IMU.readSensor()); | |
float | |
ax = IMU.getAccelX_mss(), | |
ay = IMU.getAccelY_mss(), | |
az = IMU.getAccelZ_mss(); | |
Serial.print("x: "); | |
Serial.print(ax); | |
Serial.print("\ty: "); | |
Serial.print(ay); | |
Serial.print("\tz: "); | |
Serial.println(az); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment