integration with sensors
Dependencies: JPEGCamera MODGPS RHT03 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "JPEGCamera.h" 00003 #include "RHT03.h" 00004 #include "GPS.h" 00005 00006 00007 DigitalOut myled1(LED1); //show successful picture was taken 00008 DigitalOut myled2(LED2); //show end of sequence 00009 DigitalOut myled3(LED3); //show picture take failed 00010 DigitalOut myled4(LED4); //show camera is not ready 00011 00012 Serial pc(USBTX, USBRX); // tx, rx 00013 /*Xbee Start*/ 00014 00015 Serial XBee(p13, p14); 00016 GPS gps(NC,p27); 00017 00018 // SET THIS. 00019 // Create an instance of the GPS object. You will need to 00020 00021 // your GPS module to. 00022 00023 00024 char rmc[GPS_BUFFER_LEN]; 00025 char gga[GPS_BUFFER_LEN]; 00026 char vtg[GPS_BUFFER_LEN]; 00027 char ukn[GPS_BUFFER_LEN]; 00028 00029 // 0.1 second flash of LED2 00030 DigitalOut led2(LED2); 00031 Timeout t2; 00032 int j=0;// camera variable 00033 void t2out(void) 00034 { 00035 led2 = 0; 00036 } 00037 void blip2(void) 00038 { 00039 led2 = 1; 00040 t2.attach(&t2out, 0.1); 00041 } 00042 00043 // 0.1 second flash of LED3 00044 DigitalOut led3(LED3); 00045 Timeout t3; 00046 void t3out(void) 00047 { 00048 led3 = 0; 00049 } 00050 void blip3(void) 00051 { 00052 led3 = 1; 00053 t3.attach(&t3out, 0.1); 00054 } 00055 00056 // 0.1 second flash of LED4 00057 DigitalOut led4(LED4); 00058 00059 Timeout t4; 00060 void t4out(void) 00061 { 00062 led4 = 0; 00063 } 00064 void blip4(void) 00065 { 00066 led4 = 1; 00067 t4.attach(&t4out, 0.1); 00068 } 00069 ///////////////////////////////////////////////////////////// 00070 void gps_call(void); 00071 00072 void temp_hum(void); 00073 00074 void cam_call(void); 00075 00076 GPS_Time q1; 00077 JPEGCamera camera(p9, p10); // TX, RX 00078 00079 int main() 00080 { 00081 00082 //////////////////////////////////////////////////////////////////// 00083 00084 // SET THIS. 00085 // Ensure you set the baud rate to match your serial 00086 // communications to your PC/Max/Linux host so you 00087 // can read the messages. 00088 pc.printf("setting the PC baud rate \n"); 00089 pc.baud(9600); 00090 00091 00092 // Tell MODGPS "we want copies of the NMEA sentences". When a callback 00093 // is made our buffers will contain a copy of the last received sentence 00094 // before it was processed/destroyed. 00095 gps.setRmc(rmc); 00096 gps.setGga(gga); 00097 gps.setVtg(vtg); 00098 gps.setUkn(ukn); 00099 00100 00101 // SET THIS. 00102 // Most GPS modules use 9600,8,n,1 so that's what 00103 // we default to here. Ensure your GPS module matches 00104 // this, otherwise set it to match. 00105 pc.printf("setting the GPS baud rate \n"); 00106 gps.baud(9600); 00107 gps.format(8, GPS::None, 1); 00108 00109 // OPTIONAL 00110 // If you GPS has a 1 pulse per second output you can 00111 // connect it to an Mbed pin. Here you specify what pin 00112 // and on what "edge" teh signal is active. If your GPS 00113 // module has a rising edge at the one second point then 00114 // use GPS::ppsRise 00115 #ifdef PPSPIN 00116 gps.ppsAttach(PPSPIN, GPS::ppsFall); 00117 #endif 00118 00119 // Sample of a callback to a function when the 1PPS activates. 00120 // For this example, we flash LED2 for 0.1 second. 00121 gps.attach_pps(&blip2); 00122 00123 // Sample of a callback to a function when a NMEA GGA message is recieved. 00124 // For this example, we flash LED2 for 0.1 second. 00125 gps.attach_gga(&blip3); 00126 00127 // Sample of a callback to a function when a NMEA RMC message is recieved. 00128 // For this example, we flash LED2 for 0.1 second. 00129 gps.attach_rmc(&blip4); 00130 00131 00132 00133 // Camera Code 00134 pc.printf("Loading camera module \n"); 00135 LocalFileSystem local("local"); //save images on mbed 00136 camera.setPictureSize(JPEGCamera::SIZE320x240); 00137 pc.printf("getting ready for the while loop! \n"); 00138 00139 //////////////////////////////////////////////////////////////////// 00140 int i; 00141 for(i=1;i<11;i++) 00142 {//gps 00143 gps_call(); 00144 00145 00146 00147 if(i==1||i==5||i==10) 00148 {//temp&hum 00149 temp_hum(); 00150 } 00151 if(i%2==0) 00152 {//camera 00153 cam_call(); 00154 00155 } 00156 00157 } 00158 } 00159 00160 void gps_call(void) 00161 { 00162 // GPS Code 00163 pc.printf("Turning inside the loop() \n"); 00164 // Every 3 seconds, flip LED1 and print the basic GPS info. 00165 pc.printf("hello GPS \n"); 00166 00167 myled1 = 1; 00168 00169 // Demonstrate how to find out the GPS location co-ords. 00170 pc.printf("Method 1. Lat = %.4f ", gps.latitude()); 00171 XBee.printf("Method 1. Lat = %.4f ", gps.latitude()); 00172 00173 pc.printf("Lon = %.4f ", gps.longitude()); 00174 XBee.printf("Lon = %.4f ", gps.longitude()); 00175 00176 pc.printf("Alt = %.4f ", gps.altitude()); 00177 XBee.printf("Alt = %.4f ", gps.altitude()); 00178 00179 00180 // Gran a snapshot of the current time. 00181 gps.timeNow(&q1); 00182 pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", 00183 q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); 00184 XBee.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", 00185 q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); 00186 } 00187 void temp_hum(void) 00188 { 00189 //Temperature Sensor Code 00190 pc.printf("hello TEMP"); 00191 00192 int done=0; 00193 float temp,hum; 00194 00195 RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to) 00196 00197 while(!done) { //Loop keeps running until RHT03 is read succesfully 00198 wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly 00199 if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03 00200 } 00201 00202 temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade 00203 hum = humtemp.getHumidity(); //Gets the current humidity in percentage 00204 00205 pc.printf("Temperature is %f C \r",temp); 00206 XBee.printf("Temperature is %f C \r\n",temp); 00207 00208 00209 pc.printf("Humidity is %f % \r\n",hum); 00210 XBee.printf("Humidity is %f % \r\n",hum); 00211 00212 00213 00214 ///////////////////////////////////////////////// 00215 00216 } 00217 00218 void cam_call(void) 00219 { 00220 //camera Code 00221 j++; 00222 Timer timer; 00223 pc.printf("starting timer..."); 00224 timer.start(); 00225 pc.printf("hello CAMERA"); 00226 00227 if (camera.isReady()) { 00228 char filename[32]; 00229 sprintf(filename, "/local/pict%03d.jpg", j); 00230 printf("Picture: %s ", filename); 00231 if (camera.takePicture(filename)) { 00232 while (camera.isProcessing()) { 00233 camera.processPicture(); 00234 } 00235 myled1 = 1; //show successful picture was taken 00236 00237 myled1 = 0; 00238 } else { 00239 printf("take picture failed "); 00240 myled3 = 1; //show picture take failed 00241 00242 myled3 = 0; 00243 } 00244 } else { 00245 printf("camera is not ready "); 00246 myled4 = 1; //show camera is not ready 00247 00248 myled4 = 0; 00249 } 00250 00251 myled2 = 1; //show end of sequence 00252 00253 myled2 = 0; 00254 printf("time = %f\n", timer.read()); 00255 //////////////////////////////////////////////////// 00256 00257 //Xbee Code 00258 00259 pc.printf("i'm Sending......."); 00260 00261 00262 00263 00264 ///////////////////////////////////////////// 00265 00266 }
Generated on Fri Jul 15 2022 04:21:13 by 1.7.2