Go Down

Topic: Stuck in lowpower.sleep despite dummy-function (Read 576 times) previous topic - next topic

yaelfischer

Hello everyone

I'm having some problems with putting my MKRFOX 1200 into sleep. Upon entering the sleepmode it won't wake up anymore. I've also tried to add the "attachInterruptWakeup" and the dummy-function, but it still gets stuck. Do you have any advice for me?

Kind regards
Yael

Code: [Select]
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_TSL2561_U.h>
#include "conversions.h"

#include <SigFox.h>
#include <ArduinoLowPower.h>

#define TWOHOURS 2000

int uvPin = A1;

Adafruit_BMP280 bme; //I2C-mode
Adafruit_SHT31 sht31 = Adafruit_SHT31();
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

typedef struct __attribute__ ((packed)) sigfox_message {
  int16_t bmpTemperature;
  uint16_t bmpPressure;
  uint16_t shtHumidity;
  int16_t shtTemperature;
  uint16_t tlsLight;
  uint16_t UVLight;
} SigfoxMessage;

SigfoxMessage msg;


void dummy() {
  Serial.println("dummy");
}


void setup() {
 
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
  Serial.begin(9600);
  while (!Serial) {};

  if (!SigFox.begin()) {
    Serial.println("Shield error!");
  }
  if (!bme.begin()) { 
    Serial.println("BMP280 not found!");
  }
  if (! sht31.begin(0x44)) {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
  }
  if (!tsl.begin()) {
    Serial.println("TLS Error");
  }
   
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);

 
  SigFox.end(); 
}

void loop()
{
    Serial.println(millis());
    sensors_event_t event;
   
    float bmp_temp = bme.readTemperature();
    msg.bmpTemperature = convertoFloatToInt16(bmp_temp, 60, -60);
    float bmp_pres = (bme.readPressure() / 100);
    msg.bmpPressure = convertoFloatToUInt16(bmp_pres, 2000);
    float sht_temp = sht31.readTemperature();
    msg.shtTemperature = convertoFloatToInt16(sht_temp, 60, -60);
    float sht_hum = sht31.readHumidity();
    msg.shtHumidity = convertoFloatToUInt16(sht_hum, 110);
    tsl.getEvent(&event);
    if (event.light) {
      msg.tlsLight = convertoFloatToUInt16(event.light, 100000);
    }
    float uv = analogRead(uvPin);   //Read the value of the uvPin
    uv = uv * 0.0049;               //Convert the value to volts
    uv = uv * 307;                  //Convert volts to mW/m²
    uv = uv/200;                    //Calculate the UV index
    msg.UVLight = convertoFloatToUInt16(uv, 15);

    Serial.print("Message: ");
    Serial.print(msg.bmpTemperature);
    Serial.print(" ¦ ");
    Serial.print(msg.bmpPressure);
    Serial.print(" ¦ ");
    Serial.print(msg.shtTemperature);
    Serial.print(" ¦ ");
    Serial.print(msg.shtHumidity);
    Serial.print(" ¦ ");
    Serial.print(msg.tlsLight);
    Serial.print(" ¦ ");
    Serial.println(msg.UVLight);
   
    Serial.print("Receive: ");
    Serial.print(msg.bmpTemperature * 2 * 120 * 100 / 65536);
    Serial.print(" ¦ ");
    Serial.print(msg.bmpPressure * 2000 * 10 / 65536);
    Serial.print(" ¦ ");
    Serial.print(msg.shtTemperature * 2 * 120 * 100 / 65536);
    Serial.print(" ¦ ");
    Serial.print(msg.shtHumidity * 110 * 100 / 65536);
    Serial.print(" ¦ ");
    Serial.print(msg.tlsLight * 100000  / 65536);
    Serial.print(" ¦ ");
    Serial.println(msg.UVLight * 15 * 100 / 65536);

    Serial.print("Should:  ");
    Serial.print(bmp_temp);
    Serial.print(" ¦ ");
    Serial.print(bmp_pres);
    Serial.print(" ¦ ");
    Serial.print(sht_temp);
    Serial.print(" ¦ ");
    Serial.print(sht_hum);
    Serial.print(" ¦ ");
    Serial.print(event.light);
    Serial.print(" ¦ ");
    Serial.println(uv);
    Serial.println();


//    SigFox.begin();
//    delay(100);
//    SigFox.debug();
//    SigFox.status();
//    delay(1);
//    SigFox.beginPacket();
//    SigFox.write((uint8_t*)&msg, 12);
//    SigFox.endPacket();

   
    SigFox.end();
    LowPower.sleep(2000);
    //delay(2000);
    Serial.println(millis());
 
}


jmsalomr

Hi,

Same problem here. Could you solve your issue?

Best regards.

yaelfischer

Hi jmsalomr,

Yes, I was able to solve the problem. My guess is that your only verification (board working or not) are the serial messages that should be sent, right?
I made the same mistake! After lots of struggles I found out that the serial connection is canceled when the board goes into sleep-mode.
Try adding a blinking led to your code and it should start again after waking up.
If you do need the serial connection try to restart it (serial.begin) after the board woke up. I haven't tried it and I can't try it right now but it should work.
I hope I was able to solve your issue,

Kind Regards
Yael

jmsalomr

Hi yaelfischer,

I thought the same that you tell me and I tested the board with the LED flashing after the sleep(), but nothing. What I have discovered is that I have to switch off the board. And then it works. If I upload the code and push the reset button without switching off the board, doesn't work and it seems the board si not awaking never. So, just need to switch off.

Best regards.

Go Up