CuVoodoo

the sorcery of copper

User Tools

Site Tools


spark_counter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
spark_counter [2015/10/25 17:24] – moved from power monitor kingkevinspark_counter [2015/12/08 16:22] – [Raspberry Pi] kingkevin
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 8: Line 8:
 On the other side: On the other side:
   * a [[#nRF24L01+|nRF24L01+ radio]] to receive the values   * a [[#nRF24L01+|nRF24L01+ radio]] to receive the values
-  * a [[#Raspberry Pi|Raspberry Pi single board computer]] to store the measurements +  * a [[#Raspberry Pi|Raspberry Pi single board computer]] to store the measurements in an [[https://influxdb.com/|influxDB time series database]] 
-  * a gradana graphical monitoring tool to display the electricity consumption+  * a [[http://grafana.org/|grafana graphical monitoring tool]] to display the electricity consumption 
 + 
 +{{:spark_counter:dsc02371.jpg?0x300|complete spark counter}}
  
 ====== peacefair PZEM-004 ====== ====== peacefair PZEM-004 ======
  
-The [[http://www.aliexpress.com/wholesale?catId=0&SearchText=peacefair|peacefair]] [[http://www.aliexpress.com/wholesale?catId=0&SearchText=peacefair+pzem-004|PZEM-004]] is a simple power meter.+The [[http://www.aliexpress.com/wholesale?catId=0&SearchText=peacefair|peacefair]] [[http://www.aliexpress.com/wholesale?catId=0&SearchText=peacefair+pzem-004|PZEM-004]] is a simple power meter ({{:spark_counter:peacefair_pzem-004_porduct.pdf|datasheet}}).
 It: It:
   * measures voltages 80-260 V AC   * measures voltages 80-260 V AC
Line 22: Line 24:
   * 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)
 +
 +{{:spark_counter:dsc02361.jpg?0x200|PZEM-004 front}}
 +{{:spark_counter:dsc02359.jpg?0x200|PZEM-004 back}}
  
 The voltage measurement is done over the power input port. The voltage measurement is done over the power input port.
Line 27: Line 32:
 Pass the wire on which you would like to measure the current through the coil, and connect the coil to the power meter. 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. A drawing on the back of the device will describe how to connect the wires.
 +
 +{{:spark_counter:dsc02328.jpg?0x200|PZEM-004 opto-couplers}}
  
 The meter also provides a UART port to query the measured values. The meter also provides a UART port to query the measured values.
 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.
  
-The {{:power_meter:pzem-004.rtf|manual}} provides the corresponding commands, but lacks some information.+The {{:spark_counter:pzem-004.rtf|manual}} provides the corresponding commands, but lacks some information.
 The UART configurations is 9600 bps 8N1. The UART configurations is 9600 bps 8N1.
 Before querying the measurements, you have to set an address to the device. Before querying the measurements, you have to set an address to the device.
Line 60: Line 67:
 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://www.sdicmicro.com/products.html?ic=SD3004|SDIC microelectronics SD3004]] ({{:power_meter:sd3004_datasheet_v0.2c.pdf|datasheet}}).+{{:spark_counter:dsc02344.jpg?0x200|PZEM-004 board front}} 
 +{{:spark_counter:dsc02325.jpg?0x200|PZEM-004 board back}} 
 +{{:spark_counter:dsc02327.jpg?0x200|PZEM-004 board IC}} 
 + 
 +The power meter uses a single chip solution, the [[http://www.sdicmicro.com/products.html?ic=SD3004|SDIC microelectronics SD3004]] ({{:spark_counter:sd3004_datasheet_v0.2c.pdf|datasheet}}).
 This chip does all the necessary work: measure voltage and current, drive the 7-segments LED displays, communicate over UART. 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. There is only an additional external I²C EEPROM to store the global energy consumption.
Line 66: Line 77:
 ====== ATmega328P ====== ====== ATmega328P ======
  
-{{ :power_meter:ic_dev_arduino_nano-30.svg?400|Arduino Nano pinout}}+{{:spark_counter:dsc02354.jpg?0x200|development board}} 
 +{{:spark_counter:dsc02365.jpg?0x200|development setup}} 
 +{{ :spark_counter:ic_dev_arduino_nano-30.svg?400|Arduino Nano pinout}}
  
 To read out the measurements from the [[#peacefair PZEM-004|power meter]] and send them over [[#nRF24L01+|radio]] I used an [[http://www.atmel.com/devices/atmega328p.aspx|Atmel ATmega328P]] micro-controller. To read out the measurements from the [[#peacefair PZEM-004|power meter]] and send them over [[#nRF24L01+|radio]] I used an [[http://www.atmel.com/devices/atmega328p.aspx|Atmel ATmega328P]] micro-controller.
Line 72: Line 85:
  
 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/kingkevin/spark_counter/tree/master|in this git]].
 I prefer directly writing in the registers as described in the [[http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf|datasheet]] rather than using an [[https://www.arduino.cc/en/Main/Software|abstract IDE]] and [[https://github.com/TMRh20/RF24|libraries]]. I prefer directly writing in the registers as described in the [[http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf|datasheet]] rather than using an [[https://www.arduino.cc/en/Main/Software|abstract IDE]] and [[https://github.com/TMRh20/RF24|libraries]].
 This way I learn how it works in details. This way I learn how it works in details.
Line 89: Line 102:
 ====== nRF24L01+ ====== ====== nRF24L01+ ======
  
-{{ :power_meter:nrf24l01_pinout.jpg?250|nRF24L01+ pinout}}+{{:spark_counter:dsc02353.jpg?0x150|nRF24L01+ module}} 
 +{{ :spark_counter:nrf24l01_pinout.jpg?250|nRF24L01+ pinout}}
  
 To transmit the measurements from the [[#ATmega328P]] to the [[#Raspberry Pi|RPi]] I used [[https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P|nordic nRF24L01+]] RF transceivers. To transmit the measurements from the [[#ATmega328P]] to the [[#Raspberry Pi|RPi]] I used [[https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P|nordic nRF24L01+]] RF transceivers.
Line 95: Line 109:
  
 On the [[#ATmega328P|micro-controller]] side I implemented the complete SPI-based protocol using the [[https://www.nordicsemi.com/eng/content/download/2726/34069/file/nRF24L01P_Product_Specification_1_0.pdf|datasheet]]. On the [[#ATmega328P|micro-controller]] side I implemented the complete SPI-based protocol using the [[https://www.nordicsemi.com/eng/content/download/2726/34069/file/nRF24L01P_Product_Specification_1_0.pdf|datasheet]].
-The source code is available [[https://to.do|in this git]].+The source code is available [[https://git.cuvoodoo.info/kingkevin/spark_counter/tree/master|in this git]].
  
 On the [[#Raspberry Pi|computer]] side I use the [[https://github.com/TMRh20/RF24|RF24 library]]. On the [[#Raspberry Pi|computer]] side I use the [[https://github.com/TMRh20/RF24|RF24 library]].
Line 102: Line 116:
 ====== Raspberry Pi ====== ====== Raspberry Pi ======
  
-{{ :power_meter:pi-gpio-header-26-sm.png?200|RPi P1 header}}+{{:spark_counter:dsc02375.jpg?0x200|RPi setup}} 
 +{{ :spark_counter:pi-gpio-header-26-sm.png?200|RPi P1 header}}
  
 To store the measurements I use a [[https://www.raspberrypi.org/products/model-b/|Raspberry Pi Model B1]] ([[http://elinux.org/RPi_HardwareHistory|rev 0002]]). To store the measurements I use a [[https://www.raspberrypi.org/products/model-b/|Raspberry Pi Model B1]] ([[http://elinux.org/RPi_HardwareHistory|rev 0002]]).
Line 108: Line 123:
  
 To receive the measurements I used a [[#nRF24L01+|nRF24L01+ transceiver]] with the [[https://github.com/TMRh20/RF24|RF24 library]]. To receive the measurements I used a [[#nRF24L01+|nRF24L01+ transceiver]] with the [[https://github.com/TMRh20/RF24|RF24 library]].
-The source code is available [[https://to.do|in this git]]. +The source code is available [[https://git.cuvoodoo.info/kingkevin/spark_counter/tree/master|in this git]].
-The values are then simply stored in an [[https://influxdb.com/|InfluxDB]] time series database for visualisation in [[#grafana]].+
  
 [[http://elinux.org/RPi_Low-level_peripherals#P1_Header|RPi]] - nRF24L01+ connection: [[http://elinux.org/RPi_Low-level_peripherals#P1_Header|RPi]] - nRF24L01+ connection:
Line 121: Line 135:
 | 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://influxdb.com/|InfluxDB]] time series database for visualisation in [[http://grafana.org/|grafana]].
 +
 +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://phantomjs.org/|PhantomJS]].
 +I'm running grafana on my local computer (amd64), using the remote database on the RPi.
 +
 +{{:spark_counter:grafana.png?0x200|grafana visualization}}
 +
 +====== Orange Pi ======
 +
 +There is no armel build of grafana for the Raspberry Pi, and compiling it from source wasn't possible because 256MB of RAM aren't enough.
 +Thus I tried to use a Orange Pi since it was also lying around.
 +
 +The [[http://www.orangepi.org/orangepipc/|Orange Pi PC]] is a cheap [[http://www.aliexpress.com/item/Orange-Pi-PC-ubuntu-linux-and-android-mini-PC-Beyond-and-Compatible-with-Raspberry-Pi-2/32448079125.html|$15 alternative]] to the Raspberry Pi 2.
 +This single board computer is based on an [[https://linux-sunxi.org/H3|Allwinner H3 (sun8iw7p1)]] SoC with ARM Cortex-A7 @ 1.8GHz, and 1 GB of RAM.
 +That should be plenty to compile and run grafana.
 +
 +For this price the hardware is unbeatable, but the software support is quite poor (outdated but indicating [[http://www.orangepi.org/Docs/FAQ.html|FAQ]]).
 +Only Android supports the video hardware acceleration currently.
 +The official [[http://www.orangepi.org/downloadresources/|images]] are old (e.g. Android 4.2.2), but there are newer images made available by the community:
 +  * such as [[http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=755|Android]], with weird [[http://www.orangepi.org/Docs/SDcardinstallation.html#Install_Android_OS_image|installation process]]
 +  * various [[http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=342|linux]]
 +Since I'll only use it as server I decided to go with debian jessie minimal.
 +
 +The pin header is the same as the [[http://www.raspberry-projects.com/pi/pi-hardware/raspberry-pi-2-model-b/rpi2-model-b-io-pins|40-pin Raspberry Pi]].
spark_counter.txt · Last modified: 2024/01/07 17:49 by 127.0.0.1