I have a kWh meter that has an S0 pulse output. For the past week I have tried to get the raspberry pi to count the pulses but I am unsuccessful. There isn't much documentation since I got the meter from China.

The limited documentation that it does have says that the output has 3200 impulses per kWh and the pulse length is at least 30ms long. The one part of the documentation that I don't understand is that it just has a line that says 18-27V at 27mA. I'm not sure if this means that I need to put in 18-27V, or, if the output is 18V-27V, or, if it can work at a max of 18-127V.
+
I've tried to connect it in many ways and it doesn't work. I attached one of the GPIO pins with an internal pull-up to the + pin of the meter and I connected the - min of the meter to the ground of the raspberry pi. In terms of software I have a loop that waits for a falling edge and increments a counter by 1 every time it sees the edge and prints the count number.

I wouldn't have connected my Pi to anything without a lot more infomation about what's coming out of it, but since you have, and (I assume) not broken anything, ...

The "line that says 18-27V at 27mA" is fairly meaningless.
It could mean "nothing will happen if you give it less than 18V, and it'll break if you give it more than 27V"
Or maybe "It gives out between 18V and 27V. Don't take more than 27mA or you'll break it"

So measure the pins with your multimeter. If there's no voltage, try Ohms.
Try a 2k resistor and a LED across the pins. Then try connecting a couple of 9v batteries in series (reversing the LED)

matizzy wrote:I've tried to connect it in many ways and it doesn't work. I attached one of the GPIO pins with an internal pull-up to the + pin of the meter and I connected the - min of the meter to the ground of the raspberry pi. In terms of software I have a loop that waits for a falling edge and increments a counter by 1 every time it sees the edge and prints the count number.

If your lucky the legend means that the meter output tolerates an external voltage of 18 - 27V (nominal 24V?) and will sink up to 27mA. Nothing happens because you aren't supplying a suitable voltage.

If you are unlucky the meter outputs a poorly regulated ~24V which you have connected to a 3.3V input and destroyed a GPIO input.

Step one is to test your GPIO input, With it configured as input ground the GPIO pin and check that your code, or command line GPIO read detects the changing state.

Check your code does basic pulse counting stand-alone.

If you connect two 9V batteries in series you get 18V. Wire that in series with an 1k ohm resistor and an LED.
Batt+ --> resistor --> LED Anode | LED Cathode --> Meter+ | Meter - --> Batt-

The resistor limits the short cicuit current to 18/1000 = 18 mA, which is within the meter rating.
Hopefully the meter will be low impedance when pulsing and current will flow in the LED lighting it up.
Voltage across the (red) LED will be ~2V and current will be ! 16/1000 = 16mA

Do not connect this circuit to your Pi!

If that works you will need to convert from 18V to 3.3V. Buy an opto-isolator and connect its LED terminals in place of, or series with, the LED in the circuit described above.

Now you should have a stransistor output in the Opto-isolator that you can conect to a GPIO input. Collector pin to GPIO, emitter pin to Pi 0V.

You don't need any electrical connections between the meter and the Pi.

If you can now count pulses from the meter you will need to sort out a permanent power supply. You may find it easier to find 24V supplies. 24 - 2V(LED) - 2V(opto-isolator) = 20V
20V/1000 = 20mA

The only difference in our meters is that his is a 3-wire meter meant for 230v while mine is a 2 wire meant for 120v. I tried wiring mine in the same way to his, but nothing worked. I'm thinking that it is most likely a software issue.

So, I suggest you test the SO pulse output using a multimeter, continuity tester or LED+resistor+battery.
Test your GPIO input with the 200 ohm resistor to GND. If both work independently then connect them together.

Do you have a link to the datasheet for the pulse meter that you are using?
The reason that I ask is that different energy meters operate in different fashions, if your meter is a two wire one then it will probably need a different set of connections from the three wire pulse meter in the link you gave.

First step is to get the meter wired up correctly and setup to give the correct pulses.

Although this is a fairly old thread, but www.smartmeterdashboard.nl sells S0 pulse counter modules (site is in Dutch but via Google translate you will get the info)
They are mentioned by Domoticz that runs on a RPi.

I know this is an old post, but I found a simple solution to connect a Pi to the SO output

The output side of the SO is quite simple to use and is not to be confused with the optical side of the device (the LED inside the optoisolator)

Configure IO pin on PI to use internal pull-up (so that the pi will pull it high to 3.3V)

This pin can be connected to the + on the SO whilst connecting the other pin of the SO to any of the GND pins on the PI.

What will happen in this scenario is that when the optoisolator (High voltage side of the optical isolator (or LED internally for lack of a better term) turns on it will cause the resistance on the SO side to drop out causing the pin on the PI input pin mentioned above to be pulled down to GND.

The power meter I am using gives 1600 impulses per KWh used so its basically counting the number of pulses received in a given period, multiplying that to match a timeline of one hour and then dividing it into 1600 to get the KWh currently going through the meter.

Lets say I count 10 impulses in a 10 second period, that would translate to 10*6*60 impulses per hour if extrapolated which would mean 10*6*60 = 3600 impulses projected per hour... 3600/1600 = 2.25KWh

From this one can do other math for example lets say I have 220V AC and I want the current (Amperage)