library of measure the sensor MPU6050 by I2C

Dependents:   1-K64F_with_5_acel

Fork of MPU6050 by Erik -

Files at this revision

API Documentation at this revision

Comitter:
vinajarr
Date:
Thu Jan 18 07:52:45 2018 +0000
Parent:
3:6d0ea7c8c5c4
Commit message:
implement interrupt

Changed in this revision

MPU6050.cpp Show annotated file Show diff for this revision Revisions of this file
MPU6050.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPU6050.cpp	Thu Dec 01 08:16:02 2016 +0000
+++ b/MPU6050.cpp	Thu Jan 18 07:52:45 2018 +0000
@@ -3,8 +3,12 @@
  */
 #include "MPU6050.h"
 
-MPU6050::MPU6050(PinName sda, PinName scl) : connection(sda, scl) {
+MPU6050::MPU6050(I2C * puntero) : connection(puntero) {
     this->setSleepMode(false);
+    write(0x19, 19);    //configure Fs Accel = 400Hz
+    write(0x1A, 0x00);  //Gyroscope Output Rate = 8kHz  Bandwidth (Hz) Acele= 260Hz
+    write(0x37, 0xE0);  //Interrupcion activa a nivel bajo , open drail, mantener interrupcion
+    write(0x38, 0x01);  //activa interrupcion  por data Redy
     
     //Initializations:
     currentGyroRange = 0;
@@ -20,19 +24,19 @@
     temp[0]=address;
     temp[1]=data;
     
-    connection.write(MPU6050_ADDRESS * 2,temp,2);
+    connection->write(MPU6050_ADDRESS * 2,temp,2);
 }
 
 char MPU6050::read(char address) {
     char retval;
-    connection.write(MPU6050_ADDRESS * 2, &address, 1, true);
-    connection.read(MPU6050_ADDRESS * 2, &retval, 1);
+    connection->write(MPU6050_ADDRESS * 2, &address, 1, true);
+    connection->read(MPU6050_ADDRESS * 2, &retval, 1);
     return retval;
 }
 
 void MPU6050::read(char address, char *data, int length) {
-    connection.write(MPU6050_ADDRESS * 2, &address, 1, true);
-    connection.read(MPU6050_ADDRESS * 2, data, length);
+    connection->write(MPU6050_ADDRESS * 2, &address, 1, true);
+    connection->read(MPU6050_ADDRESS * 2, data, length);
 }
 
 void MPU6050::setSleepMode(bool state) {
--- a/MPU6050.h	Thu Dec 01 08:16:02 2016 +0000
+++ b/MPU6050.h	Thu Jan 18 07:52:45 2018 +0000
@@ -1,4 +1,4 @@
-/*Use #define MPU6050_ES before you include this file if you have an engineering sample (older EVBs will have them), to find out if you have one, check your accelerometer output. 
+ /*Use #define MPU6050_ES before you include this file if you have an engineering sample (older EVBs will have them), to find out if you have one, check your accelerometer output. 
 If it is half of what you expected, and you still are on the correct planet, you got an engineering sample
 */
 
@@ -91,7 +91,7 @@
      * @param sda - mbed pin to use for the SDA I2C line.
      * @param scl - mbed pin to use for the SCL I2C line.
      */
-     MPU6050(PinName sda, PinName scl);
+     MPU6050(I2C * puntero);
      
 
      /**
@@ -262,7 +262,7 @@
         
      private:
 
-     I2C connection;
+     I2C *connection;
      char currentAcceleroRange;
      char currentGyroRange;