Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14264
    bpmcgee
    Participant

    Hi,

    I’m having two problems:

    First, although I have interrupts set for pins 0, 7, and 8, only pin 0 seems to wake the Ultra up.
    Second after LowerPower.standby(), SerialUSB never seems to come back — the LED flashes, but I get no monitor output.

    Any advice is appreciated!

    
    #include <LowPower.h>
    
    volatile uint32_t trigger1 = 0;
    volatile uint32_t trigger2 = 0;
    
    int ledstate = LOW;
    const int SENSOR1_PIN = 7;
    const int SENSOR2_PIN = 8;
    
    const int LED_PIN     = 13;
    
    void setup() {
      int pinNumber;
      //start serial connection
      SerialUSB.begin(9600);
      SerialUSB.println ("Hello world.");
    
      //configure pin 2 as an input and enable the internal pull-up resistor
      pinMode(SENSOR1_PIN, INPUT_PULLUP);
      pinMode(SENSOR2_PIN, INPUT_PULLUP);
      pinMode(LED_PIN, OUTPUT);
      digitalWrite (LED_PIN, LOW);
    
      attachInterrupt(digitalPinToInterrupt(SENSOR1_PIN), sensorChanged1, FALLING);
      attachInterrupt(digitalPinToInterrupt(SENSOR2_PIN), sensorChanged2, FALLING);
      attachInterrupt(0, sensorChanged1, LOW);
      while (!SerialUSB)
        delay (500);
      SerialUSB.println ("Completed setup.");
    
      int count;
      SerialUSB.println("Entering standby mode in:");
      for (count = 10; count > 0; count--)
      {
        SerialUSB.print(count);
        SerialUSB.println(" s");
        delay(1000);
      }
    }
    
    void loop() {
    
      // put your main code here, to run repeatedly:
      SerialUSB.end ();
      SerialUSB.println ("sleeping");
      LowPower.standby();
      delay (1000);
    
      SerialUSB.begin (9600);
    
      SerialUSB.println("Waking!");
    
      while (!SerialUSB);
      // Serial USB is blazing fast, you might miss the messages
      delay(1000);
      SerialUSB.println("Awake!");
      delay (1000);
      digitalWrite (LED_PIN, ledstate);
      ledstate = !ledstate;
    
    }
    
    void sensorChanged1()
    {
      trigger1 = millis();
    
    }
    
    void sensorChanged2()
    {
      trigger2 = millis();
    
    }

    Thanks,

    Brian

    #14277
    LIM PHANG MOH
    Keymaster

    Hi Brian,
    Sorry, we just came back from China and went a bit under the weather this morning.

    For external interrupt that requires direction (falling, rising), please use the extended external pin interrupt for the SAMD21 core as it is not supported directly under the Arduino SAMD21 core. Not sure why the Arduino team decided not to add them into the main line. Using that library also means you don’t need any other RTC and sleeping library as they are incorporated inside it.

    For the USB portion, I don’t see any proper USBDevice.detach(); USBDevice.init(); or USBDevice.attach(); in your code. Please take a look at the code in this documentation section on how it is properly implemented.

    #14282
    bpmcgee
    Participant

    Understood, thank you. With the ArduinoLowPower library I was able to get my sketch working.

    B

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.