spark_counter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
spark_counter [2015/10/25 18:04] – update attachment links kingkevin | spark_counter [2024/01/07 17:49] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | The spark counter is a custom electricity meter. | + | The spark counter is a custom electricity meter with wireless data logging capability. |
On one side I have: | On one side I have: | ||
Line 10: | Line 10: | ||
* a [[# | * a [[# | ||
* a [[http:// | * a [[http:// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | **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]].** | ||
====== peacefair PZEM-004 ====== | ====== peacefair PZEM-004 ====== | ||
- | The [[http:// | + | The [[https:// |
It: | It: | ||
* measures voltages 80-260 V AC | * measures voltages 80-260 V AC | ||
Line 22: | Line 26: | ||
* is powered using 80-260 V AC | * is powered using 80-260 V AC | ||
* provides a TTL UART port to query these values (or set an alarm so to beep when a provided power threshold is reached) | * provides a TTL UART port to query these values (or set an alarm so to beep when a provided power threshold is reached) | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
The voltage measurement is done over the power input port. | The voltage measurement is done over the power input port. | ||
Line 28: | Line 35: | ||
A drawing on the back of the device will describe how to connect the wires. | A drawing on the back of the device will describe how to connect the wires. | ||
- | The meter also provides a UART port to query the measured values. | + | {{: |
+ | |||
+ | The meter also provides a UART port (using an XH-4P connector) | ||
Two opto-couplers isolate the main power meter circuits from the TX and RX UART ports. | Two opto-couplers isolate the main power meter circuits from the TX and RX UART ports. | ||
+ | |||
+ | ^ UART ^ PZEM-004 ^ note ^ | ||
+ | | 5V | VDD | 3.3V is not enough | | ||
+ | | TX | RX | the UART pin needs to be able to sink ~4 mA | | ||
+ | | RX | TX | the UART pin needs to be idle high | | ||
+ | | GND | GND | | | ||
+ | |||
+ | 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 {{: | The {{: | ||
The UART configurations is 9600 bps 8N1. | The UART configurations is 9600 bps 8N1. | ||
- | Before querying the measurements, | + | You have to set the device' |
- | Else it won't reply to the other commands. | + | This address will be saved so the next time (even after power down) you can directly query measurements using the address(es) |
- | The manual uses an IP as address (192.168.1.1 | + | All commands include the target device address and only the device with the specified address will respond, except |
- | No idea why you would set an IP for a UART address. | + | 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: | The commands use the following 7 bytes message format: | ||
Line 59: | Line 79: | ||
Each command triggers a very loud buzzer beep (same a for the alarm). | Each command triggers a very loud buzzer beep (same a for the alarm). | ||
I removed the pizeo-element to prevent this annoying sound. | I removed the pizeo-element to prevent this annoying sound. | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
The power meter uses a single chip solution, the [[http:// | The power meter uses a single chip solution, the [[http:// | ||
Line 66: | Line 89: | ||
====== ATmega328P ====== | ====== ATmega328P ====== | ||
+ | {{: | ||
+ | {{: | ||
{{ : | {{ : | ||
Line 72: | Line 97: | ||
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). | 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 [[https://to.do|in this git]]. | + | The source code is available [[https://git.cuvoodoo.info/ |
I prefer directly writing in the registers as described in the [[http:// | I prefer directly writing in the registers as described in the [[http:// | ||
This way I learn how it works in details. | This way I learn how it works in details. | ||
Line 89: | Line 114: | ||
====== nRF24L01+ ====== | ====== nRF24L01+ ====== | ||
+ | {{: | ||
{{ : | {{ : | ||
Line 95: | Line 121: | ||
On the [[# | On the [[# | ||
- | The source code is available [[https://to.do|in this git]]. | + | The source code is available [[https://git.cuvoodoo.info/ |
On the [[# | On the [[# | ||
Line 102: | Line 128: | ||
====== Raspberry Pi ====== | ====== Raspberry Pi ====== | ||
+ | {{: | ||
{{ : | {{ : | ||
Line 108: | Line 135: | ||
To receive the measurements I used a [[# | To receive the measurements I used a [[# | ||
- | The source code is available [[https://to.do|in this git]]. | + | The source code is available [[https:// |
- | The values are then simply stored in an [[https://influxdb.com/|InfluxDB]] time series database for visualisation | + | |
[[http:// | [[http:// | ||
Line 121: | Line 147: | ||
| GPIO9/MISO | P1_21 | 7 | MISO | | | GPIO9/MISO | P1_21 | 7 | MISO | | ||
| GPIO24 | P1_18 | 8 | IRQ | | | GPIO24 | P1_18 | 8 | IRQ | | ||
+ | |||
+ | The values are then simply stored in an [[https:// | ||
+ | |||
+ | 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 [[http:// | ||
+ | I'm running grafana on my local computer (amd64), using the remote database on the RPi. | ||
+ | |||
+ | {{: | ||
+ | |||
+ |
spark_counter.txt · Last modified: 2024/01/07 17:49 by 127.0.0.1