Gas monitoring - direct pulse with EmontxV3

Hi all,

I'm doing gas monitoring with success using an emontxV3. After one week, the index displayed in my Emoncms account is exactly the same displayed on my gas meter ! So I am glad to give you some feedbacks.

My gas meter is a G4 Gallus 2000. Millions of units have been installed worldwild for years. By luck, this meter had already been equipped with a pulse generator by my gas furnisher. This pulse generator which has been designed for my gas meter is basically a reed switch normally opened. You can purchase it here in France.

If you have a different gas meter or if you don't want to buy this pulse generator you can made your own pulse generator using a reed switch (search for gas monitoring on the forum and have a look in the building block section)

In the emontxV3 pulse sketch or in the wiki, one can read that it may be needed to add a pull-down resistor onto the emonTx V3 PCB (R31). I didn't do it as the PCB is already equipped with this resistor. I guess it's a copy paste error coming from the emontxV2. So I directly connect my pulse generator into emonTx V3 terminal block port 4 (IRQ 0 / Digital 2) and block port 2 (3.3V)

First, I tried to use the emontxV3 pulse sketch available on github. It was not working as expected because I got a lot of bounces and glitches.See attached graphs. It tried to filter the signal directly in the sketch with an appropriate  interrupt service routine. It worked fine for glitches but not well for bounces. I guess some interrupts were ignored because my filtering ISR was too long.

So I wrote another sketch to smooth the pulse signal without using interrupts. It reads the state of the signal each seconds and detects real state changes. The number of real pulses is sent every ten seconds. It is difficult for me to explain how it works in english but the code is really easy to understand (see below). It works very well with my pulse signal that does not switch faster than every 6 secondes. You may adapt the duration between two read to meet your needs

I realized later that it is possible to filter such a signal using a hardware method. A simple RC circuit well designed should work fine. Look for debouncing circuit in google. For sure, it will free your arduino to do something else....

Regards,

Eric

****************************************

 

void loop()
{  
  emontx_sleep(1);
 
  val_2=val_1;    // value read 2 sec ago
  val_1=val;      // value read 1 sec ago
  val = digitalRead(2);    // value of the pin 2
    
  if (debug==1) {Serial.print(val_2);Serial.print(val_1);Serial.println(val);}
 
  if ((val_2 & val_1 & val & !state) or (!val_2 & !val_1 & !val & state)){
     state=!state;
     emontx.pulse=emontx.pulse++;
     if (debug==1) {Serial.print("  Pulse = ");Serial.println(emontx.pulse);}
  }
    
  mesure++;

  if (mesure==10){
    if (debug==1) {Serial.print("  send Pulse = ");Serial.println(emontx.pulse);}
    send_rf_data();
    mesure=0;
    emontx.pulse=0;
  }

  digitalWrite(LEDpin, HIGH); delay(2); digitalWrite(LEDpin, LOW);      // flash LED
}