AAAAAAAAAAAAAA

Dependents:   measure_1_AAAA

Embed: (wiki syntax)

« Back to documentation index

MPU6050 Class Reference

MPU6050 Class Reference

API for MPC6050. More...

#include <MPU6050.h>

Public Member Functions

 MPU6050 (PinName sda, PinName scl, int address)
 Create a MPU6050 Instance.
void start (void)
 Init MCP6050.
char getID (void)
 Get WHO_AM_I.
bool read (float *gx, float *gy, float *gz, float *ax, float *ay, float *az)
 Get data in float.
bool readraw (int *gx, int *gy, int *gz, int *ax, int *ay, int *az)
 Get data in int.

Detailed Description

API for MPC6050.

MCP6050 is a 6-axis I2C sensor

 #include "mbed.h"
 #include "MPU6050.h"

 MPU6050 mpu(D7,D8);

 float gx,gy,gz,ax,ay,az;

 int main()
 {
     if(mpu.getID()==0x68) {
         printf("MPU6050 OK");
         wait(1);
     } else {
         printf("MPU6050 error ID=0x%x\r\n",mpu.getID());
         while(1) {
         }
     }
     mpu.start();
     while(1) {
         mpu.read(&gx,&gy,&gz,&ax,&ay,&az);
         printf("gx,gy,gz,ax,ay,az %.1f,%.1f,%.1f,%.2f,%.2f,%.2f\r\n",gx,gy,gz,ax,ay,az);
         wait(0.1);
     }
 }
* 

Definition at line 149 of file MPU6050.h.


Constructor & Destructor Documentation

MPU6050 ( PinName  sda,
PinName  scl,
int  address 
)

Create a MPU6050 Instance.

Parameters:
sdaSDA pin name of I2C
sclSCL pin name of I2C

Definition at line 8 of file MPU6050.cpp.


Member Function Documentation

char getID ( void   )

Get WHO_AM_I.

return 0x68

Definition at line 24 of file MPU6050.cpp.

bool read ( float *  gx,
float *  gy,
float *  gz,
float *  ax,
float *  ay,
float *  az 
)

Get data in float.

The unit is G or deg/s

Definition at line 31 of file MPU6050.cpp.

bool readraw ( int *  gx,
int *  gy,
int *  gz,
int *  ax,
int *  ay,
int *  az 
)

Get data in int.

return as 16bit value

Definition at line 48 of file MPU6050.cpp.

void start ( void   )

Init MCP6050.

Disable sleep mode Set gyro range as +- 1000 deg/s Set accel range as +- 4G Set sample rate as 470 Hz

Definition at line 15 of file MPU6050.cpp.