spark_counter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
spark_counter [2015/12/05 12:54] – add git link kingkevin | spark_counter [2016/10/04 21:23] – [Orange Pi] moved to spark abacus kingkevin | ||
---|---|---|---|
Line 12: | Line 12: | ||
{{: | {{: | ||
+ | |||
+ | **warning: the electricity meter I am presenting will only work for 1 phase 2 wires power distribution systems. I have a 3 phases 4 wires system and I am doing it wrong.** | ||
====== 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 35: | Line 37: | ||
{{: | {{: | ||
- | 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 | + | All commands include a device address (i.e. C0 A8 01 01 = 192.168.1.1). |
- | Else it won't reply to the other commands. | + | Only the device with the specified address will respond. |
- | The manual uses an IP as address (192.168.1.1 = C0 A8 01 01). | + | This allows to query multiple devices on the same UART port, one after another, when they have different addresses. |
- | No idea why you would set an IP for a UART address. | + | Thus you have to set the device' |
+ | This address | ||
The commands use the following 7 bytes message format: | The commands use the following 7 bytes message format: | ||
Line 85: | Line 98: | ||
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:// | + | The source code is available [[https:// |
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 109: | Line 122: | ||
On the [[# | On the [[# | ||
- | The source code is available [[https:// | + | The source code is available [[https:// |
On the [[# | On the [[# | ||
Line 123: | Line 136: | ||
To receive the measurements I used a [[# | To receive the measurements I used a [[# | ||
- | The source code is available [[https:// | + | The source code is available [[https:// |
[[http:// | [[http:// | ||
Line 137: | Line 150: | ||
The values are then simply stored in an [[https:// | 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