ROHMUSDC / Mbed 2 deprecated MultiTech_DragonFly_ROHMSensorShield_SampleApplication

Dependencies:   mbed

Fork of ROHM-DragonFly-MultiSensorShield_Interface by Francis Lee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* 
00002 Sample Program Description: 
00003     This Program will enable to Multi-Tech Dragonfly platform to utilize ROHM's Multi-sensor Shield Board.
00004     This program will initialize all sensors on the shield and then read back the sensor data.
00005     Data will then be output to the UART Debug Terminal every 1 second.
00006 
00007 Sample Program Author: 
00008     ROHM USDC
00009 
00010 Additional Resources:
00011     ROHM Sensor Shield GitHub Repository: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield
00012 */
00013 #include "mbed.h"
00014 
00015 //Macros for checking each of the different Sensor Devices
00016 #define AnalogTemp  //BDE0600
00017 #define AnalogUV    //ML8511
00018 #define HallSensor  //BU52014
00019 #define RPR0521     //RPR0521
00020 #define KMX62       //KMX61, Accel/Mag         
00021 #define COLOR       //BH1745
00022 #define KX122       //KX122, Accel Only
00023 #define Pressure    //BM1383
00024 #define KXG03        //KXG03
00025 
00026 //Define Pins for I2C Interface
00027 I2C i2c(I2C_SDA, I2C_SCL);
00028 bool        RepStart = true;
00029 bool        NoRepStart = false;
00030 
00031 //Define Sensor Variables
00032 #ifdef AnalogTemp
00033 AnalogIn    BDE0600_Temp(PC_4); //Mapped to A2
00034 uint16_t    BDE0600_Temp_value;
00035 float       BDE0600_output;
00036 #endif
00037 
00038 #ifdef AnalogUV
00039 AnalogIn    ML8511_UV(PC_1);    //Mapped to A4
00040 uint16_t    ML8511_UV_value;
00041 float       ML8511_output;
00042 #endif
00043 
00044 #ifdef HallSensor
00045 DigitalIn   Hall_GPIO0(PC_8);
00046 DigitalIn   Hall_GPIO1(PB_5);
00047 int         Hall_Return1;
00048 int         Hall_Return0;
00049 #endif
00050 
00051 #ifdef RPR0521
00052 int         RPR0521_addr_w = 0x70;          //7bit addr = 0x38, with write bit 0
00053 int         RPR0521_addr_r = 0x71;          //7bit addr = 0x38, with read bit 1
00054 char        RPR0521_ModeControl[2] = {0x41, 0xE6};  
00055 char        RPR0521_ALSPSControl[2] = {0x42, 0x03};
00056 char        RPR0521_Persist[2] = {0x43, 0x20};
00057 char        RPR0521_Addr_ReadData = 0x44;
00058 char        RPR0521_Content_ReadData[6];
00059 int         RPR0521_PS_RAWOUT = 0;
00060 float       RPR0521_PS_OUT = 0;
00061 int         RPR0521_ALS_D0_RAWOUT = 0;
00062 int         RPR0521_ALS_D1_RAWOUT = 0;
00063 float       RPR0521_ALS_DataRatio = 0;
00064 float       RPR0521_ALS_OUT = 0;
00065 #endif
00066 
00067 #ifdef KMX62
00068 int         KMX62_addr_w = 0x1C;          //7bit addr = 0x38, with write bit 0
00069 int         KMX62_addr_r = 0x1D;          //7bit addr = 0x38, with read bit 1
00070 char        KMX62_CNTL2[2] = {0x3A, 0x5F};
00071 char        KMX62_Addr_Accel_ReadData = 0x0A;
00072 char        KMX62_Content_Accel_ReadData[6];
00073 char        KMX62_Addr_Mag_ReadData = 0x10;
00074 char        KMX62_Content_Mag_ReadData[6];
00075 short int   MEMS_Accel_Xout = 0;
00076 short int   MEMS_Accel_Yout = 0;
00077 short int   MEMS_Accel_Zout = 0;
00078 double      MEMS_Accel_Conv_Xout = 0;
00079 double      MEMS_Accel_Conv_Yout = 0;
00080 double      MEMS_Accel_Conv_Zout = 0;
00081 short int   MEMS_Mag_Xout = 0;
00082 short int   MEMS_Mag_Yout = 0;
00083 short int   MEMS_Mag_Zout = 0;
00084 float       MEMS_Mag_Conv_Xout = 0;
00085 float       MEMS_Mag_Conv_Yout = 0;
00086 float       MEMS_Mag_Conv_Zout = 0;
00087 #endif
00088 
00089 #ifdef COLOR
00090 int         BH1745_addr_w = 0x72;   //write 
00091 int         BH1745_addr_r = 0x73;   //read 
00092 char        BH1745_persistence[2] = {0x61, 0x03};
00093 char        BH1745_mode1[2] = {0x41, 0x00};
00094 char        BH1745_mode2[2] = {0x42, 0x92};
00095 char        BH1745_mode3[2] = {0x43, 0x02};
00096 char        BH1745_Content_ReadData[6];
00097 char        BH1745_Addr_color_ReadData = 0x50;
00098 int         BH1745_Red;
00099 int         BH1745_Blue;
00100 int         BH1745_Green;
00101 #endif
00102 
00103 #ifdef KX122
00104 int         KX122_addr_w = 0x3C;   //write 
00105 int         KX122_addr_r = 0x3D;   //read 
00106 char        KX122_Accel_CNTL1[2] = {0x18, 0x41};
00107 char        KX122_Accel_ODCNTL[2] = {0x1B, 0x02};
00108 char        KX122_Accel_CNTL3[2] = {0x1A, 0xD8};
00109 char        KX122_Accel_TILT_TIMER[2] = {0x22, 0x01};
00110 char        KX122_Accel_CNTL2[2] = {0x18, 0xC1};
00111 char        KX122_Content_ReadData[6];
00112 char        KX122_Addr_Accel_ReadData = 0x06;           
00113 float       KX122_Accel_X;
00114 float       KX122_Accel_Y;                               
00115 float       KX122_Accel_Z;
00116 short int   KX122_Accel_X_RawOUT = 0;
00117 short int   KX122_Accel_Y_RawOUT = 0;
00118 short int   KX122_Accel_Z_RawOUT = 0;
00119 int         KX122_Accel_X_LB = 0;
00120 int         KX122_Accel_X_HB = 0;
00121 int         KX122_Accel_Y_LB = 0;
00122 int         KX122_Accel_Y_HB = 0;
00123 int         KX122_Accel_Z_LB = 0;
00124 int         KX122_Accel_Z_HB = 0;
00125 #endif
00126 
00127 #ifdef KXG03
00128 int         i = 11;
00129 int         t = 1;
00130 short int   aveX = 0;
00131 short int   aveX2 = 0;
00132 short int   aveX3 = 0;
00133 short int   aveY = 0;
00134 short int   aveY2 = 0;
00135 short int   aveY3 = 0;
00136 short int   aveZ = 0;
00137 short int   aveZ2 = 0;
00138 short int   aveZ3 = 0;
00139 float       ave22;
00140 float       ave33;
00141 int         KXG03_addr_w = 0x9C;   //write 
00142 int         KXG03_addr_r = 0x9D;   //read 
00143 char        KXG03_STBY_REG[2] = {0x43, 0x00};
00144 char        KXG03_Content_Gyro_ReadData[6];
00145 char        KXG03_Content_Accel_ReadData[6];
00146 char        KXG03_Addr_Gyro_ReadData = 0x02;
00147 char        KXG03_Addr_Accel_ReadData = 0x08;
00148 float       KXG03_Gyro_X;
00149 float       KXG03_Gyro_Y;                               
00150 float       KXG03_Gyro_Z;
00151 short int   KXG03_Gyro_X_RawOUT = 0;
00152 short int   KXG03_Gyro_Y_RawOUT = 0; 
00153 short int   KXG03_Gyro_Z_RawOUT = 0;
00154 short int   KXG03_Gyro_X_RawOUT2 = 0;
00155 short int   KXG03_Gyro_Y_RawOUT2 = 0; 
00156 short int   KXG03_Gyro_Z_RawOUT2 = 0;  
00157 float       KXG03_Accel_X;
00158 float       KXG03_Accel_Y;                               
00159 float       KXG03_Accel_Z;  
00160 short int   KXG03_Accel_X_RawOUT = 0;
00161 short int   KXG03_Accel_Y_RawOUT = 0;
00162 short int   KXG03_Accel_Z_RawOUT = 0;       
00163 #endif
00164 
00165 #ifdef Pressure
00166 int         Press_addr_w = 0xBA;   //write 
00167 int         Press_addr_r = 0xBB;   //read 
00168 char        PWR_DOWN[2] = {0x12, 0x01};
00169 char        SLEEP[2] = {0x13, 0x01};
00170 char        Mode_Control[2] = {0x14, 0xC4};
00171 char        Press_Content_ReadData[6];
00172 char        Press_Addr_ReadData =0x1A;
00173 int         BM1383_Temp_highByte;
00174 int         BM1383_Temp_lowByte;
00175 int         BM1383_Pres_highByte;
00176 int         BM1383_Pres_lowByte;
00177 int         BM1383_Pres_leastByte; 
00178 short int   BM1383_Temp_Out;
00179 float       BM1383_Temp_Conv_Out;
00180 float       BM1383_Pres_Conv_Out;
00181 float       BM1383_Var;
00182 float       BM1383_Deci;
00183 #endif
00184 
00185 int main() {
00186     
00187 //Initialization Section Start! **********************************************************
00188     
00189     //Initialize I2C Devices **********************************************************
00190     
00191 #ifdef RPR0521
00192     i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false);
00193     i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false);
00194     i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false);
00195 #endif
00196 
00197 #ifdef KMX62
00198     i2c.write(KMX62_addr_w, &KMX62_CNTL2[0], 2, false);
00199 #endif
00200 
00201 #ifdef COLOR
00202     i2c.write(BH1745_addr_w, &BH1745_persistence[0], 2, false);
00203     i2c.write(BH1745_addr_w, &BH1745_mode1[0], 2, false);
00204     i2c.write(BH1745_addr_w, &BH1745_mode2[0], 2, false);
00205     i2c.write(BH1745_addr_w, &BH1745_mode3[0], 2, false);
00206 #endif
00207 
00208 #ifdef KX122
00209     i2c.write(KX122_addr_w, &KX122_Accel_CNTL1[0], 2, false);
00210     i2c.write(KX122_addr_w, &KX122_Accel_ODCNTL[0], 2, false);
00211     i2c.write(KX122_addr_w, &KX122_Accel_CNTL3[0], 2, false);
00212     i2c.write(KX122_addr_w, &KX122_Accel_TILT_TIMER[0], 2, false);
00213     i2c.write(KX122_addr_w, &KX122_Accel_CNTL2[0], 2, false);
00214 #endif
00215 
00216 #ifdef KXG03
00217     i2c.write(KXG03_addr_w, &KXG03_STBY_REG[0], 2, false);        
00218 #endif
00219 
00220 #ifdef Pressure
00221     i2c.write(Press_addr_w, &PWR_DOWN[0], 2, false);
00222     i2c.write(Press_addr_w, &SLEEP[0], 2, false);
00223     i2c.write(Press_addr_w, &Mode_Control[0], 2, false);
00224 #endif
00225 //End Initialization Section **********************************************************
00226 
00227 //Begin Main Loop **********************************************************
00228     while (1) {
00229         
00230         // ADC Routines *******************************************************
00231         #ifdef AnalogTemp
00232         BDE0600_Temp_value = BDE0600_Temp.read_u16();
00233         
00234         BDE0600_output = (float)BDE0600_Temp_value * (float)0.000050354; //(value * (3.3V/65535))
00235         BDE0600_output = (BDE0600_output-(float)1.753)/((float)-0.01068) + (float)30;
00236         
00237         printf("BDE0600 Analog Temp Sensor Data:\r\n");
00238         printf(" Temp = %.2f degC\r\n", BDE0600_output);
00239         #endif
00240 
00241         #ifdef AnalogUV
00242         ML8511_UV_value = ML8511_UV.read_u16();
00243         ML8511_output = (float)ML8511_UV_value * (float)0.000050354; //(value * (3.3V/65535))   //Note to self: when playing with this, a negative value is seen... Honestly, I think this has to do with my ADC converstion...
00244         ML8511_output = (ML8511_output-(float)2.2)/((float)0.129) + 10;                           // Added +5 to the offset so when inside (aka, no UV, readings show 0)... this is the wrong approach... and the readings don't make sense... Fix this.
00245         
00246         printf("ML8511 Analog UV Sensor Data:\r\n");
00247         printf(" UV = %.1f mW/cm2\r\n", ML8511_output);
00248         #endif
00249 
00250         // GPI Routines *******************************************************
00251         #ifdef HallSensor
00252         Hall_Return0 = Hall_GPIO0;
00253         Hall_Return1 = Hall_GPIO1;
00254         
00255         printf("BU52011 Hall Switch Sensor Data:\r\n");
00256         printf(" South Detect = %d\r\n", Hall_Return0);
00257         printf(" North Detect = %d\r\n", Hall_Return1);     
00258         #endif
00259         
00260         // I2C Routines *******************************************************
00261         #ifdef COLOR
00262         //Read color data from the IC
00263         i2c.write(BH1745_addr_w, &BH1745_Addr_color_ReadData, 1, RepStart);
00264         i2c.read(BH1745_addr_r, &BH1745_Content_ReadData[0], 6, NoRepStart);
00265         
00266         //separate all data read into colors
00267         BH1745_Red = (BH1745_Content_ReadData[1]<<8) | (BH1745_Content_ReadData[0]);
00268         BH1745_Green = (BH1745_Content_ReadData[3]<<8) | (BH1745_Content_ReadData[2]);
00269         BH1745_Blue = (BH1745_Content_ReadData[5]<<8) | (BH1745_Content_ReadData[4]);
00270         
00271         //Output Data into UART 
00272         printf("BH1745 COLOR Sensor Data:\r\n");
00273         printf(" Red   = %d ADC Counts\r\n",BH1745_Red);
00274         printf(" Green = %d ADC Counts\r\n",BH1745_Green);
00275         printf(" Blue  = %d ADC Counts\r\n",BH1745_Blue);
00276         #endif
00277         
00278         #ifdef RPR0521       //als digital
00279         i2c.write(RPR0521_addr_w, &RPR0521_Addr_ReadData, 1, RepStart);
00280         i2c.read(RPR0521_addr_r, &RPR0521_Content_ReadData[0], 6, NoRepStart);
00281         
00282         RPR0521_PS_RAWOUT = (RPR0521_Content_ReadData[1]<<8) | (RPR0521_Content_ReadData[0]);
00283         RPR0521_ALS_D0_RAWOUT = (RPR0521_Content_ReadData[3]<<8) | (RPR0521_Content_ReadData[2]);
00284         RPR0521_ALS_D1_RAWOUT = (RPR0521_Content_ReadData[5]<<8) | (RPR0521_Content_ReadData[4]);
00285         RPR0521_ALS_DataRatio = (float)RPR0521_ALS_D1_RAWOUT / (float)RPR0521_ALS_D0_RAWOUT;
00286          
00287         if(RPR0521_ALS_DataRatio < (float)0.595){
00288             RPR0521_ALS_OUT = ((float)1.682*(float)RPR0521_ALS_D0_RAWOUT - (float)1.877*(float)RPR0521_ALS_D1_RAWOUT);
00289         }
00290         else if(RPR0521_ALS_DataRatio < (float)1.015){
00291             RPR0521_ALS_OUT = ((float)0.644*(float)RPR0521_ALS_D0_RAWOUT - (float)0.132*(float)RPR0521_ALS_D1_RAWOUT);
00292         }
00293         else if(RPR0521_ALS_DataRatio < (float)1.352){
00294             RPR0521_ALS_OUT = ((float)0.756*(float)RPR0521_ALS_D0_RAWOUT - (float)0.243*(float)RPR0521_ALS_D1_RAWOUT);
00295         }
00296         else if(RPR0521_ALS_DataRatio < (float)3.053){
00297             RPR0521_ALS_OUT = ((float)0.766*(float)RPR0521_ALS_D0_RAWOUT - (float)0.25*(float)RPR0521_ALS_D1_RAWOUT);
00298         }
00299         else{
00300             RPR0521_ALS_OUT = 0;
00301         }
00302         printf("RPR-0521 ALS/PROX Sensor Data:\r\n");
00303         printf(" ALS = %0.2f lx\r\n", RPR0521_ALS_OUT);
00304         printf(" PROX= %u ADC Counts\r\n", RPR0521_PS_RAWOUT);
00305         #endif
00306         
00307         #ifdef KMX62
00308         //Read Accel Portion from the IC
00309         i2c.write(KMX62_addr_w, &KMX62_Addr_Accel_ReadData, 1, RepStart);
00310         i2c.read(KMX62_addr_r, &KMX62_Content_Accel_ReadData[0], 6, NoRepStart);
00311 
00312         //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
00313         //      However, because we need the signed value, we will adjust the value when converting to "g"
00314         MEMS_Accel_Xout = (KMX62_Content_Accel_ReadData[1]<<8) | (KMX62_Content_Accel_ReadData[0]);
00315         MEMS_Accel_Yout = (KMX62_Content_Accel_ReadData[3]<<8) | (KMX62_Content_Accel_ReadData[2]);
00316         MEMS_Accel_Zout = (KMX62_Content_Accel_ReadData[5]<<8) | (KMX62_Content_Accel_ReadData[4]);
00317           
00318         //Note: Conversion to G is as follows:
00319         //      Axis_ValueInG = MEMS_Accel_axis / 1024
00320         //      However, since we did not remove the LSB previously, we need to divide by 4 again
00321         //      Thus, we will divide the output by 4096 (1024*4) to convert and cancel out the LSB
00322         MEMS_Accel_Conv_Xout = ((float)MEMS_Accel_Xout/4096/2);
00323         MEMS_Accel_Conv_Yout = ((float)MEMS_Accel_Yout/4096/2);
00324         MEMS_Accel_Conv_Zout = ((float)MEMS_Accel_Zout/4096/2);
00325 
00326         //Read Mag portion from the IC
00327         i2c.write(KMX62_addr_w, &KMX62_Addr_Mag_ReadData, 1, RepStart);
00328         i2c.read(KMX62_addr_r, &KMX62_Content_Mag_ReadData[0], 6, NoRepStart);
00329 
00330         //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte.
00331         //      However, because we need the signed value, we will adjust the value when converting to "g"
00332         MEMS_Mag_Xout = (KMX62_Content_Mag_ReadData[1]<<8) | (KMX62_Content_Mag_ReadData[0]);
00333         MEMS_Mag_Yout = (KMX62_Content_Mag_ReadData[3]<<8) | (KMX62_Content_Mag_ReadData[2]);
00334         MEMS_Mag_Zout = (KMX62_Content_Mag_ReadData[5]<<8) | (KMX62_Content_Mag_ReadData[4]);
00335         
00336         //Note: Conversion to G is as follows:
00337         //      Axis_ValueInG = MEMS_Accel_axis / 1024
00338         //      However, since we did not remove the LSB previously, we need to divide by 4 again
00339         //      Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB
00340         MEMS_Mag_Conv_Xout = (float)MEMS_Mag_Xout/4096*(float)0.146;
00341         MEMS_Mag_Conv_Yout = (float)MEMS_Mag_Yout/4096*(float)0.146;
00342         MEMS_Mag_Conv_Zout = (float)MEMS_Mag_Zout/4096*(float)0.146; 
00343 
00344         // Return Data to UART
00345         printf("KMX62 Accel+Mag Sensor Data:\r\n");
00346         printf(" AccX= %0.2f g\r\n", MEMS_Accel_Conv_Xout);
00347         printf(" AccY= %0.2f g\r\n", MEMS_Accel_Conv_Yout);
00348         printf(" AccZ= %0.2f g\r\n", MEMS_Accel_Conv_Zout);
00349         printf(" MagX= %0.2f uT\r\n", MEMS_Mag_Conv_Xout);
00350         printf(" MagY= %0.2f uT\r\n", MEMS_Mag_Conv_Yout);
00351         printf(" MagZ= %0.2f uT\r\n", MEMS_Mag_Conv_Zout);
00352         #endif
00353      
00354         #ifdef KX122
00355         //Read KX122 Portion from the IC
00356         i2c.write(KX122_addr_w, &KX122_Addr_Accel_ReadData, 1, RepStart);
00357         i2c.read(KX122_addr_r, &KX122_Content_ReadData[0], 6, NoRepStart);
00358                     
00359         //Format Data
00360         KX122_Accel_X_RawOUT = (KX122_Content_ReadData[1]<<8) | (KX122_Content_ReadData[0]);
00361         KX122_Accel_Y_RawOUT = (KX122_Content_ReadData[3]<<8) | (KX122_Content_ReadData[2]);
00362         KX122_Accel_Z_RawOUT = (KX122_Content_ReadData[5]<<8) | (KX122_Content_ReadData[4]);       
00363 
00364         //Scale Data
00365         KX122_Accel_X = (float)KX122_Accel_X_RawOUT / 16384;
00366         KX122_Accel_Y = (float)KX122_Accel_Y_RawOUT / 16384;
00367         KX122_Accel_Z = (float)KX122_Accel_Z_RawOUT / 16384;
00368         
00369         //Return Data through UART
00370         printf("KX122 Accelerometer Sensor Data: \r\n");
00371         printf(" AccX= %0.2f g\r\n", KX122_Accel_X);
00372         printf(" AccY= %0.2f g\r\n", KX122_Accel_Y);
00373         printf(" AccZ= %0.2f g\r\n", KX122_Accel_Z);
00374         #endif
00375         
00376         #ifdef KXG03
00377         //Read KXG03 Gyro Portion from the IC
00378         i2c.write(KXG03_addr_w, &KXG03_Addr_Gyro_ReadData, 1, RepStart);
00379         i2c.read(KXG03_addr_r, &KXG03_Content_Gyro_ReadData[0], 6, NoRepStart);
00380         
00381         if (t == 1){    
00382             int i = 11;
00383             while(--i) 
00384             {
00385                 //Read KXG03 Gyro Portion from the IC
00386                 i2c.write(KXG03_addr_w, &KXG03_Addr_Gyro_ReadData, 1, RepStart);
00387                 i2c.read(KXG03_addr_r, &KXG03_Content_Gyro_ReadData[0], 6, NoRepStart);
00388       
00389                 //Format Data
00390                 KXG03_Gyro_X_RawOUT = (KXG03_Content_Gyro_ReadData[1]<<8) | (KXG03_Content_Gyro_ReadData[0]);
00391                 KXG03_Gyro_Y_RawOUT = (KXG03_Content_Gyro_ReadData[3]<<8) | (KXG03_Content_Gyro_ReadData[2]);
00392                 KXG03_Gyro_Z_RawOUT = (KXG03_Content_Gyro_ReadData[5]<<8) | (KXG03_Content_Gyro_ReadData[4]);
00393                 aveX = KXG03_Gyro_X_RawOUT;
00394                 aveY = KXG03_Gyro_Y_RawOUT;
00395                 aveZ = KXG03_Gyro_Z_RawOUT;
00396                 aveX2 = aveX2 + aveX;
00397                 aveY2 = aveY2 + aveY;
00398                 aveZ2 = aveZ2 + aveZ;  
00399              } 
00400         aveX3 = aveX2 / 10;
00401         aveY3 = aveY2 / 10;
00402         aveZ3 = aveZ2 / 10;
00403         printf("KXG03 Gyroscopic Sensor Data: \r\n");
00404         printf("KXG03 Gyroscopic Offset Calculation: \r\n");      
00405         printf(" aveX2= %d \r\n", aveX2);        
00406         printf(" aveY2= %d \r\n", aveY2);
00407         printf(" aveZ2= %d \r\n", aveZ2);
00408         printf(" aveX3= %d \r\n", aveX3);  
00409         printf(" aveY3= %d \r\n", aveY3);  
00410         printf(" aveZ3= %d \r\n", aveZ3);       
00411         t = 0;
00412         }                  
00413         
00414         else {
00415         //Read KXG03 Gyro Portion from the IC
00416         i2c.write(KXG03_addr_w, &KXG03_Addr_Gyro_ReadData, 1, RepStart);
00417         i2c.read(KXG03_addr_r, &KXG03_Content_Gyro_ReadData[0], 6, NoRepStart);
00418                             
00419         //Format Data
00420         KXG03_Gyro_X_RawOUT = (KXG03_Content_Gyro_ReadData[1]<<8) | (KXG03_Content_Gyro_ReadData[0]);
00421         KXG03_Gyro_Y_RawOUT = (KXG03_Content_Gyro_ReadData[3]<<8) | (KXG03_Content_Gyro_ReadData[2]);
00422         KXG03_Gyro_Z_RawOUT = (KXG03_Content_Gyro_ReadData[5]<<8) | (KXG03_Content_Gyro_ReadData[4]);  
00423         
00424         //printf(" aveX3= %d \r\n", aveX3);  
00425         //printf(" aveY3= %d \r\n", aveY3);  
00426         //printf(" aveZ3= %d \r\n", aveZ3);
00427 
00428         KXG03_Gyro_X_RawOUT2 = KXG03_Gyro_X_RawOUT - aveX3;
00429         KXG03_Gyro_Y_RawOUT2 = KXG03_Gyro_Y_RawOUT - aveY3;
00430         KXG03_Gyro_Z_RawOUT2 = KXG03_Gyro_Z_RawOUT - aveZ3;
00431         
00432         //Scale Data
00433         KXG03_Gyro_X = (float)KXG03_Gyro_X_RawOUT2 * (float)0.007813 + (float)0.000004;
00434         KXG03_Gyro_Y = (float)KXG03_Gyro_Y_RawOUT2 * (float)0.007813 + (float)0.000004;
00435         KXG03_Gyro_Z = (float)KXG03_Gyro_Z_RawOUT2 * (float)0.007813 + (float)0.000004;           
00436         
00437         printf("KXG03 Gyroscopic Sensor Data: \r\n");
00438         printf(" GyroX= %0.2f deg/sec\r\n", KXG03_Gyro_X);
00439         printf(" GyroY= %0.2f deg/sec\r\n", KXG03_Gyro_Y);
00440         printf(" GyroZ= %0.2f deg/sec\r\n", KXG03_Gyro_Z);        
00441         
00442         //Read KXG03 Accel Portion from the IC
00443         i2c.write(KXG03_addr_w, &KXG03_Addr_Accel_ReadData, 1, RepStart);
00444         i2c.read(KXG03_addr_r, &KXG03_Content_Accel_ReadData[0], 6, NoRepStart); 
00445         
00446         KXG03_Accel_X_RawOUT = (KXG03_Content_Accel_ReadData[1]<<8) | (KXG03_Content_Accel_ReadData[0]);
00447         KXG03_Accel_Y_RawOUT = (KXG03_Content_Accel_ReadData[3]<<8) | (KXG03_Content_Accel_ReadData[2]);
00448         KXG03_Accel_Z_RawOUT = (KXG03_Content_Accel_ReadData[5]<<8) | (KXG03_Content_Accel_ReadData[4]);        
00449          
00450         //Scale Data
00451         KXG03_Accel_X = (float)KXG03_Accel_X_RawOUT * (float)0.000061 + (float)0.000017;
00452         KXG03_Accel_Y = (float)KXG03_Accel_Y_RawOUT * (float)0.000061 + (float)0.000017;
00453         KXG03_Accel_Z = (float)KXG03_Accel_Z_RawOUT * (float)0.000061 + (float)0.000017;        
00454                             
00455         //Return Data through UART
00456         printf(" AccX= %0.2f g\r\n", KXG03_Accel_X);
00457         printf(" AccY= %0.2f g\r\n", KXG03_Accel_Y);
00458         printf(" AccZ= %0.2f g\r\n", KXG03_Accel_Z);   
00459         aveX2 = 0;
00460         aveY2 = 0;
00461         aveZ2 = 0;
00462         }              
00463         #endif
00464      
00465         #ifdef Pressure
00466         i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart);
00467         i2c.read(Press_addr_r, &Press_Content_ReadData[0], 6, NoRepStart);
00468         
00469         BM1383_Temp_Out = (Press_Content_ReadData[0]<<8) | (Press_Content_ReadData[1]);
00470         BM1383_Temp_Conv_Out = (float)BM1383_Temp_Out/32;
00471         
00472         BM1383_Var  = (Press_Content_ReadData[2]<<3) | (Press_Content_ReadData[3] >> 5);
00473         BM1383_Deci = ((Press_Content_ReadData[3] & 0x1f) << 6 | ((Press_Content_ReadData[4] >> 2)));
00474         BM1383_Deci = (float)BM1383_Deci* (float)0.00048828125;  //0.00048828125 = 2^-11
00475         BM1383_Pres_Conv_Out = (BM1383_Var + BM1383_Deci);   //question pending here...
00476         
00477         printf("BM1383 Pressure Sensor Data:\r\n");
00478         printf(" Temperature= %0.2f degC\r\n", BM1383_Temp_Conv_Out);
00479         printf(" Pressure   = %0.2f hPa\r\n", BM1383_Pres_Conv_Out);
00480         #endif
00481         //*********************************************************************
00482 
00483         printf("\r\n");
00484         wait(1);    //Wait before re-gathering sensor data
00485     }
00486 }