Slightly modified version (to work with processing GUI)

Dependencies:   ITG3200 mbed

Fork of 6DoF_IMU_readvalue by Ryo Nakabayashi

Files at this revision

API Documentation at this revision

Comitter:
Vigneshwar
Date:
Wed Feb 05 22:12:32 2014 +0000
Parent:
4:c7d5863b2576
Commit message:
adsf

Changed in this revision

ADXL345_I2C.cpp Show annotated file Show diff for this revision Revisions of this file
ADXL345_I2C.h Show annotated file Show diff for this revision Revisions of this file
ITG3200.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c7d5863b2576 -r e4a11d519322 ADXL345_I2C.cpp
--- a/ADXL345_I2C.cpp	Thu Oct 24 20:31:54 2013 +0000
+++ b/ADXL345_I2C.cpp	Wed Feb 05 22:12:32 2014 +0000
@@ -59,7 +59,7 @@
 // initialize the BW data rate
     char tx[2];
     tx[0] = ADXL345_BW_RATE_REG;
-    tx[1] = ADXL345_6HZ25; //value greater than or equal to 0x0A is written into the rate bits (Bit D3 through Bit D0) in the BW_RATE register 
+    tx[1] = ADXL345_1600HZ; //value greater than or equal to 0x0A is written into the rate bits (Bit D3 through Bit D0) in the BW_RATE register 
  i2c_.write( ADXL345_I2C_WRITE , tx, 2);  
 
 //Data format (for +-16g) - This is done by setting Bit D3 of the DATA_FORMAT register (Address 0x31) and writing a value of 0x03 to the range bits (Bit D1 and Bit D0) of the DATA_FORMAT register (Address 0x31).
@@ -129,13 +129,13 @@
 }
 
 
-void ADXL345_I2C::getOutput(int* readings){
+void ADXL345_I2C::getOutput(short int* readings){
     char buffer[6];    
     multiByteRead(ADXL345_DATAX0_REG, buffer, 6);
     
-    readings[0] = (int)buffer[1] << 8 | (int)buffer[0];
-    readings[1] = (int)buffer[3] << 8 | (int)buffer[2];
-    readings[2] = (int)buffer[5] << 8 | (int)buffer[4];
+    readings[0] = (short int)buffer[1] << 8 | (short int)buffer[0];
+    readings[1] = (short int)buffer[3] << 8 | (short int)buffer[2];
+    readings[2] = (short int)buffer[5] << 8 | (short int)buffer[4];
 
 }
 
diff -r c7d5863b2576 -r e4a11d519322 ADXL345_I2C.h
--- a/ADXL345_I2C.h	Thu Oct 24 20:31:54 2013 +0000
+++ b/ADXL345_I2C.h	Wed Feb 05 22:12:32 2014 +0000
@@ -147,7 +147,7 @@
      * @param Pointer to a buffer to hold the accelerometer value for the
      *        x-axis, y-axis and z-axis [in that order].
      */
-    void getOutput(int* readings);
+    void getOutput(short int* readings);
 
     /**
      * Read the device ID register on the device.
diff -r c7d5863b2576 -r e4a11d519322 ITG3200.lib
--- a/ITG3200.lib	Thu Oct 24 20:31:54 2013 +0000
+++ b/ITG3200.lib	Wed Feb 05 22:12:32 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Digixx/code/ITG3200/#8967cbe04d96
+http://mbed.org/users/Vigneshwar/code/ITG3200/#de82c71cfc08
diff -r c7d5863b2576 -r e4a11d519322 main.cpp
--- a/main.cpp	Thu Oct 24 20:31:54 2013 +0000
+++ b/main.cpp	Wed Feb 05 22:12:32 2014 +0000
@@ -8,7 +8,7 @@
 ADXL345_I2C accel(p28, p27);
 
 int main() {
-    char str[512];
+    char str[296];
     rn42.baud(115200);
     gyro.setWhoAmI(0x68);
     //pc.printf("Now starting 6-degrees-of-freedom (ITG-3200 ADXL345) test...\n");
@@ -16,7 +16,7 @@
     //pc.printf("Gyro Devide ID is: 0x%02x\n", gyro.getWhoAmI());
      
      
-    int accel_read[3] = {0, 0, 0};
+    short int accel_read[3] = {0, 0, 0};
     
     // Accel setup
     // These are here to test whether any of the initialization fails. It will print the failure
@@ -24,25 +24,25 @@
          rn42.printf("didn't intitialize power control\n"); 
          return 0;  }
     //Full resolution, +/-16g, 4mg/LSB.
-    wait(.001);
+    //wait(.001);
      
-    if(accel.setDataFormatControl(0x0B)){
-        rn42.printf("didn't set data format\n");
-        return 0;  }
-    wait(.001);
+    //if(accel.setDataFormatControl(0x0B)){
+      //  rn42.printf("didn't set data format\n");
+      //  return 0;  }
+    //wait(.001);
     
     //3.2kHz data rate.
-    if(accel.setDataRate(ADXL345_1600HZ)){
-       rn42.printf("didn't set data rate\n");
-       return 0;    }
-    wait(.001);
+    //if(accel.setDataRate(ADXL345_3200HZ)){
+      // rn42.printf("didn't set data rate\n");
+      // return 0;    }
+    //wait(.001);
      
     //Measurement mode.
     
-    if(accel.setPowerControl(MeasurementMode)) {
-       rn42.printf("didn't set the power control to measurement\n"); 
-       return 0;   
-    }
+    //if(accel.setPowerControl(MeasurementMode)) {
+      // rn42.printf("didn't set the power control to measurement\n"); 
+      // return 0;   
+    //}
      
     // Gyro setup   
     gyro.setLpBandwidth(LPFBW_256HZ);
@@ -53,8 +53,11 @@
         
         accel.getOutput(accel_read);
         
-        sprintf(str, "%i,%i,%i,%i,%i,%i,%i,A", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2],
-                                                     gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature());  
+        /*sprintf(str, "%i,%i,%i,%i,%i,%i,%i,A", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2],
+                                                     gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature());*/  
+                                                     
+        sprintf(str, "%i,%i,%i,%i,%i,%iA", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2],
+                                                     gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ());
         rn42.printf(str);
         
         /*