Hello everyone,
I am currently using a Seeeduino Xiao (ATSAMD21G18A) in a project. The project involves taking a temperature and ambient light measurement (I2C) every 10 minutes. The MCU should be in sleep mode otherwise. The LowPower.attachInterruptWakeup() from the Arduino low power library is not supported by the Xiao. I found this sleep and wakeup with RTC and tried to implement it. When the MCU starts the first measurements are taken but once it enters standby and wakes up, no measurements show up in the serial monitor again. However, the code in the while loop does execute as the blink sketch works. The sensors communicate perfectly without the stand-by mode. Here is the code:
#include "RTC_SAMD21.h" //install seeed_arduino_RTC : https://github.com/Seeed-Studio/Seeed_Arduino_RTC
#include "DateTime.h"
#include <EnergySaving.h>
#include<Wire.h> //include library
#define Address_GY49 0x4A // GY-49 I2C Address is 0x4A(74)
#include <Adafruit_TMP006.h>
Adafruit_TMP006 tmp006 (temperature sensor);
EnergySaving myPowSave;
RTC_SAMD21 myRtc;
#define PIN_LED 13
void setup()
{
//configure gy-49 module (Ambient light sensor)
Wire.begin(); //initialize library
Serial.begin(9600); //start serial monitor
Wire.beginTransmission(Address_GY49); //start wire iic transmission
Wire.write(0x02); // Select configuration register
Wire.write(0x40); // Continuous mode, Integration time = 800 ms
Wire.endTransmission(); // Stop iic transmission
delay(300);
myRtc.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); //LED off (active LOW)
myRtc.adjust(DateTime(2030, 4, 1, 8, 30, 0) );
myRtc.attachInterrupt(dummyfunc);
myPowSave.begin(WAKE_RTC_ALARM);
myRtc.disableAlarm();
DateTime timeNow = myRtc.now();
const uint16_t uiAlmNextSec = 1000;
DateTime timeAlarm = DateTime(timeNow.year(), timeNow.month(), timeNow.day(), timeNow.hour(), timeNow.minute(), timeNow.second() + uiAlmNextSec);
myRtc.setAlarm(timeAlarm);
myRtc.enableAlarm(myRtc.MATCH_SS);
}
void loop()
{
// this executes
for (int i = 0; i < 3; i++) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
//temperature sensor
digitalWrite(LED_BUILTIN, HIGH);
float objt = tmp006.readObjTempC();
Serial.print("Object Temperature: "); Serial.print(objt); Serial.println("*C");
float diet = tmp006.readDieTempC();
Serial.print("Die Temperature: "); Serial.print(diet); Serial.println("*C");
//gy-49 ambient light module
unsigned int data[2];
Wire.beginTransmission(Address_GY49); //start wire iic transmission
Wire.write(0x03); // Select data register
Wire.endTransmission(); // Stop iic transmission
Wire.requestFrom(Address_GY49, 2); // Request 2 bytes of data
// Read 2 bytes of data
// luminance msb, luminance lsb
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
// Convert the data to lux
int exponent = (data[0] & 0xF0) >> 4;
int mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F);
float luminance = pow(2, exponent) * mantissa * 0.045;
// Output data to serial monitor
Serial.print("Ambient Light Luminance :");
Serial.print(luminance);
Serial.println(" lux");
delay(4300);
myPowSave.standby();
//proceed after wakeup
}
void dummyfunc()
{}
`
Does anyone have an idea what the problem could be? I am still quite new to Arduino so the solution might be super trivial. Also, I am unable to change the duration of the standby mode. The MCU says in standby mode for around about 50 seconds regardless of the uiAlmNextSec value. Anyone help will be much appreciated. Bless!