Feather M0 adalogger Sleep Mode

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
krx7
 
Posts: 6
Joined: Mon Aug 08, 2022 8:55 am

Feather M0 adalogger Sleep Mode

Post by krx7 »

Hello everyone,

I'm trying to make an energy efficiencies sensor. I use the feather M0 adalogger and it is working fine with 3 i2c sensors. The veml 7700 lux, amc2315c sensor and ds3231 RTC for an outdoor project.

I need some guidance of the best way to minimize the power consumption of the EEMB 3.7V Li-ION 1800mAh Lipo Battery.

Code: Select all

#include <RTClib.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_AHTX0.h>

#define VBATPIN A7

Adafruit_AHTX0 aht;
Adafruit_Sensor *aht_humidity, *aht_temp;


RTC_DS3231 rtc;

const int chipSelect = 4;         // SPI chip select for SD card
const int cardDetect = 7;          // pin that detects whether the card is there
const int writeLed = 8;           // LED indicator for writing to card
const int errorLed = 13;          // LED indicator for error
long lastWriteTime = 0;           // timestamp for last write attempt
long interval = 300000;            // time between readings
char fileName[] = "datalog.csv";  // filename to save on SD card

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
  //rtc.adjust(DateTime(2019, 1, 21, 5, 0, 0));

  // initialize LED and cardDetect pins:
  pinMode(writeLed, OUTPUT);
  pinMode(errorLed, OUTPUT);
  pinMode(cardDetect, INPUT_PULLUP);
  
    if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }

  if (!veml.begin()) {
    Serial.println("Sensor not found");
    while (10);
  }  
  Serial.println("Sensor found");

  Serial.println("AHT10 or AHT20 found");
  // startSDCard() blocks everything until the card is present
  // and writable:
  if (startSDCard() == true) {
    Serial.println("card initialized.");
    delay(100);
    // open the log file:
    File logFile = SD.open(fileName, FILE_WRITE);
    // write header columns to file:
    if (logFile) {
      logFile.println("Date,Hour,Batt,Humi,Temp");
      logFile.close();
    }
  }
}
void loop()
{
    // if the cart's not there, don't do anything more:
  if (digitalRead(cardDetect) == LOW) {
    digitalWrite(errorLed, HIGH);
    return;
  }
  // turn of the error LED:
  digitalWrite(errorLed, LOW);

  DateTime now = rtc.now();
  char dateBuffer[16];
  char hourBuffer[16];
  sprintf(dateBuffer,"%02u-%02u-%04u ",now.day(),now.month(),now.year());
  sprintf(hourBuffer,"%02d:%02d:%02d ",now.hour(),now.minute(),now.second());

  float measuredvbat = analogRead(VBATPIN);
  measuredvbat *= 2;  
  measuredvbat *= 3.3;
  measuredvbat /= 1024;

  aht_humidity = aht.getHumiditySensor();
  sensors_event_t humidity;
  aht_humidity->getEvent(&humidity);
  float rHumidity = humidity.relative_humidity;

  aht_temp = aht.getTemperatureSensor();
  sensors_event_t temp;
  aht_temp->getEvent(&temp);
  float temperature = temp.temperature;

  // read the lux value from the sensor:
  float readLux = veml.readLux();

  // read sensors every 5 minutes
  if (millis()  - lastWriteTime >=  interval) {
    File logFile = SD.open(fileName, FILE_WRITE);   // open the log file
    if (logFile) {                                  // if you can write to the log file,
      digitalWrite(writeLed, HIGH);                 // turn on the write LED

      logFile.print(dateBuffer);
      logFile.print(", ");
      logFile.print(hourBuffer);
      logFile.print(", ");
      logFile.print(measuredvbat);
      logFile.print(", ");
      logFile.println(rHumidity);
      logFile.print(", ");
      logFile.println(temperature);
      logFile.print(", ");
      logFile.println(readLux);
      logFile.flush();


      Serial.print(dateBuffer);
      Serial.print(",");
      Serial.print(hourBuffer);
      Serial.print(",");
      Serial.print(measuredvbat);
      Serial.print(",");
      Serial.print(rHumidity);
      Serial.print(",");
      Serial.print(temperature);
      Serial.print(",");
      Serial.print(readLux);
      Serial.print('\n'); 

      // update the last attempted save time:
      lastWriteTime = millis();
    }
    digitalWrite(writeLed, LOW);      // turn off the write LED
  }

  delay(5000);
}

boolean startSDCard() {
  // Wait until the card is inserted:
  while (digitalRead(cardDetect) == LOW) {
    Serial.println("Waiting for card...");
    digitalWrite(errorLed, HIGH);
    delay(750);
  }

  // wait until the card initialized successfully:
  while (!SD.begin(chipSelect)) {
    digitalWrite(errorLed, HIGH);   // turn on error LED
    Serial.println("Card failed");
    delay(750);
  }
  return true;
}
Thanks

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: Feather M0 adalogger Sleep Mode

Post by mikeysklar »

There is a power management page for the Feather M0 Adalogger which will help set expectations.

https://learn.adafruit.com/adafruit-fea ... t?view=all

The SleepyDog Arduino Library works on this board.

https://github.com/adafruit/Adafruit_SleepyDog

User avatar
krx7
 
Posts: 6
Joined: Mon Aug 08, 2022 8:55 am

Re: Feather M0 adalogger Sleep Mode

Post by krx7 »

Hi mikeysklar,

Thanks for the official documentation of adafruit. I have read this information.

The Adafruit_SleepyDog only allows 16 seconds to sleep mode maximum, I'm looking for long standby or sleep mode in order to save energy of the battery for example (5 min or 20 minutes of interval time).

Thanks in advanced

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”