mirror of
https://github.com/richardghirst/PiBits.git
synced 2024-11-28 12:24:11 +01:00
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include "I2Cdev.h"
|
|
#include "MPU6050.h"
|
|
|
|
// class default I2C address is 0x68
|
|
// specific I2C addresses may be passed as a parameter here
|
|
// AD0 low = 0x68 (default for InvenSense evaluation board)
|
|
// AD0 high = 0x69
|
|
MPU6050 accelgyro;
|
|
|
|
int16_t ax, ay, az;
|
|
int16_t gx, gy, gz;
|
|
|
|
void setup() {
|
|
// initialize device
|
|
printf("Initializing I2C devices...\n");
|
|
accelgyro.initialize();
|
|
|
|
// verify connection
|
|
printf("Testing device connections...\n");
|
|
printf(accelgyro.testConnection() ? "MPU6050 connection successful\n" : "MPU6050 connection failed\n");
|
|
}
|
|
|
|
void loop() {
|
|
// read raw accel/gyro measurements from device
|
|
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
|
|
|
// these methods (and a few others) are also available
|
|
//accelgyro.getAcceleration(&ax, &ay, &az);
|
|
//accelgyro.getRotation(&gx, &gy, &gz);
|
|
|
|
// display accel/gyro x/y/z values
|
|
printf("a/g: %6hd %6hd %6hd %6hd %6hd %6hd\n",ax,ay,az,gx,gy,gz);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
setup();
|
|
for (;;)
|
|
loop();
|
|
}
|
|
|