Go Down

Topic: SLEEP_MODE_PWR_DOWN Wake UP problems ... (Read 1 time) previous topic - next topic


I am using an Arduino IDE 1.03 + an arduino stalker 2.3 board (seeduino) with a LiPo, Solar Panel and SD card as a dataloger loging 4 parameters

1: Date/Time
2: internal temp from the DS3231 RTC/Temp Sensor
3: External temp from an Sensirion ST11 Sensor connected to Pins 10 and 11 + 3,3v/GND
4: External Humidity from same sensor as #3

I am trying the deep sleeping routines with set_sleep_mode(SLEEP_MODE_PWR_DOWN) and other routines that i do not completly understand yet

the first time the sketch runs after power up i get all the data perfectly on my serial monitor then the sketch puts the board to sleep and wakes up 1 minute later, there my problem begins, the internal temp and date are read perfectly but i can not read the Sensirion at pins 10/11

2013/1/17 13:24:29
Tint oC: 25.25, Text oC: 24.68

Awake from sleep
2013/1/17 13:25:0
Tint oC: 25.25, Text oC: -40.01

any ideas?????

and thanks in advance for your replies!!!!


here is the code

Code: [Select]
#include <avr/sleep.h>
#include <avr/power.h>
#include <Wire.h>
#include <DS3231.h>
#include <Fat16.h>
#include <Fat16util.h>
#include <SHT1x.h>

//The following code is taken from sleep.h as Arduino Software v22 (avrgcc), in w32 does not have the latest sleep.h file
#define sleep_bod_disable() \
{ \
  uint8_t tempreg; \
  __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \
                       "ori %[tempreg], %[bods_bodse]" "\n\t" \
                       "out %[mcucr], %[tempreg]" "\n\t" \
                       "andi %[tempreg], %[not_bodse]" "\n\t" \
                       "out %[mcucr], %[tempreg]" \
                       : [tempreg] "=&d" (tempreg) \
                       : [mcucr] "I" _SFR_IO_ADDR(MCUCR), \
                         [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \
                         [not_bodse] "i" (~_BV(BODSE))); \

DS3231 RTC; //Create RTC object for DS3231 RTC/Temp Sensor
static uint8_t prevSecond=0;
static DateTime interruptTime;
SdCard card;
Fat16 file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  if (card.errorCode) {
    PgmPrint("SD error: ");
    Serial.println(card.errorCode, HEX);

#define dataPin  10
#define clockPin 11

SHT1x sht1x(dataPin, clockPin);

void setup ()
     /*Initialize INT0 pin for accepting interrupts */
     PORTD |= 0x04;
     DDRD &=~ 0x04;
     pinMode(4,INPUT);//extern power
     attachInterrupt(0, INT0_ISR, LOW); //Only LOW level interrupt can wake up from PWR_DOWN

     //Enable Interrupt
     RTC.enableInterrupts(EveryMinute); //interrupt at  EverySecond, EveryMinute, EveryHour

void loop ()
    float temp_c;
    float humidity;
    ////////////////////// START : Application or data logging code//////////////////////////////////
    RTC.convertTemperature();          //convert current temperature into registers
    float temp = RTC.getTemperature(); //Read temperature from internal sensor (DS3231)
    DateTime now = RTC.now(); //get the current date-time   

    // Read values from the external sensor
    temp_c = sht1x.readTemperatureC();
    humidity = sht1x.readHumidity();

    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(now.date(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.println(now.second(), DEC);
    Serial.print("Tint oC: ");
    Serial.print(", ");
    Serial.print("Text oC: ");
    prevSecond = now.second();
    //|||||||||||||||||||Write to Disk||||||||||||||||||||||||||||||||||
    // initialize the SD card
    if (!card.init()) error("card.init");
    // initialize a FAT16 volume
    if (!Fat16::init(&card)) error("Fat16::init");
    char name[] = "DATALOG.CSV";
    // clear write error
    file.writeError = false;
    // O_CREAT - create the file if it does not exist
    // O_APPEND - seek to the end of the file prior to each write
    // O_WRITE - open for write
    if (!file.open(name, O_CREAT | O_APPEND | O_WRITE))
        error("error opening file");

    file.print(now.year(), DEC);
    file.print(now.month(), DEC);
    file.print(now.date(), DEC);
    file.print(now.hour(), DEC);
    file.print(now.minute(), DEC);
    file.print(now.second(), DEC);

    if (!file.close())
        error("error closing file");
    //|||||||||||||||||||Write to Disk||||||||||||||||||||||||||||||||||
    RTC.clearINTStatus(); //This function call is  a must to bring /INT pin HIGH after an interrupt.
    attachInterrupt(0, INT0_ISR, LOW);  //Enable INT0 interrupt (as ISR disables interrupt). This strategy is required to handle LEVEL triggered interrupt
    ////////////////////////END : Application code ////////////////////////////////
    //\/\/\/\/\/\/\/\/\/\/\/\/Sleep Mode and Power Down routines\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    //Power Down routines
    sleep_enable();      // Set sleep enable bit
    sleep_bod_disable(); // Disable brown out detection during sleep. Saves more power
    delay(10); //This delay is required to allow print to complete
    //Shut down all peripherals like ADC before sleep. Refer Atmega328 manual
    power_all_disable(); //This shuts down ADC, TWI, SPI, Timers and USART
    sleep_cpu();         // Sleep the CPU as per the mode set earlier(power down) 
    sleep_disable();     // Wakes up sleep and clears enable bit. Before this ISR would have executed
    power_all_enable();  //This shuts enables ADC, TWI, SPI, Timers and USART
    delay(10); //This delay is required to allow CPU to stabilize
    Serial.println("Awake from sleep");   
    //\/\/\/\/\/\/\/\/\/\/\/\/Sleep Mode and Power Saver routines\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


//Interrupt service routine for external interrupt on INT0 pin conntected to DS3231 /INT
void INT0_ISR()
  //Keep this as short as possible. Possibly avoid using function calls


Doesn't the SD card run from SPI bus signals? SCK, MISO, MOSI on D13,12,11, and SS on D10.
Probably want to use something besides D10, D11 for sensors.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


that´s why i like smart people  XD

sometimes you´re so absorved with your project that you can´t see the obvious details


Serial data is output using interrupts, which don't happen when you're snoozing. You want to ensure that all the serial data has been sent before nodding off.
The art of getting good answers lies in asking good questions.

Go Up