Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

RTC Interrupt

Home Forums Mayfly Data Logger RTC Interrupt

Tagged: ,

Viewing 2 reply threads
  • Author
    • #1547

        I just got my Mayfly yesterday and totally love it so far.
        I’m trying to use the interrupt from the clock to control an event but I have not been successful in detecting the interrupt.

        I’ve been using the “interrupts” example from the Sodaq_DS3231.h library but it isn’t working.
        Looking at the Mayfly schematic, it appears the interrupt output from the rtc chip is on pin A7 of the Mayfly. Is that correct?

        I don’t know much about interrupts in general, but I assume I need to change the code to listen on the right pin.
        All my attempts to edit the program have been unsuccessful so far.
        Does anyone know how I could get this to work properly?

        I appreciate any advice – thanks.

        //Interrupts for Battery management/saving using MCU power down mode. /INT from DS3231 is connected to INT0 of MCU.

        #include <avr/sleep.h>
        #include <Wire.h>
        #include "Sodaq_DS3231.h"

        static uint8_t prevSecond=0;

        void setup ()
        /*Initialize INT0 for accepting interrupts */
        PORTD |= 0x04;
        DDRD &=~ 0x04;


        attachInterrupt(0, INT0_ISR, FALLING);

        //Enable Interrupt
        rtc.enableInterrupts(EveryMinute); //interrupt at EverySecond, EveryMinute, EveryHour
        // or this
        //rtc.enableInterrupts(18,4,0); // interrupt at (h,m,s)

        void loop ()

        DateTime now = rtc.now(); //get the current date-time
        if((now.second()) != prevSecond )
        //print only when there is a change in seconds
        Serial.print(now.year(), DEC);
        Serial.print(now.month(), DEC);
        Serial.print(now.date(), DEC);
        Serial.print(' ');
        Serial.print(now.hour(), DEC);
        Serial.print(now.minute(), DEC);
        Serial.print(now.second(), DEC);
        Serial.println(' ');
        prevSecond = now.second();


        //Interrupt service routine for external interrupt on INT0 pin conntected to /INT
        void INT0_ISR()
        //Keep this as short as possible. Possibly avoid using function calls

        Serial.println(" External Interrupt detected ");

      • #1548
        Shannon Hicks

          The Mayfly has 3 hardware interrupts, D2, D3, and D10. Since the first two are part of the serial UART, that only leaves D10 as the only available hardware interrupt. On the Mayfly v0.3 board, the RTC is connect to A7, so you have to use a “pin change interrupt” library to handle an interrupt from something other than one of the hardware pins. This can also be helpful if you’re looking for a trigger signal on any input pin.

          The SODAQ pin change interrupt library works great for this: https://github.com/SodaqMoja/Sodaq_PcInt

          You can also read more information about how SODAQ handles the interrupts on the Mbili, which is similar to the Mayfly. http://support.sodaq.com/interrupts/

          I’m working on some sample Mayfly code for handling the pin change interrupts, I can hopefully post it soon, but the SODAQ links should help you in the meantime.

        • #1549

            Thanks for the info.
            I’ll look into that for sure.

            Would it be possible to cut the trace between them and run a jumper to D10?

            • #1550
              Shannon Hicks

                Yes, if you’d prefer to use the hardware D10 interrupt, just cut the trace and solder a jumper over to the D10 pin on the header row. Then you can use “INT2” as the interrupt.

          Viewing 2 reply threads
          • You must be logged in to reply to this topic.