Home Forums Mayfly Data Logger Interrupt

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Shannon Hicks Shannon Hicks 1 month, 2 weeks ago.

  • Author
  • #2224
    Profile photo of lillquist

    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
    Profile photo of Shannon Hicks
    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
    Profile photo of JimMoore

    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
    Profile photo of Shannon Hicks
    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.

You must be logged in to reply to this topic.