emonPi + connecting reed switch for gas pulse counting

Hi

I’m planning to connect a reed switch from my gas meter to an emonPi, but it’s not clear to me what the best way to wire it up is…

I’ve got this reed switch - I’ve tested it with a simple circuit and I can see that it closes as the fastest dial rotates (opens & closes once per full rotation).

I’m not sure whether I can connect it to the RJ45 to Terminal Block Breakout to make use of the standard code without modifications? - As I understand, the terminal block breakouts have a 3 wire connection and talk to a bus interface, but this is a simple 2 wire switch and I think I need to connect it to an interrupt or poll a GPIO line?

Would I be better off not using the breakout board and butchering a cat5 cable to wire the switch to PIN5/GND & PIN6/IRQ1/D3? Will this allow me to add a temp sensor later to pins 2,4,5 as shown on this diagram - Will this need some changes to the arduino code?

Thanks in advance!

Moz

Yes, no, yes and no.
You will be better to use the RJ45 socket provided exactly for this purpose.
You cannot use that particular breakout board.
You do wire to pins 5&6.
You don’t need to modify the sketch in the Atmel processor (there’s no Arduino involved).

The interrupt pin is set as “input pullup” in the sketch, so you shouldn’t need an external pull-up resistor, though it might be necessary if you have a very long cable run with a lot of capacitance.

Thanks, I really appreciate the reply, could you clarify if it’s possible to have the Reed switch and a temp probe connected at the same time via the RJ45 socket?

Yes, there should be no interaction there - the reed switch used the interrupt input, the temperature probes (you can have more than one) the OneWire.

Please bear in mind that the code wasn’t designed to read reed switches. Reed switches show the problem of bouncing which has to be handled in the hard- or software. I use an emonTh to read the pulses of my gas meter and in the beginning it was quite bad. I counted a lot more pulses as my gas meter showed, so I started to analyze and modify the code. Now it works very well, I already counted over 11.000 pulses and didn’t miss a single one. You can find my software debounce code here: emonth2/firmware/src/src.ino at 73d6a9eacb4571cab572a90feb1bd3685340c891 · rexometer/emonth2 · GitHub

thanks for the heads up, I’ve ordered my emonPi today, so will hopefully get it installed in the coming days and have a play… I had a quick look at your code and I couldn’t quite tell how often you poll the GPIO line once you’ve detected it’s been pulled low? I’m guessing you check to make sure it’s low for a certain duration to eliminate false positives?

trying to find the equivalent line for the emonPi and I saw this bit where I think it checks a count modified by the interrupt service routine… but I couldn’t find the ISR code, any pointers on where that might be?

In the same directory.

Also, there are many threads about this in the “Archived” section.

thanks, I saw the interrupt.ino file but couldn’t see where the onPulse() callback got registered so wasn’t so sure that was it…

will have a proper look later and dig around the archives too

edit: found the bit where it’s registered