2013
Dependencies: BMP085_2 SDFileSystem mbed
Fork of cansat new by
Diff: main.cpp
- Revision:
- 6:3cc5c120fbe3
- Parent:
- 5:9cfdae50349e
- Child:
- 7:ba3fa64f04e9
diff -r 9cfdae50349e -r 3cc5c120fbe3 main.cpp --- a/main.cpp Wed Jul 31 10:59:58 2013 +0000 +++ b/main.cpp Thu Aug 01 11:18:50 2013 +0000 @@ -1,8 +1,9 @@ #include "mbed.h" -#include "SDFileSystem.h" #include "BMP085.h" +#include "ADXL345_I2C.h" + -SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board +//SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board Serial xbee(p13,p14); // tx, rx /*Timeout dater;*/ //LocalFileSystem local("local"); @@ -15,7 +16,8 @@ AnalogIn v_out(p16); AnalogIn light_in(p15); BMP085 bmp085(p28, p27); - +ADXL345_I2C accelerometer(p9, p10); +Serial pc(USBTX, USBRX); int main() { @@ -24,8 +26,40 @@ float vo,ax,ay,az, light,P,t; FILE* fp = NULL; - fp = fopen("/sd/CanSat.txt", "a"); + // fp = fopen("/local/CanSat.txt", "a"); unsigned count = 0; + + + int readings[3] = {0, 0, 0}; + + + // These are here to test whether any of the initialization fails. It will print the failure + if (accelerometer.setPowerControl(0x00)){ + xbee.printf("didn't intitialize power control\n"); + return 0; + } + //Full resolution, +/-16g, 4mg/LSB. + wait(.001); + + if(accelerometer.setDataFormatControl(0x0B)){ + xbee.printf("didn't set data format\n"); + return 0; } + wait(.001); + + //3.2kHz data rate. + if(accelerometer.setDataRate(ADXL345_3200HZ)){ + xbee.printf("didn't set data rate\n"); + return 0; + } + wait(.001); + + //Measurement mode. + + if(accelerometer.setPowerControl(MeasurementMode)) { + xbee.printf("didn't set the power control to measurement\n"); + return 0; + } + //time_t epoch = 0; @@ -45,6 +79,7 @@ bmp085.update(); P = bmp085.get_pressure(); t = bmp085.get_temperature(); + if (fp != NULL) { fprintf(fp, "S %f ", seconds); @@ -56,16 +91,28 @@ fprintf(fp, "L %5.2f ",light); fprintf(fp, "P %6.2f ", P); fprintf(fp, "t %6.2f ", t); + accelerometer.getOutput(readings); + fprintf(fp,"%+4.2f, %+4.2f, %+4.2f", + (float((int16_t)readings[0]+18)/256), + (float((int16_t)readings[1]-4 )/256), + (float((int16_t)readings[2]+22)/256)); + fprintf(fp,"\n\r"); + // fclose(fp); }//if if (count % 10 == 0) { xbee.printf("S %f ", seconds); xbee.printf("T %5.2f ",r_temp); xbee.printf("H %5.2f ",((vo*8-6)/25)); - xbee.printf("X %5.2f ",(ax*33-1.65)/0.66); - xbee.printf("Y %5.2f ",(ay*33-1.65)/0.66); - xbee.printf("Z %5.2f ",(az*33-1.65)/0.66); +// xbee.printf("X %5.2f ",(ax*33-1.65)/0.66); +// xbee.printf("Y %5.2f ",(ay*33-1.65)/0.66); +// xbee.printf("Z %5.2f ",(az*33-1.65)/0.66); + accelerometer.getOutput(readings); + xbee.printf("X %+4.2f, Y %+4.2f, Z %+4.2f", + (float((int16_t)readings[0]+18)/256), + (float((int16_t)readings[1]-4 )/256), + (float((int16_t)readings[2]+22)/256)); xbee.printf("L %5.2f",light); xbee.printf("P %6.2f ", P); xbee.printf("t %6.2f ", t);