CLTP統合検証プログラム_気圧とxbeeのみで,圧電スピーカの実装が必要

Dependencies:   mbed HEPTA_CDH_lite LPS25HB_I2C

Committer:
wasabimal
Date:
Tue Aug 16 10:05:12 2022 +0000
Revision:
2:bc6e512b58ac
Parent:
1:ddac5ec89167
Child:
3:08260b6b0828
aq

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heptasat2021 0:da0f6aca15b8 1 #include "mbed.h"
wasabimal 2:bc6e512b58ac 2 #include "LPS.h"
heptasat2021 1:ddac5ec89167 3 #include "HEPTA_CDH.h"
wasabimal 2:bc6e512b58ac 4 Timer t;
wasabimal 2:bc6e512b58ac 5 Serial pc(USBTX, USBRX); // tx, rx
wasabimal 2:bc6e512b58ac 6 Serial xbee(D1, D0); // tx, rx
wasabimal 2:bc6e512b58ac 7 I2C i2c(D4,D5);
wasabimal 2:bc6e512b58ac 8 LPS ps(i2c);
heptasat2021 1:ddac5ec89167 9 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd");
wasabimal 2:bc6e512b58ac 10 Ticker press;
wasabimal 2:bc6e512b58ac 11 int i;
wasabimal 2:bc6e512b58ac 12 int ct = 0;
wasabimal 2:bc6e512b58ac 13 float pressure = 0;
wasabimal 2:bc6e512b58ac 14 float altitude = 0;
wasabimal 2:bc6e512b58ac 15 float temperature = 0;
wasabimal 2:bc6e512b58ac 16 char cmd1,cmd2,cmd3;
wasabimal 2:bc6e512b58ac 17 void pre() {
wasabimal 2:bc6e512b58ac 18 xbee.printf("%.2f %.2f %.2f \r\n",pressure,altitude,temperature);
wasabimal 2:bc6e512b58ac 19 }
wasabimal 2:bc6e512b58ac 20 int main() {//1
wasabimal 2:bc6e512b58ac 21 //Display from satellite to PC via xbee.
wasabimal 2:bc6e512b58ac 22 pc.printf("settig start\r\n");
wasabimal 2:bc6e512b58ac 23 xbee.printf("settig start\r\n");
wasabimal 2:bc6e512b58ac 24
wasabimal 2:bc6e512b58ac 25 //Create a file to save the data acquired from the sensor to a microSD card
wasabimal 2:bc6e512b58ac 26 //Also, if there is no microSD card, this error statement will be displayed
heptasat2021 1:ddac5ec89167 27 mkdir("/sd/mydir", 0777);
heptasat2021 1:ddac5ec89167 28 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
heptasat2021 1:ddac5ec89167 29 if(fp == NULL) {
heptasat2021 1:ddac5ec89167 30 error("Could not open file for write\r\n");
heptasat2021 0:da0f6aca15b8 31 }
wasabimal 2:bc6e512b58ac 32
wasabimal 2:bc6e512b58ac 33 //If there is no Barometric Pressure Sensors, this error statement will appear in teraterm
wasabimal 2:bc6e512b58ac 34 if (!ps.init()){//2
wasabimal 2:bc6e512b58ac 35 printf("Failed to autodetect pressure sensor!\r\n");
wasabimal 2:bc6e512b58ac 36 while (1);
wasabimal 2:bc6e512b58ac 37 }//2
wasabimal 2:bc6e512b58ac 38 ps.enableDefault();
wasabimal 2:bc6e512b58ac 39
wasabimal 2:bc6e512b58ac 40 //Display "begin" in teraterm and save it to SDcard
wasabimal 2:bc6e512b58ac 41 pc.printf("begin\r\n");
wasabimal 2:bc6e512b58ac 42 xbee.printf("begin\r\n");
wasabimal 2:bc6e512b58ac 43 fprintf(fp,"begin\r\n");
wasabimal 2:bc6e512b58ac 44 for (;;) {//2
wasabimal 2:bc6e512b58ac 45 //if (pc.readable()) xbee.putc(pc.getc());
wasabimal 2:bc6e512b58ac 46 if (xbee.readable()) {//3
wasabimal 2:bc6e512b58ac 47 pc.putc(xbee.getc());
wasabimal 2:bc6e512b58ac 48 cmd1 = xbee.getc();
wasabimal 2:bc6e512b58ac 49 //char cmd1 = xbee.getc();//cmd共有
wasabimal 2:bc6e512b58ac 50
wasabimal 2:bc6e512b58ac 51 //Input "m", the sensor data is displayed on the teraterm.
wasabimal 2:bc6e512b58ac 52 //And the acquired data is saved to the SD card.
wasabimal 2:bc6e512b58ac 53 if(cmd1 == 'm'){//4
wasabimal 2:bc6e512b58ac 54 pc.printf("start\r\n");
wasabimal 2:bc6e512b58ac 55 fprintf(fp,"start\r\n");
wasabimal 2:bc6e512b58ac 56 xbee.printf("start\r\n");
wasabimal 2:bc6e512b58ac 57 t.start();
wasabimal 2:bc6e512b58ac 58
wasabimal 2:bc6e512b58ac 59 cmd1 = '\0';
wasabimal 2:bc6e512b58ac 60
wasabimal 2:bc6e512b58ac 61 pc.printf("p [mbar]\ta [m]\tdeg [C]\r\n");
wasabimal 2:bc6e512b58ac 62 xbee.printf("p [mbar]\ta [m]\tdeg [C]\r\n");
wasabimal 2:bc6e512b58ac 63 fprintf(fp,"p [mbar]\ta [m]\tdeg [C]\r\n");
wasabimal 2:bc6e512b58ac 64 fclose(fp);
wasabimal 2:bc6e512b58ac 65 press.attach(&pre, 0.1);
wasabimal 2:bc6e512b58ac 66 //Save sensor acquisition data to SD card every 10 times
wasabimal 2:bc6e512b58ac 67 while(1){//5
wasabimal 2:bc6e512b58ac 68 FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
wasabimal 2:bc6e512b58ac 69 for(i = 0;i<10;i++){//6
wasabimal 2:bc6e512b58ac 70 pressure = ps.readPressureMillibars();
wasabimal 2:bc6e512b58ac 71 altitude = ps.pressureToAltitudeMeters(pressure);
wasabimal 2:bc6e512b58ac 72 temperature = ps.readTemperatureC();
wasabimal 2:bc6e512b58ac 73 fprintf(fp,"%d %.2f\t \t%.2f \t%.2f \r\n",ct,pressure,altitude,temperature);
wasabimal 2:bc6e512b58ac 74 ct = ct + 1;
wasabimal 2:bc6e512b58ac 75 //if (pc.readable()) xbee.putc(pc.getc());
wasabimal 2:bc6e512b58ac 76 if (xbee.readable()){//7
wasabimal 2:bc6e512b58ac 77 pc.putc(xbee.getc());
wasabimal 2:bc6e512b58ac 78 cmd2 = xbee.getc();
wasabimal 2:bc6e512b58ac 79 //char cmd2 = xbee.getc();
wasabimal 2:bc6e512b58ac 80 //xbee.printf("%c\r\n",cmd);
wasabimal 2:bc6e512b58ac 81 if(cmd2 == 'n'){//8
wasabimal 2:bc6e512b58ac 82 press.detach();
wasabimal 2:bc6e512b58ac 83 pc.printf("end\r\n");
wasabimal 2:bc6e512b58ac 84 pc.printf("time = %f",t.read());
wasabimal 2:bc6e512b58ac 85 fprintf(fp,"time = %f",t.read());
wasabimal 2:bc6e512b58ac 86 t.stop();
wasabimal 2:bc6e512b58ac 87 fclose(fp);
wasabimal 2:bc6e512b58ac 88 cmd2 = '\0';
wasabimal 2:bc6e512b58ac 89 return 0;
wasabimal 2:bc6e512b58ac 90 }//8
wasabimal 2:bc6e512b58ac 91 }//7
wasabimal 2:bc6e512b58ac 92 wait_us(1);
wasabimal 2:bc6e512b58ac 93 }//6
wasabimal 2:bc6e512b58ac 94 fclose(fp);
wasabimal 2:bc6e512b58ac 95 }//5
wasabimal 2:bc6e512b58ac 96 }//4
wasabimal 2:bc6e512b58ac 97 }//3
wasabimal 2:bc6e512b58ac 98 }//2
wasabimal 2:bc6e512b58ac 99 }//1