Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed HEPTA_CDH_lite HEPTA_COM_lite LPS25HB_I2C HEPTA_SENSOR_lite HEPTA_EPS_lite
main.cpp
00001 #include "mbed.h" 00002 #include "HEPTA_EPS.h" 00003 #include "HEPTA_CDH.h" 00004 #include "HEPTA_SENSOR.h" 00005 #include "HEPTA_COM.h" 00006 #include "LPS.h" //library for pressure sensor 00007 00008 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd"); 00009 HEPTA_EPS eps(PA_0,PA_4); 00010 HEPTA_SENSOR sensor(PA_7,PB_7,PB_6,0xD0); 00011 HEPTA_COM com(PA_9,PA_10,9600); 00012 DigitalOut condition(PB_1); 00013 DigitalOut analog_switch(PA_3); 00014 Serial sat(USBTX,USBRX, 9600); 00015 I2C i2c(PB_7, PB_6); //i2c for pressure sensor 00016 LPS ps(i2c); 00017 DigitalOut sp1(PA_1); //DigitalOut for buzzer 00018 Timer sattime; 00019 Ticker hk; 00020 Ticker sound; 00021 int flag = 0; //condition flag 00022 float batvol, temp; //voltage, temperature 00023 int rcmd=0,cmdflag=0; //command variable 00024 int i, count; 00025 float pressure = 0.0, altitude = 0.0; 00026 float ax,ay,az,gx,gy,gz; 00027 int s = 0; 00028 00029 #define mC 261.626 00030 #define mD 293.665 00031 #define mE 329.628 00032 #define mF 349.228 00033 #define mG 391.995 00034 #define mA 440.000 00035 #define mB 493.883 00036 float mm[]={mC*4,mD*4,mE*4,mF*4,mG*4,mA*4,mB*4,mC*8}; //timbre 00037 00038 // 00039 void tick(void) 00040 { 00041 sp1.write(s); 00042 s=!s; 00043 } 00044 00045 // downlink HK dsta function 00046 void hk_sensing() { 00047 com.printf("HEPTASAT::Time = %.4f [s], batvol = %.4f [V], temp = %.4f [deg C], altitude = %.4f [m]\r\n",sattime.read(),batvol,temp,altitude); 00048 com.printf(" ::ax = %.4f, ay = %.4f, az = %.4f, gx = %.4f, gy = %.4f, gz = %.4f\r\n",ax,ay,az,gx,gy,gz); 00049 00050 } 00051 00052 int main() 00053 { 00054 sat.printf("From Sat : Nominal Operation\r\n"); 00055 com.printf("From Sat : Nominal Operation\r\n"); 00056 sattime.start(); // start sat timer 00057 eps.turn_on_regulator(); //turn on 3.3V conveter 00058 analog_switch = 1; //turn on analog switch (transceiver mode) 00059 00060 // check saving to SD card 00061 mkdir("/sd/mydir", 0777); 00062 FILE *fp = fopen("/sd/mydir/sdtest.csv", "w"); 00063 if(fp == NULL) { 00064 error("Could not open file for write\r\n"); 00065 } 00066 fclose(fp); 00067 00068 // setting the pressure sensor 00069 // initialize the pressure sensor 00070 if (!ps.init()){ 00071 printf("Failed to autodetect pressure sensor!\r\n"); 00072 while (1); 00073 } 00074 ps.init(); 00075 ps.enableDefault(); 00076 00077 while(1){ 00078 com.initialize(); // communication system initialize 00079 FILE *fp = fopen("/sd/mydir/sdtest.csv", "a"); 00080 hk.attach(&hk_sensing, 1.0); // Start the Ticker 00081 for(count=0; count<10; count++){ 00082 condition = !condition; // LED blinking 00083 eps.vol(&batvol); // Get battery voltage 00084 sensor.temp_sense(&temp); // Get temperature 00085 sensor.sen_acc(&ax,&ay,&az); // Get acceleration 00086 sensor.sen_gyro(&gx,&gy,&gz); // Get gyro 00087 pressure = ps.readPressureMillibars(); // Get pressure 00088 altitude = ps.pressureToAltitudeMeters(pressure); // Get altitude 00089 // add HK data to file 00090 fprintf(fp,"%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\r\n",sattime.read(),batvol,temp,pressure,altitude,ax,ay,az,gx,gy,gz); 00091 wait_ms(100); 00092 } 00093 fclose(fp); // save the file 00094 if(sattime > 300){ 00095 //sound on 00096 for(i=0;i < sizeof(mm)/sizeof(mm[0]);i++) { 00097 sound.attach(&tick,1.0/mm[i]/2.0); 00098 wait(0.5f); 00099 } 00100 sound.detach(); 00101 } 00102 } 00103 }
Generated on Sun Aug 21 2022 08:27:49 by
1.7.2