I am meassuring data pulses from my electrical meter, giving me one pulse per Watt used. I have 4 electrical meters connected to my Raspberry Pi model B. I have connected them directly like this (no other components used):
3.3VDC GPIO 0, pin 11 GPIO 1, pin 12 GPIO 2, pin 13 GPIO 3, pin 15
I have this Python code (picked from a larger code):
# Use board layout pin scheme GPIO.setmode(GPIO.BOARD) # Setup pins GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Create interrupt for each pulse GPIO.add_event_detect(11,GPIO.FALLING, callback=eventHandler, bouncetime=350) GPIO.add_event_detect(12,GPIO.FALLING, callback=eventHandler, bouncetime=350) GPIO.add_event_detect(13,GPIO.FALLING, callback=eventHandler, bouncetime=350) GPIO.add_event_detect(15,GPIO.FALLING, callback=eventHandler, bouncetime=350) ... # Threaded callback handler def eventHandler (pin): global gpio0_totalPulses global gpio1_totalPulses global gpio2_totalPulses global gpio3_totalPulses global logger # GPIO 0 if(pin == 11): gpio0_totalPulses = gpio0_totalPulses + 1 logger.info("GPIO 0: Pulse number ["+ str(gpio0_totalPulses) +"] detected") # GPIO 1 if(pin == 12): gpio1_totalPulses = gpio1_totalPulses + 1 logger.info("GPIO 1: Pulse ["+ str(gpio1_totalPulses) +"] detected") ...
I am using one of the four electrical meters as a base reference, to check if I can trust the data but unfortanly it seems I cannot as I think I am getting bouncing counts. I am having a fixed power consumption on aprox 6W which should result in aprox 6 counts per hour but from time to time I am getting multiple hits within a 1-3 seconds period!? This is happening randomly but I really don't think this is the actual power usage though I have not checked if the electrical meter is actually giving the same number of blinks (too long to test).
My suspicion is that these extra-counts are ghosts/bouncing values and though I am using the built-in pull-down resistor I don't think this is enough? My setup is very "improvised" with a lot 1-wire connections and stuff you wouldn't see in a real product (hey, this is what RasPi is all about), so maybe my wires are acting as an antenna or the inputs are influencing each other?
I have read this raspberry-gpio-python link which suggests to use a 0.1u capacitor and maybe even using both the built-in pull-down AND a capacitor.
I have a couple of questions to this:
1) Should I use a 0.1u capacitor and how should it be wired?
2) Should I use my own 10K ohm resistor instead of the built-in?
# UPDATE 1 #
This is a database extraction of the data gathered over night:
There is clearly something wrong as it should be pretty fixed at aprox 5-7 in the
My physical setup is like this (maybe hard to see):
There are a few terminal strips, 1-wires and the length of the pulse cables are aprox 1-2 meters (not twisted pair).
The electrical meters I am using are these from Kamstrup (382L), Data pulse module for electricity meters
# UPDATE 2 #
I have now tried unplugging the electrical meter from its power source and still it gives a few pulses per hour!? For sure there is some interference but I cannot seem to figure out how to avoid this?
# UPDATE 3, 2014-12-10 21:30 #
I don't understand how this is possible (this is from my logfile):
20:32:06.373451 GPIO  pulse  detected (1.969 seconds since last = aprox 1828.7W) 20:32:06.378121 GPIO  pulse  detected (0.005 seconds since last = aprox 748908.6W)
I am recieving two pulses within
5ms - this should be impossible due to the
350ms bouncetime I have setup in the callback!?
I have now shifted from using the
3.3V to using the
GND and I have shifted the
pull-down to be a
pull-up and trigger on
RISING edge. This has certainly helped on the ghosting but it has not completely removed it and I am still receiving ghost-inputs on GPIO 3 (pin 15) even though the electrical meter is not even plugged in to its power souce (and thereby it should NEVER give out a pulse)! :-/
# UPDATE 4, 2014-12-12 14:55 #
Today I have been watching my electrical meter and seen with my own eyes that there in fact are "ghost inputs" - meaning it registered a pulse but it didn't blink on the meter. I saw these pulses (two of them ghosts):
14:10:49.586792 GPIO  pulse  detected; real pulse 14:21:38.909866 GPIO  pulse  detected; real pulse 14:30:46.887632 GPIO  pulse  detected; GHOST pulse 14:32:30.498948 GPIO  pulse  detected; real pulse 14:37:46.849414 GPIO  pulse  detected; GHOST pulse 14:43:16.992208 GPIO  pulse  detected; real pulse
I viewed my logfile to see if I could find any common grounds and it seems that the two above ghost pulses are happening when the RasPi get pulses from two other electrical meters almost simultaneously (within a few milliseconds).
Will it help to have hardware debouncing in this case?
# UPDATE 5, 2014-12-14 20:11 #
Though I have dramatically reduced the weird ghost pulses by replacing the pulse wires with network twisted pair cables, I am not sure I have 100% eliminated them as I suspect there to be minor issues when receiving multiple pulses simultaneous on several GPIO pins. I am considering to try out the hardware debouncing option, which I have not done yet - just to rule out if this can help or not.
Can someone please advice if this drawing below will be perfect for my setup? Is the resistor and capacitor good with a 30ms pulse from the electrical meter or should I instead use a bigger/10uF capacitor (10ms?)? Then of course I should scrap the internal pull-up resistor and the software debouncing.
The full Kamstrup 382L data sheet is here but this is what they write about its "S0 supply":
Sends 24 V via 2-wire and pulses by drawing the voltage to 0 V at every pulse.
This is what I plan to test:
Sorry for reasking this again but I really want to make this as good as possible and not fry my RasPi (I have no clue about hardware);-)