Openwear Life logger example
Dependencies: BLE_API MPL6_1 TCS3472_I2C mbed-src-openwear nRF51822_openwear
Fork of BLE_LoopbackUART by
Revision 8:150a9cb60210, committed 2014-09-16
- Comitter:
- janekm
- Date:
- Tue Sep 16 22:43:44 2014 +0000
- Parent:
- 7:9a474d182e4b
- Commit message:
- I forgot
Changed in this revision
diff -r 9a474d182e4b -r 150a9cb60210 MPL6_1.lib --- a/MPL6_1.lib Mon Sep 08 23:17:06 2014 +0000 +++ b/MPL6_1.lib Tue Sep 16 22:43:44 2014 +0000 @@ -1,1 +1,1 @@ -MPL6_1#61a7cadab29e +http://mbed.org/users/janekm/code/MPL6_1/#6221b0518f94
diff -r 9a474d182e4b -r 150a9cb60210 TCS3472_I2C.lib --- a/TCS3472_I2C.lib Mon Sep 08 23:17:06 2014 +0000 +++ b/TCS3472_I2C.lib Tue Sep 16 22:43:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/karlmaxwell67/code/TCS3472_I2C/#2a240f6ca27a +http://mbed.org/users/janekm/code/TCS3472_I2C/#2a240f6ca27a
diff -r 9a474d182e4b -r 150a9cb60210 main.cpp --- a/main.cpp Mon Sep 08 23:17:06 2014 +0000 +++ b/main.cpp Tue Sep 16 22:43:44 2014 +0000 @@ -16,13 +16,10 @@ #include "mbed.h" #include "BLEDevice.h" -#include "MPU9250.h" -#include "AHRS.h" #include "TCS3472_I2C.h" - +#include "mpu_hal.h" I2C i2c(p7, p6); TCS3472_I2C rgb_sensor(&i2c); -MPU9250 mpu9250(&i2c); Timer t; @@ -98,31 +95,7 @@ i2c.frequency(100000); ticker.attach(periodicCallback, 0.3); t.start(); - - if (mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250) != 0x71) { - while (1); - } - - mpu9250.resetMPU9250(); // Reset registers to default in preparation for device calibration - //led2 = 0; - wait(1); - mpu9250.MPU9250SelfTest(SelfTest); // Start by performing self test and reporting values - //led1 = 0; - mpu9250.calibrateMPU9250(gyroBias, accelBias); - mpu9250.getAres(); // Get accelerometer sensitivity - mpu9250.getGres(); // Get gyro sensitivity - mpu9250.getMres(); // Get magnetometer sensitivity - //magbias[0] = +470.; // User environmental x-axis correction in milliGauss, should be automatically calculated - //magbias[1] = +120.; // User environmental x-axis correction in milliGauss - //magbias[2] = +125.; // User environmental x-axis correction in milliGauss - - led1 = 0; - //while (1); - wait(2); - mpu9250.initMPU9250(); - mpu9250.initAK8963(magCalibration); - wait(1); - led2 = 0; + mpu_i2c_dev = &(i2c._i2c); ble.init(); @@ -168,17 +141,10 @@ if (current > max) max = current; if (current < min) min = current; } - mpu9250.readAccelData(accelCount); // Read the x/y/z adc values - // Now we'll calculate the accleration value into actual g's - ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set - ay = (float)accelCount[1]*aRes - accelBias[1]; - az = (float)accelCount[2]*aRes - accelBias[2]; len = sprintf((char *)reading, "%d,%d,%d,%d", rgb_readings[0], rgb_readings[1], rgb_readings[2], rgb_readings[3]); ble.updateCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(),(uint8_t *) reading, len); len = sprintf((char *)reading, "%1.4f", (max - min) * 10.0); ble.updateCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(),(uint8_t *) reading, len); - len = sprintf((char *)reading, "%1.1f, %1.1f, %1.1f", mx, my, mz); - ble.updateCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(),(uint8_t *) reading, len); //whoami = readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); //len = sprintf((char *)reading, "%d", whoami); @@ -205,76 +171,6 @@ led2 = 1.0; led1 = 1; } - - // If intPin goes high, all data registers have new data - if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) { // On interrupt, check if data ready interrupt - //led1 = !led1; - mpu9250.readAccelData(accelCount); // Read the x/y/z adc values - // Now we'll calculate the accleration value into actual g's - ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set - ay = (float)accelCount[1]*aRes - accelBias[1]; - az = (float)accelCount[2]*aRes - accelBias[2]; - - mpu9250.readGyroData(gyroCount); // Read the x/y/z adc values - // Calculate the gyro value into actual degrees per second - gx = (float)gyroCount[0]*gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set - gy = (float)gyroCount[1]*gRes - gyroBias[1]; - gz = (float)gyroCount[2]*gRes - gyroBias[2]; - - mpu9250.readMagData(magCount); // Read the x/y/z adc values - // Calculate the magnetometer values in milliGauss - // Include factory calibration per data sheet and user environmental corrections - mx = (float)magCount[0]*mRes*magCalibration[0] - magbias[0]; // get actual magnetometer value, this depends on scale being set - my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1]; - mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2]; - - - Now = t.read_us(); - deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update - lastUpdate = Now; - - sum += deltat; - sumCount++; - - MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz, deltat, q); - - // Serial print and/or display at 0.5 s rate independent of data rates - delt_t = t.read_ms() - count; - if (delt_t > 500) { // update LCD once per half-second independent of read rate - - - tempCount = mpu9250.readTempData(); // Read the adc values - temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade - - // Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation. - // In this coordinate system, the positive z-axis is down toward Earth. - // Yaw is the angle between Sensor x-axis and Earth magnetic North (or true North if corrected for local declination, looking down on the sensor positive yaw is counterclockwise. - // Pitch is angle between sensor x-axis and Earth ground plane, toward the Earth is positive, up toward the sky is negative. - // Roll is angle between sensor y-axis and Earth ground plane, y-axis up is positive roll. - // These arise from the definition of the homogeneous rotation matrix constructed from quaternions. - // Tait-Bryan angles as well as Euler angles are non-commutative; that is, the get the correct orientation the rotations must be - // applied in the correct order which for this configuration is yaw, pitch, and then roll. - // For more see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles which has additional links. - yaw = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]); - pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2])); - roll = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]); - pitch *= 180.0f / PI; - yaw *= 180.0f / PI; - // yaw -= 13.8f; // Declination at Danville, California is 13 degrees 48 minutes and 47 seconds on 2014-04-04 - roll *= 180.0f / PI; - - count = t.read_ms(); - - if(count > 1<<21) { - t.start(); // start the timer over again if ~30 minutes has passed - count = 0; - deltat= 0; - lastUpdate = t.read_us(); - } - sum = 0; - sumCount = 0; - } - } } } }
diff -r 9a474d182e4b -r 150a9cb60210 mbed-src-openwear.lib --- a/mbed-src-openwear.lib Mon Sep 08 23:17:06 2014 +0000 +++ b/mbed-src-openwear.lib Tue Sep 16 22:43:44 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/janekm/code/mbed-src-openwear/#1576dac518fb +http://mbed.org/users/janekm/code/mbed-src-openwear/#6188e0254baa