![](/media/cache/profiles/6f7790bb54a7c5d3dea27385488a604a.jpg.50x50_q85.jpg)
putting strings to xbee
Dependencies: BMP085 SDFileSystem mbed JPEGCamera
Fork of SaibiCansat2014 by
main.cpp@0:e4ca6571a751, 2014-07-11 (annotated)
- Committer:
- emanon
- Date:
- Fri Jul 11 21:36:20 2014 +0000
- Revision:
- 0:e4ca6571a751
- Child:
- 1:31e810237ac1
test
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 | 0:e4ca6571a751 | 14 | DigitalOut myled(LED1); |
emanon | 0:e4ca6571a751 | 15 | |
emanon | 0:e4ca6571a751 | 16 | int fileio() { |
emanon | 0:e4ca6571a751 | 17 | mkdir("/sd/20014", 0777); |
emanon | 0:e4ca6571a751 | 18 | |
emanon | 0:e4ca6571a751 | 19 | FILE *fp = fopen("/sd/mydir/datalog.txt", "w"); |
emanon | 0:e4ca6571a751 | 20 | if(fp == NULL) { |
emanon | 0:e4ca6571a751 | 21 | error("Could not open file for write\n"); |
emanon | 0:e4ca6571a751 | 22 | } |
emanon | 0:e4ca6571a751 | 23 | fprintf(fp, "Hello fun SD Card World!"); |
emanon | 0:e4ca6571a751 | 24 | fclose(fp); |
emanon | 0:e4ca6571a751 | 25 | |
emanon | 0:e4ca6571a751 | 26 | printf("Goodbye World!\n"); |
emanon | 0:e4ca6571a751 | 27 | |
emanon | 0:e4ca6571a751 | 28 | return(0); |
emanon | 0:e4ca6571a751 | 29 | } |
emanon | 0:e4ca6571a751 | 30 | |
emanon | 0:e4ca6571a751 | 31 | |
emanon | 0:e4ca6571a751 | 32 | int main() { |
emanon | 0:e4ca6571a751 | 33 | myled = 1; |
emanon | 0:e4ca6571a751 | 34 | |
emanon | 0:e4ca6571a751 | 35 | pc.baud(115200); |
emanon | 0:e4ca6571a751 | 36 | |
emanon | 0:e4ca6571a751 | 37 | int readings[3] = {0, 0, 0}; |
emanon | 0:e4ca6571a751 | 38 | |
emanon | 0:e4ca6571a751 | 39 | pc.printf("Starting ADXL345 test...\n"); |
emanon | 0:e4ca6571a751 | 40 | wait(.001); |
emanon | 0:e4ca6571a751 | 41 | pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); |
emanon | 0:e4ca6571a751 | 42 | wait(.001); |
emanon | 0:e4ca6571a751 | 43 | |
emanon | 0:e4ca6571a751 | 44 | // These are here to test whether any of the initialization fails. It will print the failure |
emanon | 0:e4ca6571a751 | 45 | if (accelerometer.setPowerControl(0x00)){ |
emanon | 0:e4ca6571a751 | 46 | pc.printf("didn't intitialize power control\n"); |
emanon | 0:e4ca6571a751 | 47 | return 0; |
emanon | 0:e4ca6571a751 | 48 | } |
emanon | 0:e4ca6571a751 | 49 | //Full resolution, +/-16g, 4mg/LSB. |
emanon | 0:e4ca6571a751 | 50 | wait(.001); |
emanon | 0:e4ca6571a751 | 51 | |
emanon | 0:e4ca6571a751 | 52 | if(accelerometer.setDataFormatControl(0x0B)){ |
emanon | 0:e4ca6571a751 | 53 | pc.printf("didn't set data format\n"); |
emanon | 0:e4ca6571a751 | 54 | return 0; } |
emanon | 0:e4ca6571a751 | 55 | wait(.001); |
emanon | 0:e4ca6571a751 | 56 | |
emanon | 0:e4ca6571a751 | 57 | //3.2kHz data rate. |
emanon | 0:e4ca6571a751 | 58 | if(accelerometer.setDataRate(ADXL345_3200HZ)){ |
emanon | 0:e4ca6571a751 | 59 | pc.printf("didn't set data rate\n"); |
emanon | 0:e4ca6571a751 | 60 | return 0; |
emanon | 0:e4ca6571a751 | 61 | } |
emanon | 0:e4ca6571a751 | 62 | wait(.001); |
emanon | 0:e4ca6571a751 | 63 | |
emanon | 0:e4ca6571a751 | 64 | //Measurement mode. |
emanon | 0:e4ca6571a751 | 65 | |
emanon | 0:e4ca6571a751 | 66 | if(accelerometer.setPowerControl(MeasurementMode)) { |
emanon | 0:e4ca6571a751 | 67 | pc.printf("didn't set the power control to measurement\n"); |
emanon | 0:e4ca6571a751 | 68 | return 0; |
emanon | 0:e4ca6571a751 | 69 | } |
emanon | 0:e4ca6571a751 | 70 | myled = 0; |
emanon | 0:e4ca6571a751 | 71 | |
emanon | 0:e4ca6571a751 | 72 | while (1) { |
emanon | 0:e4ca6571a751 | 73 | wait(0.1); |
emanon | 0:e4ca6571a751 | 74 | |
emanon | 0:e4ca6571a751 | 75 | accelerometer.getOutput(readings); |
emanon | 0:e4ca6571a751 | 76 | pc.printf("%+4.2f, %+4.2f, %+4.2f\n", |
emanon | 0:e4ca6571a751 | 77 | (float((int16_t)readings[0]+18)/256), |
emanon | 0:e4ca6571a751 | 78 | (float((int16_t)readings[1]-4 )/256), |
emanon | 0:e4ca6571a751 | 79 | (float((int16_t)readings[2]+22)/256)); |
emanon | 0:e4ca6571a751 | 80 | |
emanon | 0:e4ca6571a751 | 81 | bmp085.update(); |
emanon | 0:e4ca6571a751 | 82 | pc.printf("p:%6.2f hPa / t:%6.2f C\n", bmp085.get_pressure(), bmp085.get_temperature()); |
emanon | 0:e4ca6571a751 | 83 | wait(2); |
emanon | 0:e4ca6571a751 | 84 | } |
emanon | 0:e4ca6571a751 | 85 | } |