Pages: [1]   Go Down
Author Topic: SLEEP_MODE_PWR_DOWN Wake UP problems ...  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
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

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

Sleeping
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!!!!

Femur

here is the code

Code:
#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: ");
  SerialPrintln_P(str);
  if (card.errorCode) {
    PgmPrint("SD error: ");
    Serial.println(card.errorCode, HEX);
  }
  while(1);
}

#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
   
     Wire.begin();
     Serial.begin(38400);
     RTC.begin();
     
     attachInterrupt(0, INT0_ISR, LOW); //Only LOW level interrupt can wake up from PWR_DOWN
     set_sleep_mode(SLEEP_MODE_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('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.date(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.println(now.second(), DEC);
    Serial.print("Tint oC: ");
    Serial.print(temp);
    Serial.print(", ");
    Serial.print("Text oC: ");
    Serial.print(temp_c);
    Serial.println();
   
    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('/');
    file.print(now.month(), DEC);
    file.print('/');
    file.print(now.date(), DEC);
    file.print(',');
    file.print(now.hour(), DEC);
    file.print(':');
    file.print(now.minute(), DEC);
    file.print(':');
    file.print(now.second(), DEC);
    file.print(',');
    file.println(temp);

    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
    cli();
    sleep_enable();      // Set sleep enable bit
    sleep_bod_disable(); // Disable brown out detection during sleep. Saves more power
    sei();
       
    Serial.println("\nSleeping");
    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
    detachInterrupt(0);
}

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23718
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dang!!!!
that´s why i like smart people  smiley-lol

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: