![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
commit
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
main.cpp@0:203cf529f52a, 2017-09-14 (annotated)
- Committer:
- suads
- Date:
- Thu Sep 14 16:50:16 2017 +0000
- Revision:
- 0:203cf529f52a
- Child:
- 1:75966605a6a3
MPU_SD_CARD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suads | 0:203cf529f52a | 1 | #include "mbed.h" |
suads | 0:203cf529f52a | 2 | #include "SDFileSystem.h" |
suads | 0:203cf529f52a | 3 | #include "SIM5320.h" |
suads | 0:203cf529f52a | 4 | #include "MPU6050.h" |
suads | 0:203cf529f52a | 5 | #include "SensorBoards.h" |
suads | 0:203cf529f52a | 6 | #include "WakeUp.h" |
suads | 0:203cf529f52a | 7 | |
suads | 0:203cf529f52a | 8 | |
suads | 0:203cf529f52a | 9 | |
suads | 0:203cf529f52a | 10 | uint8_t write_sd_buffer[12]; |
suads | 0:203cf529f52a | 11 | void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id); |
suads | 0:203cf529f52a | 12 | //SIM5320 sim5320(PA_9,PA_10); |
suads | 0:203cf529f52a | 13 | DigitalOut SIM5320_PWR(PA_1); |
suads | 0:203cf529f52a | 14 | DigitalOut SIM_PWR_KEY(PA_15); |
suads | 0:203cf529f52a | 15 | InterruptIn mpuInterrupt(PB_6); |
suads | 0:203cf529f52a | 16 | uint8_t sensor_board_readings[4]; |
suads | 0:203cf529f52a | 17 | bool test = false; |
suads | 0:203cf529f52a | 18 | // MOSI, MISO, SCLK, CS, name |
suads | 0:203cf529f52a | 19 | SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd"); |
suads | 0:203cf529f52a | 20 | |
suads | 0:203cf529f52a | 21 | int go_to_sleep = 0; |
suads | 0:203cf529f52a | 22 | void mpuInterruptCallback() |
suads | 0:203cf529f52a | 23 | { |
suads | 0:203cf529f52a | 24 | test=!test; |
suads | 0:203cf529f52a | 25 | |
suads | 0:203cf529f52a | 26 | } |
suads | 0:203cf529f52a | 27 | void rtc_wakeup() |
suads | 0:203cf529f52a | 28 | { |
suads | 0:203cf529f52a | 29 | go_to_sleep = 1; |
suads | 0:203cf529f52a | 30 | } |
suads | 0:203cf529f52a | 31 | |
suads | 0:203cf529f52a | 32 | MPU6050 mpu; |
suads | 0:203cf529f52a | 33 | int main() |
suads | 0:203cf529f52a | 34 | { |
suads | 0:203cf529f52a | 35 | /////////////////////////////////////////////////MPU_DEEP_SLEEP_WAKEUP//////////////////////////// |
suads | 0:203cf529f52a | 36 | /* |
suads | 0:203cf529f52a | 37 | mpuInterrupt.fall(mpuInterruptCallback); |
suads | 0:203cf529f52a | 38 | wait(2); |
suads | 0:203cf529f52a | 39 | mpu.calibrate(accelBias, gyroBias); |
suads | 0:203cf529f52a | 40 | mpu.initialize(); |
suads | 0:203cf529f52a | 41 | mpu.setSleepEnabled(0); |
suads | 0:203cf529f52a | 42 | wait(2); |
suads | 0:203cf529f52a | 43 | mpu.setIntFreefallEnabled(1); |
suads | 0:203cf529f52a | 44 | mpu.setIntZeroMotionEnabled(0); |
suads | 0:203cf529f52a | 45 | mpu.setIntMotionEnabled(1); |
suads | 0:203cf529f52a | 46 | printf("Setting mpu parameters...\r\n"); |
suads | 0:203cf529f52a | 47 | mpu.setMotionDetectionThreshold(1); |
suads | 0:203cf529f52a | 48 | mpu.setMotionDetectionDuration(15); |
suads | 0:203cf529f52a | 49 | |
suads | 0:203cf529f52a | 50 | while(1){ |
suads | 0:203cf529f52a | 51 | printf("sleep\r\n"); |
suads | 0:203cf529f52a | 52 | deepsleep(); |
suads | 0:203cf529f52a | 53 | if(test){ |
suads | 0:203cf529f52a | 54 | wait(1); |
suads | 0:203cf529f52a | 55 | printf("Desio se motion\r\n"); |
suads | 0:203cf529f52a | 56 | test = 0; |
suads | 0:203cf529f52a | 57 | } |
suads | 0:203cf529f52a | 58 | } |
suads | 0:203cf529f52a | 59 | */ |
suads | 0:203cf529f52a | 60 | |
suads | 0:203cf529f52a | 61 | /////////////////////////////////////////////////////////////////////////////////////////// |
suads | 0:203cf529f52a | 62 | |
suads | 0:203cf529f52a | 63 | // wait(3); |
suads | 0:203cf529f52a | 64 | // SIM5320_PWR = 1; |
suads | 0:203cf529f52a | 65 | // SIM_PWR_KEY = 1; |
suads | 0:203cf529f52a | 66 | // wait(1); |
suads | 0:203cf529f52a | 67 | // SIM_PWR_KEY = 0; |
suads | 0:203cf529f52a | 68 | /* |
suads | 0:203cf529f52a | 69 | wait(25); |
suads | 0:203cf529f52a | 70 | wait(2); |
suads | 0:203cf529f52a | 71 | printf("Starting...\r\n"); |
suads | 0:203cf529f52a | 72 | printf("Starting...\r\n"); |
suads | 0:203cf529f52a | 73 | printf("Starting...\r\n"); |
suads | 0:203cf529f52a | 74 | printf("Starting...\r\n"); |
suads | 0:203cf529f52a | 75 | sim5320.sendCommand("AT+CNUM",2); |
suads | 0:203cf529f52a | 76 | printf("Checking credit balance...\r\n"); |
suads | 0:203cf529f52a | 77 | sim5320.sendCommand("AT+CUSD=1, \"*100#\",15",5); |
suads | 0:203cf529f52a | 78 | //Testing GPS |
suads | 0:203cf529f52a | 79 | |
suads | 0:203cf529f52a | 80 | sim5320.enableGPS(true); |
suads | 0:203cf529f52a | 81 | wait(30); |
suads | 0:203cf529f52a | 82 | |
suads | 0:203cf529f52a | 83 | //Gettting GPS location |
suads | 0:203cf529f52a | 84 | sim5320.sendCommand("AT+CGPSINFO",2); |
suads | 0:203cf529f52a | 85 | sim5320.sendCommand("AT+CGPSINFO",2); |
suads | 0:203cf529f52a | 86 | sim5320.sendCommand("AT+CGPSINFO",2); |
suads | 0:203cf529f52a | 87 | |
suads | 0:203cf529f52a | 88 | |
suads | 0:203cf529f52a | 89 | |
suads | 0:203cf529f52a | 90 | //Testing network connection and disconnection |
suads | 0:203cf529f52a | 91 | sim5320.connect("active.bhmobile.ba","",""); |
suads | 0:203cf529f52a | 92 | wait(2); |
suads | 0:203cf529f52a | 93 | if(sim5320.disconnect()) { |
suads | 0:203cf529f52a | 94 | printf("Disconnected\r\n"); |
suads | 0:203cf529f52a | 95 | } |
suads | 0:203cf529f52a | 96 | |
suads | 0:203cf529f52a | 97 | else { |
suads | 0:203cf529f52a | 98 | printf("Still connected or error occured!\r\n"); |
suads | 0:203cf529f52a | 99 | } |
suads | 0:203cf529f52a | 100 | |
suads | 0:203cf529f52a | 101 | |
suads | 0:203cf529f52a | 102 | |
suads | 0:203cf529f52a | 103 | while(1) { |
suads | 0:203cf529f52a | 104 | wait(1); |
suads | 0:203cf529f52a | 105 | sim5320.sendCommand("AT",1); |
suads | 0:203cf529f52a | 106 | } |
suads | 0:203cf529f52a | 107 | */ |
suads | 0:203cf529f52a | 108 | |
suads | 0:203cf529f52a | 109 | |
suads | 0:203cf529f52a | 110 | |
suads | 0:203cf529f52a | 111 | /////////////////////////////////////////////////RTC_DEEP_SLEEP_WAKEUP//////////////////////////// |
suads | 0:203cf529f52a | 112 | /* |
suads | 0:203cf529f52a | 113 | set_time(1495040081); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
suads | 0:203cf529f52a | 114 | WakeUp::attach(&rtc_wakeup); |
suads | 0:203cf529f52a | 115 | WakeUp::calibrate(); |
suads | 0:203cf529f52a | 116 | while (1) { |
suads | 0:203cf529f52a | 117 | WakeUp::set_ms(5000); |
suads | 0:203cf529f52a | 118 | time_t seconds = time(NULL); |
suads | 0:203cf529f52a | 119 | printf("Time = %s\n", ctime(&seconds)); |
suads | 0:203cf529f52a | 120 | wait(1); |
suads | 0:203cf529f52a | 121 | printf("sleep\n"); |
suads | 0:203cf529f52a | 122 | deepsleep(); |
suads | 0:203cf529f52a | 123 | if (go_to_sleep == 1) { |
suads | 0:203cf529f52a | 124 | wait(1); |
suads | 0:203cf529f52a | 125 | printf("Wake_up\n"); |
suads | 0:203cf529f52a | 126 | go_to_sleep=0; |
suads | 0:203cf529f52a | 127 | } |
suads | 0:203cf529f52a | 128 | } |
suads | 0:203cf529f52a | 129 | */ |
suads | 0:203cf529f52a | 130 | //////////////////////////////////////////////////////////////////////////////////////////////// |
suads | 0:203cf529f52a | 131 | |
suads | 0:203cf529f52a | 132 | |
suads | 0:203cf529f52a | 133 | |
suads | 0:203cf529f52a | 134 | //////////////////////////////////////////////CODE FOR SENDOR_BOARDS//////////////////////////////////////////////////////////////// |
suads | 0:203cf529f52a | 135 | /* |
suads | 0:203cf529f52a | 136 | uint8_t IDBuffer[8]; |
suads | 0:203cf529f52a | 137 | uint8_t IDMeasure[4]; |
suads | 0:203cf529f52a | 138 | float measure=0.0; |
suads | 0:203cf529f52a | 139 | float measure2=0.0; |
suads | 0:203cf529f52a | 140 | |
suads | 0:203cf529f52a | 141 | |
suads | 0:203cf529f52a | 142 | SensorBoards B1; |
suads | 0:203cf529f52a | 143 | B1.getSensorReadings(0x4a,0x10,IDMeasure); |
suads | 0:203cf529f52a | 144 | printf("number_of__boards= %d\n",B1.numberOfBoards); |
suads | 0:203cf529f52a | 145 | B1.sensorBoardScanner(); |
suads | 0:203cf529f52a | 146 | printf("SnesorBoardAdress= %d\n",B1.boards[0].I2CAddress); |
suads | 0:203cf529f52a | 147 | B1.getSensorNumbers(); |
suads | 0:203cf529f52a | 148 | printf("SensorBoardsensors= %d\n",B1.boards[0].numberOfSensors); |
suads | 0:203cf529f52a | 149 | B1.getSensorIDs(); |
suads | 0:203cf529f52a | 150 | printf("SensorBoardIDs=%d %d \n",B1.boards[0].sensorIDs[0],B1.boards[0].sensorIDs[1]); |
suads | 0:203cf529f52a | 151 | |
suads | 0:203cf529f52a | 152 | B1.getSensorReadings(0x4a,0x10,IDMeasure); |
suads | 0:203cf529f52a | 153 | |
suads | 0:203cf529f52a | 154 | for(int k=0; k<1; k++) { |
suads | 0:203cf529f52a | 155 | printf("broj senzora %d \n",B1.boards[k].numberOfSensors); |
suads | 0:203cf529f52a | 156 | for(int i=0; i<B1.boards[k].numberOfSensors; i++){ |
suads | 0:203cf529f52a | 157 | B1.getSensorReadings(B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i],IDMeasure); |
suads | 0:203cf529f52a | 158 | printf("measure=%d %d %d %d keaj\n",IDMeasure[0],IDMeasure[1],IDMeasure[2],IDMeasure[3]); |
suads | 0:203cf529f52a | 159 | //create_sensor_data(write_sd_buffer,IDMeasure,B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i]); |
suads | 0:203cf529f52a | 160 | } |
suads | 0:203cf529f52a | 161 | } |
suads | 0:203cf529f52a | 162 | |
suads | 0:203cf529f52a | 163 | for(int i=0;i<12;i++) |
suads | 0:203cf529f52a | 164 | printf("_%d\n",write_sd_buffer[i]); |
suads | 0:203cf529f52a | 165 | */ |
suads | 0:203cf529f52a | 166 | |
suads | 0:203cf529f52a | 167 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
suads | 0:203cf529f52a | 168 | |
suads | 0:203cf529f52a | 169 | |
suads | 0:203cf529f52a | 170 | |
suads | 0:203cf529f52a | 171 | return 0; |
suads | 0:203cf529f52a | 172 | } |
suads | 0:203cf529f52a | 173 | void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id) |
suads | 0:203cf529f52a | 174 | { |
suads | 0:203cf529f52a | 175 | //pcf8563_read(&rtc); |
suads | 0:203cf529f52a | 176 | |
suads | 0:203cf529f52a | 177 | write_sd_buffer[0]=0; |
suads | 0:203cf529f52a | 178 | write_sd_buffer[1]=1; |
suads | 0:203cf529f52a | 179 | write_sd_buffer[2]=2; |
suads | 0:203cf529f52a | 180 | write_sd_buffer[3]=3; |
suads | 0:203cf529f52a | 181 | write_sd_buffer[4]=4; |
suads | 0:203cf529f52a | 182 | write_sd_buffer[5] =b_id; //sensor boaard id |
suads | 0:203cf529f52a | 183 | write_sd_buffer[6] =s_id; //sensor id |
suads | 0:203cf529f52a | 184 | write_sd_buffer[7] =sensor_board_readings[3]; //sensor reading |
suads | 0:203cf529f52a | 185 | write_sd_buffer[8] =sensor_board_readings[2]; //sensor reading |
suads | 0:203cf529f52a | 186 | write_sd_buffer[9] =sensor_board_readings[1]; //sensor reading |
suads | 0:203cf529f52a | 187 | write_sd_buffer[10]=sensor_board_readings[0]; //sensor reading |
suads | 0:203cf529f52a | 188 | write_sd_buffer[11]=0xFF; |
suads | 0:203cf529f52a | 189 | write_sd_buffer[12]=0xFF; |
suads | 0:203cf529f52a | 190 | |
suads | 0:203cf529f52a | 191 | } |