1

I am having a little trouble with my arduino deep sleep script. I want to create measuring station, which will get some value and after getting this value, after that will go sleep, for 5 minutes. I have been experimenting with this code and library, but I can not solve one problem. If I put in the setup Serial.print it is not working (the same thing is happening in the function alarmMatch().

Thank you much for your answers.

#include <RTCZero.h>

    /* Create an rtc object */
    RTCZero rtc;

    /* Change these values to set the current initial time */
    const byte seconds = 0;
    const byte minutes = 00;
    const byte hours = 17;

    /* Change these values to set the current initial date */
    const byte day = 17;
    const byte month = 11;
    const byte year = 15;

    void setup()
    {
      delay(10000);
      pinMode(LED_BUILTIN, OUTPUT);
      digitalWrite(LED_BUILTIN, LOW);

      Serial.begin(9600);
        Serial.println("test");
      rtc.begin();
      Serial.println("test");
      rtc.setTime(hours, minutes, seconds); 
      Serial.println("test");
      rtc.setDate(day, month, year);
      Serial.println("test");
      rtc.setAlarmTime(17, 00, 10);
        Serial.println("test");
      rtc.enableAlarm(rtc.MATCH_HHMMSS);
      Serial.println("test");
      rtc.attachInterrupt(alarmMatch);
      Serial.println("test");
      rtc.standbyMode();
    }

    void loop()
    {
     // Sleep until next alarm match
    }

    void alarmMatch()
    {
      digitalWrite(LED_BUILTIN, HIGH);
    }
walnut
  • 21,629
  • 4
  • 23
  • 59
  • Have you ever been able to write on `Serial` before? – JohnFilleau Feb 29 '20 at 16:01
  • I don't see in your code where you are putting anything to sleep. Is this the whole code? If you are printing to serial and then immediately going to sleep then you are probably sleeping before serial has a chance to finish sending out your data. Try using a Serial.flush() right before you go to sleep to let the serial line have time to send everything before it gets to the line that puts it to sleep. – Delta_G Feb 29 '20 at 16:47
  • Yeah, thank you, but I have one more question, "rtc.attachInterrupt(alarmMatch);" if I call here a functiom "alarmMatch" there no delays work, how to fix it? –  Feb 29 '20 at 17:12
  • Is your Serial over USB for your M0 board? If so, maybe put a delay between the Serial.begin() and the first Serial.print in your setup() routine. I think I've read that it can take a little time for the serial connection to get established over usb, and so nothing comes out if we print when it's not yet ready. Something like that! :-) Also check out Serial.available() to see if the device is ready. – aMike Feb 29 '20 at 17:18
  • If it's indeed the USB issue you can use the code snippet here https://www.arduino.cc/reference/en/language/functions/communication/serial/ifserial/ to wait until `Serial` connects. `while (!Serial) {}` – JohnFilleau Feb 29 '20 at 17:35
  • Thank you guys, and now, sorry, that I am asking, but why does not dely work in the function called by attachinterrupt(here is my function, where the delays do not work)... –  Feb 29 '20 at 19:14

0 Answers0