Two Reed Style inputs on WaterMote possible?

Started by G550_Pilot, May 05, 2016, 06:29:23 PM

G550_Pilot

I see that the WaterMote is setup to use the SY310 Optical sensor to read a water meter, but I have three meters (two on one arduino) which use  dry contact reed switches to trigger a pulse reading. Here is the code:


// Set up some timers
const int time_between_readings= 1;            // How often do you want to tranmist your readings to your Emonhub/Pi?
const int polling_period = 500;               // Polling period in ms (check the state of the reed switch)

...

 for (int i=0; i<time_between_readings; i++)
  { 
     for (int j=0; j<55000/polling_period; j++) {       //1 minute should be 60000 but is not because of variation of internal time source
    //caution parameter cannot be more than 65000, maybe find better solution
    //due to internal time source 60000 is longer than 1 minute. so 55s is used.
       inputHistory = (inputHistory << 1) + ((digitalRead(PULSEPIN1)==HIGH) ? 1 : 0);   // use as shift register - clock switch state through right-left
       if (inputHistory == 0x0F) {                                       // look for pattern 0 0 0 0 1 1 1 1,  i.e. LOW for 2 s, then HIGH for 2 s if the polling_period is 500ms
        water.pulse1++;
       }
       inputHistory2 = (inputHistory2 << 1) + ((digitalRead(PULSEPIN2)==HIGH) ? 1 : 0);   // use as shift register - clock switch state through right-left
       if (inputHistory2 == 0x0F) {                                       // look for pattern 0 0 0 0 1 1 1 1,  i.e. LOW for 2 s, then HIGH for 2 s if the polling_period is 500ms
        water.pulse2++;
      } 
        
       dodelay(polling_period); // im ms 
     }
  }



My reed switches are two wire reed switches which output 10 pulses per gallon. Testing with a meter shows they simply open and close the contact at each pulse. I attempted to use the WaterMote code and connected one wire to ground and one to a D3, but the sketch did not detect any of the pulses. I attempted the same thing using 3.3v and a resistor (10k) instead of to ground, that did not work either.....


Is it possible with the WaterMote to:
    1) Have multiple meters connected and
    2) Use reed switches as opposed to the optical reader to fire the pulses...?



These are the meters that I am using: MJR-075-10P

Felix

Quote from: G550_Pilot on May 05, 2016, 06:29:23 PM
Is it possible with the WaterMote to:
    1) Have multiple meters connected and
    2) Use reed switches as opposed to the optical reader to fire the pulses...?

1) I don't know without trying it. It should be possible but the way the sketch is configured is to read a hardware interrupt, and there are none left after using D2 for the radio and D3 for a pulse meter.
2) It doesn't matter what the source is. Configure the interrupt as RISING or FALLING depending on how that pulse behaves etc.

G550_Pilot

Quote from: Felix on May 06, 2016, 08:30:47 AM
1) I don't know without trying it. It should be possible but the way the sketch is configured is to read a hardware interrupt, and there are none left after using D2 for the radio and D3 for a pulse meter.
2) It doesn't matter what the source is. Configure the interrupt as RISING or FALLING depending on how that pulse behaves etc.

Thanks Felix -

So there are only two interrupts on the Moteinos I gather from your answer above. The WaterMote is configured to read an LED, how do I convert that to a pulse?



void pulseCounter(void)
{
  noInterrupts();
  ledState = !ledState;
  PulseCounterVolatile++;  // increase when LED turns on
  digitalWrite(LED, ledState);
  NOW = millis();



Felix

Quote from: G550_Pilot on May 10, 2016, 07:14:23 PM
So there are only two interrupts on the Moteinos I gather from your answer above. The WaterMote is configured to read an LED, how do I convert that to a pulse?
Yes only 2 hardware interrupts. You can always try PINChangeInterrupts, but when you wake you have to check which pin actually triggered the interrupt. There is a library for that and some conversations in the forum about it.
The WaterMote reads pulses not an LED. That pulse can be generated by anything, in my case I use a EE-SY310 photo reflective sensor.

G550_Pilot

Quote from: Felix on May 11, 2016, 08:15:07 AM
Quote from: G550_Pilot on May 10, 2016, 07:14:23 PM
So there are only two interrupts on the Moteinos I gather from your answer above. The WaterMote is configured to read an LED, how do I convert that to a pulse?
Yes only 2 hardware interrupts. You can always try PINChangeInterrupts, but when you wake you have to check which pin actually triggered the interrupt. There is a library for that and some conversations in the forum about it.
The WaterMote reads pulses not an LED. That pulse can be generated by anything, in my case I use a EE-SY310 photo reflective sensor.

Thanks again Felix -

If it reads pulses, what is the reference to reading an LED here? Sorry, I am a bit confused is all...

void pulseCounter(void)
{
  noInterrupts();
  ledState = !ledState;
  PulseCounterVolatile++;  // increase when LED turns on
  digitalWrite(LED, ledState);
  NOW = millis();

Felix

That's a digitalWrite(). It simply flashes the LED of the Moteino periodically, and faster when the meter is giving pulses.

G550_Pilot

Quote from: Felix on May 12, 2016, 08:40:02 AM
That's a digitalWrite(). It simply flashes the LED of the Moteino periodically, and faster when the meter is giving pulses.

Ah..understood! Thanks!