integration with sensors
Dependencies: JPEGCamera MODGPS RHT03 mbed
Revision 0:a93721ad3c1a, committed 2013-09-16
- Comitter:
- aldih
- Date:
- Mon Sep 16 14:02:57 2013 +0000
- Commit message:
- integration between camera , Gps ,temperature sensor ,humidity and zigbee.
Changed in this revision
diff -r 000000000000 -r a93721ad3c1a JPEGCamera.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/JPEGCamera.lib Mon Sep 16 14:02:57 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/yamaguch/code/JPEGCamera/#27417b6a951d
diff -r 000000000000 -r a93721ad3c1a MODGPS.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODGPS.lib Mon Sep 16 14:02:57 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mprinke/code/MODGPS/#34a9030f27a4
diff -r 000000000000 -r a93721ad3c1a RHT03.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RHT03.lib Mon Sep 16 14:02:57 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tristanjph/code/RHT03/#153e20f26d54
diff -r 000000000000 -r a93721ad3c1a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 16 14:02:57 2013 +0000 @@ -0,0 +1,266 @@ +#include "mbed.h" +#include "JPEGCamera.h" +#include "RHT03.h" +#include "GPS.h" + + +DigitalOut myled1(LED1); //show successful picture was taken +DigitalOut myled2(LED2); //show end of sequence +DigitalOut myled3(LED3); //show picture take failed +DigitalOut myled4(LED4); //show camera is not ready + +Serial pc(USBTX, USBRX); // tx, rx +/*Xbee Start*/ + +Serial XBee(p13, p14); +GPS gps(NC,p27); + +// SET THIS. +// Create an instance of the GPS object. You will need to + +// your GPS module to. + + +char rmc[GPS_BUFFER_LEN]; +char gga[GPS_BUFFER_LEN]; +char vtg[GPS_BUFFER_LEN]; +char ukn[GPS_BUFFER_LEN]; + +// 0.1 second flash of LED2 +DigitalOut led2(LED2); +Timeout t2; +int j=0;// camera variable +void t2out(void) +{ + led2 = 0; +} +void blip2(void) +{ + led2 = 1; + t2.attach(&t2out, 0.1); +} + +// 0.1 second flash of LED3 +DigitalOut led3(LED3); +Timeout t3; +void t3out(void) +{ + led3 = 0; +} +void blip3(void) +{ + led3 = 1; + t3.attach(&t3out, 0.1); +} + +// 0.1 second flash of LED4 +DigitalOut led4(LED4); + +Timeout t4; +void t4out(void) +{ + led4 = 0; +} +void blip4(void) +{ + led4 = 1; + t4.attach(&t4out, 0.1); +} +///////////////////////////////////////////////////////////// +void gps_call(void); + +void temp_hum(void); + +void cam_call(void); + + GPS_Time q1; + JPEGCamera camera(p9, p10); // TX, RX + +int main() +{ + +//////////////////////////////////////////////////////////////////// + + // SET THIS. + // Ensure you set the baud rate to match your serial + // communications to your PC/Max/Linux host so you + // can read the messages. + pc.printf("setting the PC baud rate \n"); + pc.baud(9600); + + + // Tell MODGPS "we want copies of the NMEA sentences". When a callback + // is made our buffers will contain a copy of the last received sentence + // before it was processed/destroyed. + gps.setRmc(rmc); + gps.setGga(gga); + gps.setVtg(vtg); + gps.setUkn(ukn); + + + // SET THIS. + // Most GPS modules use 9600,8,n,1 so that's what + // we default to here. Ensure your GPS module matches + // this, otherwise set it to match. + pc.printf("setting the GPS baud rate \n"); + gps.baud(9600); + gps.format(8, GPS::None, 1); + + // OPTIONAL + // If you GPS has a 1 pulse per second output you can + // connect it to an Mbed pin. Here you specify what pin + // and on what "edge" teh signal is active. If your GPS + // module has a rising edge at the one second point then + // use GPS::ppsRise +#ifdef PPSPIN + gps.ppsAttach(PPSPIN, GPS::ppsFall); +#endif + + // Sample of a callback to a function when the 1PPS activates. + // For this example, we flash LED2 for 0.1 second. + gps.attach_pps(&blip2); + + // Sample of a callback to a function when a NMEA GGA message is recieved. + // For this example, we flash LED2 for 0.1 second. + gps.attach_gga(&blip3); + + // Sample of a callback to a function when a NMEA RMC message is recieved. + // For this example, we flash LED2 for 0.1 second. + gps.attach_rmc(&blip4); + + + + // Camera Code + pc.printf("Loading camera module \n"); + LocalFileSystem local("local"); //save images on mbed + camera.setPictureSize(JPEGCamera::SIZE320x240); + pc.printf("getting ready for the while loop! \n"); + +//////////////////////////////////////////////////////////////////// + int i; + for(i=1;i<11;i++) + {//gps + gps_call(); + + + + if(i==1||i==5||i==10) + {//temp&hum + temp_hum(); + } + if(i%2==0) + {//camera + cam_call(); + + } + + } + } + +void gps_call(void) +{ +// GPS Code + pc.printf("Turning inside the loop() \n"); + // Every 3 seconds, flip LED1 and print the basic GPS info. + pc.printf("hello GPS \n"); + + myled1 = 1; + + // Demonstrate how to find out the GPS location co-ords. + pc.printf("Method 1. Lat = %.4f ", gps.latitude()); + XBee.printf("Method 1. Lat = %.4f ", gps.latitude()); + + pc.printf("Lon = %.4f ", gps.longitude()); + XBee.printf("Lon = %.4f ", gps.longitude()); + + pc.printf("Alt = %.4f ", gps.altitude()); + XBee.printf("Alt = %.4f ", gps.altitude()); + + + // Gran a snapshot of the current time. + gps.timeNow(&q1); + pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", + q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); + XBee.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", + q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); +} +void temp_hum(void) +{ +//Temperature Sensor Code + pc.printf("hello TEMP"); + + int done=0; + float temp,hum; + + RHT03 humtemp(p24); //Initalise the RHT03 (change pin number to the pin its connected to) + + while(!done) { //Loop keeps running until RHT03 is read succesfully + wait(2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly + if(humtemp.readData() == RHT_ERROR_NONE) done=1; //Request data from the RHT03 + } + + temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade + hum = humtemp.getHumidity(); //Gets the current humidity in percentage + + pc.printf("Temperature is %f C \r",temp); + XBee.printf("Temperature is %f C \r\n",temp); + + + pc.printf("Humidity is %f % \r\n",hum); + XBee.printf("Humidity is %f % \r\n",hum); + + + + ///////////////////////////////////////////////// + +} + +void cam_call(void) +{ +//camera Code + j++; + Timer timer; + pc.printf("starting timer..."); + timer.start(); + pc.printf("hello CAMERA"); + + if (camera.isReady()) { + char filename[32]; + sprintf(filename, "/local/pict%03d.jpg", j); + printf("Picture: %s ", filename); + if (camera.takePicture(filename)) { + while (camera.isProcessing()) { + camera.processPicture(); + } + myled1 = 1; //show successful picture was taken + + myled1 = 0; + } else { + printf("take picture failed "); + myled3 = 1; //show picture take failed + + myled3 = 0; + } + } else { + printf("camera is not ready "); + myled4 = 1; //show camera is not ready + + myled4 = 0; + } + + myled2 = 1; //show end of sequence + + myled2 = 0; + printf("time = %f\n", timer.read()); + //////////////////////////////////////////////////// + + //Xbee Code + + pc.printf("i'm Sending......."); + + + + + ///////////////////////////////////////////// + +} \ No newline at end of file
diff -r 000000000000 -r a93721ad3c1a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 16 14:02:57 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb \ No newline at end of file