README.md 3.3 KB

S0ImpulseCounter

Impulse Counter for keeping track of the current reading of power and gas meters with S0 impulse output.

Consists of Arduino based hardware for capturing impulses and saving the current reading in EEPROM and a Python program to log the data to InfluxDB and publish via MQTT. Also measures duration between impulses, to calculate power/current usage from that.

Intended to run (but not limited to) on a Raspberry Pi. I developed this project because directly logging impulse counters with the Raspberry Pi using GPIO inputs proved to be unreliable. I experienced missed impulses because the Pi was not running all the time, ghost impulses I don´t know why, even when always using optocouplers on the impulse inputs, and also other issues. So I decided to develop a hardware based impulse capturing module which also saves everything to EEPROM and makes losing of the total values unlikely in the future. Also this module should provide an accurate (well, relatively) measured time between impulses, in order to calculate current power or momentary usage.

The Arduino based impulse capturing unit counts impulses, increments a counter in a unit like kWh, saves this counter to EEPROM on change, and also saves impulses in between to EEPROM regularly. Impulses count is saved to a large EEPROM area organized as a ring buffer to accomplish little EEPROM wear.

Regarding the power supply there is buffer capacitor as well as a power loss detection, so that the current values can be saved to EEPROM just before power goes out. Apart from that, saving is performed in configurable intervals and when there was no impulse detected for a timeout (useful for gas counters).

Arduino (ATmega) based counter module "DualS0ImpulseCounter"

  • 2 individual inputs/counters with configurable impulses per unit
  • unit-counter is saved to EEPROM on every change
  • impulses in between are saved in configurable intervals
  • impulses counter is saved in a large ring buffer with automatic rollover to minimize EEPROM wear
  • power out detection and saving of all data before power is really gone
  • UART interface to Server/Raspberry/PC, where the actual data logging is done
  • no Arduino-like UART interface with DTS line connected (which resets the Arduino) - instead there is a software function to reset for a firmware update, and just connecting to the UART from the host does NOT reset the device. Scripts to perform Arduino/AVR firmware update from a Raspberry Pi included.

Details: Arduino counter hardware

S0Meters (Python program)

  • receives data from the module via UART
  • data logging, implemented in 2 manners:
    • InfluxDB (current total reading, momentary power/usage)
    • file log (only daily minimum and total value)
  • MQTT publishing of current values
  • calculation of momentary power/usage based on time between impulses received from capturing module
  • calculation of today´s/yesterday´s total usage (only if file logging is enabled)
  • send commands to the module over MQTT (to set readings, configuration, etc.)

Details: Python S0Meters

Node-RED UI

Straightforward Node-RED flow providing a simple UI to set current readings.

Connects to "middleware" S0Meters.py over MQTT.

Details: NodeRED-UI