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


Home Forums Mayfly Data Logger Interrupt

Viewing 6 reply threads
  • Author
    • #2224

        I’m trying to use a flow meter that ticks every revolution from a magnet passing a hall effect sensor, equating to some volume of liquid. I need to be sure not to miss a tick so I need the interrupt. I’ve read that D10 is interrupt enabled but I can’t get it to work. I’ve gotten the system to work on other ardionos so I know it isn’t the wiring. Below is the code.
        Thanks for the help!

      • #2226
        Shannon Hicks

          The Mayfly has 3 hardware interrupts. They are RXD1 (INT0), TXD1 (INT1), and D10 (INT2). To use the “attachInterrupt” function, you can only use the three hardware interrupt pins, and you have to refer to them as “0”, “1”, or “2”. So if you want to use the D10 interrupt pin, you’ll need to say the following on line 8:

          attachInterrupt(2, countUp, CHANGE);

          You also don’t have to define the interrupt pin in line 1 of your above code, or set the pinMode in line 7, so remove both of those lines.

          Depending on what hall effect sensor you’re using, you’ll probably need to use a pullup resistor on the output of the sensor. If you’re using the Mayfly v0.5, you can use the optional onboard pullup resistor for D10 by closing SJ12, meaning you can measure a switch like the hall effect sensor as an interrupt with no additional parts.

        • #2227
          Jim Moore

            I have been trying to setup the new rev 0.5 boards to run my Atlas Scientific sensors and I have been using the Mayfly_sleep example. I changed J1 to use D10 as the interupt and it didn’t work till I used attachInterrupt(2, wakeISR,CHANGE)
            This didn’t work reliably until I added the pinMode(RTC_PIN, INPUT_PULLUP) back into the example code.

            I now have the example code working on my rev 0.5 board but the battery voltage is 1.5.
            Multiple of 2! Initiating sensor reading and logging data to SDcard….
            Data Record: 2017-05-14 22:28:00,548116080,23.8,1.52
            showTime = 2017-05-14 22:29:00
            showTime = 2017-05-14 22:30:00
            Multiple of 2! Initiating sensor reading and logging data to SDcard….
            Data Record: 2017-05-14 22:30:00,548116200,23.8,1.52

            This code read the battery voltage correctly on the rev 0.3 board.
            Is the correct pin still A6?

          • #2228
            Shannon Hicks

              Because the v0.5 board can now accept an input supply voltage up to 12v, I had to change the onboard voltage divider that’s used for measuring the battery voltage by way of A6. So the formula for reading the battery voltage on a v0.3 or v0.4 board is this:

              rawBattery = analogRead(A6);
              sensorValue_battery = (3.3 / 1023.) * 1.47 * rawBattery;

              But for boards v0.5 and later, the formula is now this:

              rawBattery = analogRead(A6);
              sensorValue_battery = (3.3 / 1023.) * 4.7 * rawBattery;

              This is built in to the MayflyOnboardSensors library we posted recently on Github. More instructions will hopefully be posted soon about how to use all of our new libraries.

              EDIT: I’ve also updated the Battery Measurement example to show both formulas.

            • #2266

                I’ve the same problem with a rain gauge sensor:

                I’ve tried with a bridge in sj12 and also in sj1 but nothing happens…

                Any hints?

              • #2270
                Shannon Hicks

                  SJ-12 is for enabling the pullup resistor on D10. SJ-1 is for changing the square wave alarm signal from the RealTimeClock from A7 (default) to D10. As stated on the Jumper Settings page (https://envirodiy.org/mayfly/hardware/jumper-settings/), you should never use SJ-12 if you’ve also changed SJ-1 to D10. The two can’t be used together or it will cause problems.

                  So remove your solder bridge on SJ-1 and put it back to the default setting by connecting the middle pad to the one labeled “A7”. Then have your sketch look for a LOW pulse on D10 by using this line:

                  attachInterrupt(2, tip, LOW);

                  Then anytime you get a tip by the bucket (assuming you connect D10 and GND to the two NormallyOpen poles of you rain gauge switch, the Mayfly will go into the “tip” function. If you still need help, I can post an entire sketch for how to sleep the Mayfly all the time and only wake up briefly whenever there’s a tip, record the tip, then go back to sleep.

                • #2280
                  Sara Damiano

                    You should also be able to use pin-change interrupts for the tipping bucket, which would allow you to use any pin at all. Using pin change interrupts requires an extra library, though. I’m a fan of GreyGnome’s EnableInterrupt library, which I’ve modified to have all the right pin numbers for the Mayfly: https://github.com/EnviroDIY/EnableInterrupt

                    The external interrupts do have priority over pin-change interrupts, but I don’t imagine the bucket would tip so fast that you’d have any problems, especially when your ISR is just a count.

                    All pin change interrupt libraries also conflict with the interrupts defined by SoftwareSerial and the SDI-12 library, although there are fairly easy work-arounds for those if you need them.

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