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