Going to sleep for a period to conserve power

28 Nov 2010

Hi there, I have just managed to make my first ever electronics project, which I am really proud of! I have connected up two I2C temperature sensors (TMP102) on the same bus and have them reading temperature and writing to a file in the file system.

The application for this will be in a remote data logging environment so I want to conserve as much energy as possible (so that I can run the unit for a few weeks at a time without having to replace batteries, reset clocks etc.

The code I currently have is:

#include "mbed.h"

#include "TMP102.h"
 
TMP102 TEMP1(p9, p10, 0x90); //A0 pin is connected to ground
TMP102 TEMP2(p9, p10, 0x92); //A0 pin is connected to V+
LocalFileSystem local("local"); // Create the local filesystem under the name "local"
int dd;
int main()
{
    dd = 1;
    while(dd < 5)
    {
        printf("Temperature 1: %f", TEMP1.read());
        printf(" Temperature 2: %f\r\n", TEMP2.read());
        FILE *fp = fopen("/local/out.txt", "a");  // Open "out.txt" on the local file system for writing
        fprintf(fp, "%f", TEMP1.read());
        fprintf(fp, ",%f\r\n", TEMP2.read());
        fclose(fp);
        wait(1);
        dd++;
    }
    return 0;
}

So i would like to know how to replace that wait(1) with some kind of sleep function that would power almost everything off (apart from the clock that will do the counting) and then power everything back up to do a read say 10 minutes later.

I am not a C wizz and I have seen the forum post http://mbed.org/users/no2chem/notebook/mbed-power-controlconsumption/ But i'm not quite sure how I would implement and which powerdown function I would use.

Any suggestions are gretly appreciated!

Thanks, Dan