![](/media/cache/profiles/6f7790bb54a7c5d3dea27385488a604a.jpg.50x50_q85.jpg)
putting strings to xbee
Dependencies: BMP085 SDFileSystem mbed JPEGCamera
Fork of SaibiCansat2014 by
main.cpp@2:71f75585db19, 2014-07-14 (annotated)
- Committer:
- TakashiSasaki
- Date:
- Mon Jul 14 09:42:11 2014 +0000
- Revision:
- 2:71f75585db19
- Parent:
- 1:31e810237ac1
- Child:
- 3:7ea76022b5eb
corrected printf messages for BMP085 and ADXL345
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emanon | 0:e4ca6571a751 | 1 | #include "mbed.h" |
emanon | 0:e4ca6571a751 | 2 | #include "SDFileSystem.h" |
emanon | 0:e4ca6571a751 | 3 | #include "BMP085.h" |
emanon | 0:e4ca6571a751 | 4 | #include "ADXL345_I2C.h" |
emanon | 0:e4ca6571a751 | 5 | |
emanon | 0:e4ca6571a751 | 6 | |
emanon | 0:e4ca6571a751 | 7 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
emanon | 0:e4ca6571a751 | 8 | |
emanon | 0:e4ca6571a751 | 9 | ADXL345_I2C accelerometer(p28, p27); |
emanon | 0:e4ca6571a751 | 10 | BMP085 bmp085(p28, p27); |
emanon | 0:e4ca6571a751 | 11 | |
emanon | 0:e4ca6571a751 | 12 | Serial pc(USBTX, USBRX); |
emanon | 0:e4ca6571a751 | 13 | |
emanon | 1:31e810237ac1 | 14 | AnalogIn ain_CDS(p15); |
emanon | 1:31e810237ac1 | 15 | AnalogIn ain_Humedity(p16); |
emanon | 1:31e810237ac1 | 16 | AnalogIn ain_LM35DZ(p20); |
emanon | 1:31e810237ac1 | 17 | |
emanon | 1:31e810237ac1 | 18 | |
emanon | 0:e4ca6571a751 | 19 | DigitalOut myled(LED1); |
emanon | 0:e4ca6571a751 | 20 | |
emanon | 0:e4ca6571a751 | 21 | int fileio() { |
emanon | 0:e4ca6571a751 | 22 | mkdir("/sd/20014", 0777); |
emanon | 0:e4ca6571a751 | 23 | |
emanon | 0:e4ca6571a751 | 24 | FILE *fp = fopen("/sd/mydir/datalog.txt", "w"); |
emanon | 0:e4ca6571a751 | 25 | if(fp == NULL) { |
emanon | 0:e4ca6571a751 | 26 | error("Could not open file for write\n"); |
emanon | 0:e4ca6571a751 | 27 | } |
emanon | 0:e4ca6571a751 | 28 | fprintf(fp, "Hello fun SD Card World!"); |
emanon | 0:e4ca6571a751 | 29 | fclose(fp); |
emanon | 0:e4ca6571a751 | 30 | |
emanon | 0:e4ca6571a751 | 31 | printf("Goodbye World!\n"); |
emanon | 0:e4ca6571a751 | 32 | |
emanon | 0:e4ca6571a751 | 33 | return(0); |
emanon | 0:e4ca6571a751 | 34 | } |
emanon | 0:e4ca6571a751 | 35 | |
emanon | 0:e4ca6571a751 | 36 | |
emanon | 0:e4ca6571a751 | 37 | int main() { |
emanon | 0:e4ca6571a751 | 38 | myled = 1; |
emanon | 0:e4ca6571a751 | 39 | |
emanon | 0:e4ca6571a751 | 40 | pc.baud(115200); |
emanon | 0:e4ca6571a751 | 41 | |
emanon | 0:e4ca6571a751 | 42 | int readings[3] = {0, 0, 0}; |
emanon | 0:e4ca6571a751 | 43 | |
emanon | 0:e4ca6571a751 | 44 | pc.printf("Starting ADXL345 test...\n"); |
emanon | 0:e4ca6571a751 | 45 | wait(.001); |
emanon | 0:e4ca6571a751 | 46 | pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); |
emanon | 0:e4ca6571a751 | 47 | wait(.001); |
emanon | 0:e4ca6571a751 | 48 | |
emanon | 0:e4ca6571a751 | 49 | // These are here to test whether any of the initialization fails. It will print the failure |
emanon | 0:e4ca6571a751 | 50 | if (accelerometer.setPowerControl(0x00)){ |
emanon | 0:e4ca6571a751 | 51 | pc.printf("didn't intitialize power control\n"); |
emanon | 0:e4ca6571a751 | 52 | return 0; |
emanon | 0:e4ca6571a751 | 53 | } |
emanon | 0:e4ca6571a751 | 54 | //Full resolution, +/-16g, 4mg/LSB. |
emanon | 0:e4ca6571a751 | 55 | wait(.001); |
emanon | 0:e4ca6571a751 | 56 | |
emanon | 0:e4ca6571a751 | 57 | if(accelerometer.setDataFormatControl(0x0B)){ |
emanon | 0:e4ca6571a751 | 58 | pc.printf("didn't set data format\n"); |
emanon | 0:e4ca6571a751 | 59 | return 0; } |
emanon | 0:e4ca6571a751 | 60 | wait(.001); |
emanon | 0:e4ca6571a751 | 61 | |
emanon | 0:e4ca6571a751 | 62 | //3.2kHz data rate. |
emanon | 0:e4ca6571a751 | 63 | if(accelerometer.setDataRate(ADXL345_3200HZ)){ |
emanon | 0:e4ca6571a751 | 64 | pc.printf("didn't set data rate\n"); |
emanon | 0:e4ca6571a751 | 65 | return 0; |
emanon | 0:e4ca6571a751 | 66 | } |
emanon | 0:e4ca6571a751 | 67 | wait(.001); |
emanon | 0:e4ca6571a751 | 68 | |
emanon | 0:e4ca6571a751 | 69 | //Measurement mode. |
emanon | 0:e4ca6571a751 | 70 | |
emanon | 0:e4ca6571a751 | 71 | if(accelerometer.setPowerControl(MeasurementMode)) { |
emanon | 0:e4ca6571a751 | 72 | pc.printf("didn't set the power control to measurement\n"); |
emanon | 0:e4ca6571a751 | 73 | return 0; |
emanon | 0:e4ca6571a751 | 74 | } |
emanon | 0:e4ca6571a751 | 75 | myled = 0; |
emanon | 0:e4ca6571a751 | 76 | |
emanon | 0:e4ca6571a751 | 77 | while (1) { |
emanon | 1:31e810237ac1 | 78 | wait(1.5); |
emanon | 1:31e810237ac1 | 79 | |
emanon | 1:31e810237ac1 | 80 | //BOSH BMP085 Barometric pressure,temperature measurement |
emanon | 0:e4ca6571a751 | 81 | accelerometer.getOutput(readings); |
TakashiSasaki | 2:71f75585db19 | 82 | pc.printf("ADXL345 ------------------------\n"); |
emanon | 1:31e810237ac1 | 83 | pc.printf(" %+4.2f, %+4.2f, %+4.2f\n", |
emanon | 0:e4ca6571a751 | 84 | (float((int16_t)readings[0]+18)/256), |
emanon | 0:e4ca6571a751 | 85 | (float((int16_t)readings[1]-4 )/256), |
emanon | 0:e4ca6571a751 | 86 | (float((int16_t)readings[2]+22)/256)); |
emanon | 0:e4ca6571a751 | 87 | |
emanon | 0:e4ca6571a751 | 88 | bmp085.update(); |
emanon | 1:31e810237ac1 | 89 | |
emanon | 1:31e810237ac1 | 90 | //ADXL 345 Acceleration measurement |
TakashiSasaki | 2:71f75585db19 | 91 | pc.printf("\nBOSH BMP085 --------------------\n"); |
emanon | 1:31e810237ac1 | 92 | pc.printf(" p:%6.2f hPa / t:%6.2f C\n", bmp085.get_pressure(), bmp085.get_temperature()); |
emanon | 1:31e810237ac1 | 93 | |
emanon | 1:31e810237ac1 | 94 | //CSDS Ambient light measurement P15 analog-in1 |
emanon | 1:31e810237ac1 | 95 | pc.printf("Ambient light :: %f\n",ain_CDS*100); |
emanon | 1:31e810237ac1 | 96 | |
emanon | 1:31e810237ac1 | 97 | //Humidity measurement P16 analog-in2 |
emanon | 1:31e810237ac1 | 98 | pc.printf("Humidity :: %f\n",ain_Humedity*100); |
emanon | 1:31e810237ac1 | 99 | |
emanon | 1:31e810237ac1 | 100 | //LM35DZ Temperature measurement P20 analog-in6 |
emanon | 1:31e810237ac1 | 101 | pc.printf("Temperature :: %f\n",ain_LM35DZ*100); |
emanon | 1:31e810237ac1 | 102 | |
emanon | 0:e4ca6571a751 | 103 | } |
emanon | 0:e4ca6571a751 | 104 | } |