The spark counter is a custom electricity meter with wireless data logging capability.
On one side I have:
On the other side:
warning: the electricity meter I am presenting will only work for 1-phase 2-wire power distribution systems. I have a 3-phase 4-wire system and I was doing it wrong. This has been fixed with the spark abacus.
The voltage measurement is done over the power input port. The current measurement is done using a coil. Pass the wire on which you would like to measure the current through the coil, and connect the coil to the power meter. A drawing on the back of the device will describe how to connect the wires.
The meter also provides a UART port (using an XH-4P connector) to query the measured values. Two opto-couplers isolate the main power meter circuits from the TX and RX UART ports.
|3.3V is not enough
|the UART pin needs to be able to sink ~4 mA
|the UART pin needs to be idle high
I used a CP2102 based USB to UART converter. CH340 based USB to UART converters will not work (it seems to not be able to sink enough current). And when using the Arduino you should not use the USB port (for serial), since that interferes with the UART signals.
The manual provides the corresponding commands, but lacks some information. The UART configurations is 9600 bps 8N1. You have to set the device's address (i.e. C0 A8 01 01 = 192.168.1.1 in the examples) at least once using the 0xB4 command before querying measurements. This address will be saved so the next time (even after power down) you can directly query measurements using the address(es) set in the device(s). All commands include the target device address and only the device with the specified address will respond, except for the command setting the address in the first place. This allows to query multiple devices connected to the same UART port, one after another, when they have different addresses. Note: the optocouplers on the Tx pin of the device have a pull-up resistor. Be sure to remove all but one when using multiple devices, else the low value of the signal will be too high for the receiver to decode the serial communication.
The commands use the following 7 bytes message format:
Have a look at the manual for examples. Each command triggers a very loud buzzer beep (same a for the alarm). I removed the pizeo-element to prevent this annoying sound.
The power meter uses a single chip solution, the SDIC microelectronics SD3004 (datasheet). This chip does all the necessary work: measure voltage and current, drive the 7-segments LED displays, communicate over UART. There is only an additional external I²C EEPROM to store the global energy consumption.
To read out the measurements from the power meter and send them over radio I used an Atmel ATmega328P micro-controller. Because the development board costs less than the chip itself I simply used a cheap Arduino Nano clone.
USART to query the power meter, SPI to communicate with the nRF24L01+, and the nRF24L01+ protocol are implemented in C (using a lot of interrupts). The source code is available in this git. I prefer directly writing in the registers as described in the datasheet rather than using an abstract IDE and libraries. This way I learn how it works in details.
Arduino - nRF24L01+ connection:
|Arduino Nano pin
|nRF24L01+ board pin
|3V (add cap.)
To transmit the measurements from the ATmega328P to the RPi I used nordic nRF24L01+ RF transceivers. There are very inexpensive, require low power, provide enough bandwidth for such application, are easy to control, and because I always wanted to try them out.
RPi - nRF24L01+ connection:
|nRF24L01+ board pin
Note: there is no ARM build of grafana (armel for RPi 1, armhf for later versions). This is also because there is no ARM release of PhantomJS. I'm running grafana on my local computer (amd64), using the remote database on the RPi.