Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16529
    henry_toal
    Participant

    Hello,

    I am using the Rocket Scream Mini Ultra for a data collection application which uses a serial connection to interface with a LoRa module. The example on Github for the LowPowerAVRZero standby mode uses the RTCAVRZero library to set a function to run on an interrupt but I cannot use serial communications from inside the interrupt. Is there a simple way to exit standby mode to transmit data via serial then return to standby?

    Thank you!

    #16530
    LIM PHANG MOH
    Keymaster

    Hi,
    You basically add a flag that is set in the ISR whenever the interrupt takes place.
    Then in the main loop, just check whether that flag is set.
    If it is being set, then you can talk to your LoRa module. Don’t forget to clear the flag though.
    Some skeleton of the code would look like this:

    volatile bool wakeUp = false;
    void setup()
    {
      uint8_t index;
    
      for (index = 0; index < sizeof(unusedPins); index++)
      {
        pinMode(unusedPins[index], INPUT_PULLUP);
        LowPower.disablePinISC(unusedPins[index]);
      }
    
      pinMode(LED_BUILTIN, OUTPUT);
      digitalWrite(LED_BUILTIN, LOW);
    
      /* true: external 32.768 kHz crystal */
      /* false: internal 32.768 kHz ULP oscillator */
      RTCAVRZero.begin(false);
      /* Time in seconds, true: repeat, false: once */
      RTCAVRZero.enableAlarm(60, true);
      RTCAVRZero.attachInterrupt(awake);  
    }
    
    void loop()
    {
      /* RTC works down to standby mode only. In power down, PIT is required */
      LowPower.standby();
      digitalWrite(LED_BUILTIN, HIGH);
      if (wakeUp)
      {
        wakeUp = false;
       // Do your LoRa communication here
      }
      digitalWrite(LED_BUILTIN, LOW);
    }
    
    void awake(void)
    {
      wakeUp = true;
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.