CuVoodoo

the sorcery of copper

User Tools

Site Tools


spark_abacus

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
spark_abacus [2016/10/01 09:02] – [AT firmware] kingkevinspark_abacus [2024/01/07 17:49] (current) – external edit 127.0.0.1
Line 1: Line 1:
-The spark abacus is a custom electricity meter with wireless data logging capability. +{{ :spark_abacus:installation.jpg?400x0|final installation}}
-It's a follow-up to the [[spark_counter|spark counter]] for a 3 phases 4 wires electricity installation.+
  
-====== EPS8266 ======+The spark abacus is a custom electricity meter monitoring system. 
 +It's a follow-up of the [[spark_counter|spark counter]], but for a 3-phase 4-wire mains electricity power distribution installation.
  
-To send the values I used a WiFi module based on the [[http://www.esp8266.com/wiki/doku.php|ESP8266]] SoC.+It is composed by: 
 +  * 1 [[#DDM100TC|DDM100TC]] 3-phase 4-wire electricity meter with pulse output 
 +  * 3 [[#Eastron SDM120-Modbus|SDM120]] single phase electricity meter with Modbus interface (with an UART to RS-485 adapter) 
 +  * 3 [[#peacefair PZEM-004T|PZEM-004T]] single phase electricity meter with UART interface 
 +  * 1 [[stm32f1xx|STM32F1]] micro-controller to collect the measurements from the electricity meters 
 +  * 1 [[#ESP-01|ESP6266]] WiFi module to transmit the measurement values to the database 
 +  * 1 [[#Orange Pi PC|Orange Pi PC]] single board computer with [[https://influxdb.com/|InfluxDB]] time series database and [[http://grafana.org/|Grafana]] graphical monitoring tool 
 + 
 +====== prototypes ====== 
 + 
 +===== complete ===== 
 + 
 +The first prototype used an old WiFi D-Link router case. 
 +I glued a DIN-rail mount on the back to install it in the distribution panel. 
 +The development board is a small [[stm32f1xx#blue_pill|blue pill]]. 
 + 
 +I could fit all elements inside, including the three PZEM-004Ts, and had nice connectors, but it was too large to fit in the distribution panel along with the other electricity meters and RCCB. 
 + 
 +The source code and all technical details are available on [[https://git.cuvoodoo.info/kingkevin/spark_abacus/src/branch/full|git]]. 
 + 
 +{{:spark_abacus:complete-01.jpg?0x300|complete prototype, inside}} 
 +{{:spark_abacus:complete-02.jpg?0x300|complete prototype, front}} 
 +{{:spark_abacus:complete-03.jpg?0x300|complete prototype, back}} 
 + 
 +===== light ===== 
 + 
 +For this second prototype I used a broken SDM630 electricity meter case. 
 +It is smaller and is designed to fit nicely in the distribution panel. 
 + 
 +This time I did not include the PZEM-004T meters since they are to large to fit in, and would only provide information I could already get from the other electricity meters. 
 +This left a lot of space to include a larger [[stm32f1xx#system_board|development board]], and I could use dupont cables to connect all elements. 
 +I used the connector already available in the case (for two pulse outputs and one RS-485 interface) as inputs for the monitoring system (one pulse input, as RS-485 master, AC input for 5V). 
 + 
 +The source code and all technical details are available on [[https://git.cuvoodoo.info/kingkevin/spark_abacus/src/branch/light|git]]. 
 + 
 +{{:spark_abacus:light-03.jpg?0x300|light prototype, fong}} 
 +{{:spark_abacus:light-01.jpg?0x300|light prototype, inside}} 
 +{{:spark_abacus:light-02.jpg?0x300|light prototype, inside}} 
 +{{:spark_abacus:light-04.jpg?0x300|light prototype, connection}} 
 + 
 +===== improvements ====== 
 + 
 +Future improvments: 
 +  * submit measurement values to influxDB using UDP (faster, no need for credentials) 
 +  * make a bulk ModBus request to get most measurements at once (the pauses between requests for each measurement cost a lot of time) 
 +  * use an LCD to show the values (the LEDs only show the status) 
 +  * use the touch button already available on the SDM630 case 
 + 
 +====== electricity meters ====== 
 + 
 +For the spark abacus I am using several electricity meters. 
 +This just evolved over time as I wanted to try different technologies, but one (set) of them is sufficient to complete the task. 
 + 
 +===== peacefair PZEM-004T ===== 
 + 
 +The [[https://peacefair.aliexpress.com/store/1773456|pacefair]] [[https://www.aliexpress.com/store/product/PEACEFAIR-AC-100A-Electric-power-monitoring-and-communication-module-power-meter-power-energy-Volt-Ammeter-with/1773456_32405328185.html|PZEM-004T]] is an inexpensive single phase electricity meter. 
 + 
 +{{:spark_abacus:pzem-004t-02.jpg?400x0|PZEM-004T module, front side}} 
 +{{:spark_abacus:pzem-004t-03.jpg?400x0|PZEM-004T module, circuit}} 
 +{{:spark_abacus:pzem-004t-01.jpg?400x0|PZEM-004T module, back side}} 
 + 
 +Connect mains electricity (AC) and the current sensing coil (put around the wire going to the load to monitor) and this electricity meter will measure voltage, current, power (active), and energy used by the load to monitor. 
 +The energy value is saved (in EEPROM) and can be reset using the button (on the board). 
 + 
 +The device also offers a serial port (isolated from mains electricity using optocouplers) so to be able to read out the measured values. 
 +The serial protocol is the same as for the [[spark_counter#peacefair_pzem-004|PZEM-004]]. 
 + 
 +Compared to the [[spark_counter#peacefair_pzem-004|PZEM-004]] it comes without display and buzzer, but is much smaller. 
 +Else it uses the same design and chip. 
 + 
 +===== DDM100TC ===== 
 + 
 +The [[http://www.china-huabang.com/en/product-show.asp?id=31&tt=101|DDM100TC]] (you can find it under different brands) is a 3-phase 4-wire electricity meter. 
 + 
 +{{:spark_abacus:ddm100tc-01.jpg?0x200|DDM100TC module, front side}} 
 +{{:spark_abacus:ddm100tc-02.jpg?0x200|DDM100TC module, connectivity}} 
 + 
 +The meter provides: 
 +  * 1 LCD to show the energy used in kWh (with a precision od 0.1 kWh) 
 +  * 3 LEDs to show which phase powered (L1, L2, L3) 
 +  * 1 LED to show the direction to the current (reverse if REV is on) 
 +  * 1 LED to show impulses as energy is used 
 +  * 1 S0 interface to output impulses as energy is used 
 + 
 +The S0 interface (labelled TEST on the side) allows me to collect the energy used on my micro-controller. 
 +Connect the + side (pin 8) to a positive voltage (i.e. +5V), an the - side (pin 7) to an input (with a pull-down resistor). 
 +Each impulse will generate a high signal (+2.5V in my case) on - for ~ 90 ms. 
 +The number of impulses indicates the energy used, and the time interval between impulses indicates the current power consumption. 
 +I chose one with a high impulse rate of 1600 impulses/kWh (= 1 impulse for every 0.625 Wh). 
 + 
 +{{:spark_abacus:ddm100tc-03.jpg?0x150|DDM100TC module, LCD board, front side}} 
 +{{:spark_abacus:ddm100tc-06.jpg?0x150|DDM100TC module, LCD board, back side}} 
 +{{:spark_abacus:ddm100tc-04.jpg?0x150|DDM100TC module, meter board, front side}} 
 +{{:spark_abacus:ddm100tc-05.jpg?0x150|DDM100TC module, meter board, back side}} 
 + 
 +There is also the DDM100TCR model with an RS-485 interface, but I couldn't find any documentation about the protocol messages, thus I wasn't interested in this feature. 
 + 
 +===== Eastron SDM120-Modbus ===== 
 + 
 +The [[http://www.eastrongroup.com/|Eastron]] [[http://eastrongroupco.hk02.057321.com/productsview/14.html|SDM120-Modbus]] is a slim 1-phase 2-wire electricity meter. 
 + 
 +{{:spark_abacus:sdm120-02.jpg?0x200|SDM120 front}} 
 +{{:spark_abacus:sdm120-01.jpg?0x200|SDM120 side}} 
 +{{:spark_abacus:sdm120-03.jpg?0x200|SDM120 board back}} 
 +{{:spark_abacus:sdm120-04.jpg?0x200|SDM120 board side}} 
 +{{:spark_abacus:sdm120-05.jpg?0x200|SDM120 board side}} 
 + 
 +Be aware as numerous SDM120 models exist, combining following options: 
 +  * in-line current measurement or using a current sensing coil (CT) 
 +  * with electro-mechanical display or LCD, sometimes with backlight 
 +  * only with 2 pulse outputs, or with additional MBus or Modbus interface 
 + 
 +I chose the {{:spark_abacus:sdm120-modbus_user_manual_scan.pdf|SDM120 model}} (one per phase) since I wanted to learn about the RS-485 interface and Modbus protocol. 
 +The [[http://eastrongroupco.hk02.057321.com/data/uploads/Eastron_SDM120-Modbus_protocol_V2_3_(1).pdf|corresponding Modbus document]] ({{:spark_abacus:sdm120-modbus_protocol_v2.1.pdf |older v2.1}}) lists the registers containing the measurements (input registers) and configuration (holding registers). 
 +This document also explains the Modbus protocol, but I rather recommend to read the one for the [[http://eastrongroupco.hk02.057321.com/data/uploads/Eastron_SDM630MV_CT_protocol_V1_0_.pdf|SDM630]] since it contains more information, most importantly the timing between messages. 
 + 
 +====== ESP8266 ====== 
 + 
 +To send the values measured by the electricity meters and collected by the micro-controller, I used a WiFi module based on the [[http://www.esp8266.com/wiki/doku.php|ESP8266]] SoC.
  
 Several [[http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family|modules]] based on this chip exist. Several [[http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family|modules]] based on this chip exist.
-Since I only use it'WiFi functionality, and no other micro-controller capability, I used the simplest, smallest, and cheapest one, the [[http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family#esp-01|ESP-01]].+Since I only use its WiFi functionality, and no other micro-controller capability, I used the simplest, smallest, and cheapest one, the [[http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family#esp-01|ESP-01]].
  
 ===== ESP-01 ===== ===== ESP-01 =====
Line 13: Line 131:
 {{ :spark_abacus:esp-01.jpg?0x200|ESP-01 module}}{{ :spark_abacus:esp-01.svg?0x200|ESP-01 pinout}} {{ :spark_abacus:esp-01.jpg?0x200|ESP-01 module}}{{ :spark_abacus:esp-01.svg?0x200|ESP-01 pinout}}
  
-To use the device, simply connect the GND, VCC (3.3V), RX (module input), TX (module output), RST (using a pull-up resistor), and CH_PD (using a pull-up resistor) pins.+To use the device, simply connect GND, VCC (3.3V), RX (module input), TX (module output), RST (using a pull-up resistor), and CH_PD (using a pull-up resistor).
  
 ===== AT firmware ===== ===== AT firmware =====
  
 My module showed the following firmware information when powered up (with 9600 8N1 serial configuration): ''Vendor:www.ai-thinker.com Version:0.9.2.4''. My module showed the following firmware information when powered up (with 9600 8N1 serial configuration): ''Vendor:www.ai-thinker.com Version:0.9.2.4''.
-When using the ''AT+GMR'' command to get the version it returned ''0018000902-AI03''+When using the ''AT+GMR'' command to get the version it showed ''0018000902-AI03''
-This custom firmware wasn't particularly stable, so I decided to use a more recent standard one.+This custom firmware wasn't particularly stable, so I decided to use a more recent, and standard one.
  
 To flash a firmware you have to enter the bootloader mode by connecting GPIO0 to ground. To flash a firmware you have to enter the bootloader mode by connecting GPIO0 to ground.
Line 25: Line 143:
 I used [[https://github.com/themadinventor/esptool|esptool]]. I used [[https://github.com/themadinventor/esptool|esptool]].
  
-Espressif offer [[https://espressif.com/en/support/download/sdks-demos|SDKs]] for the ESP chip.+Espressif offers [[https://espressif.com/en/support/download/sdks-demos|SDKs]] for the ESP chips.
 Since I only want to use this module for its WiFi connectivity I only care about the AT firmware. Since I only want to use this module for its WiFi connectivity I only care about the AT firmware.
-The AT firmware allows to use the ESP over serial using AT commands. +The AT firmware allows to control the ESP using AT commands over serial
-This firmware is provided in the NONOS SDKs (V2.0.0 since 2016-08-10).+This firmware is provided in the NONOS SDKs (V2.0.0 as of 2016-08-10).
  
 The module I had uses a 25Q40 flash chip with only 4Mbits/512KBytes. You can also identity using esptool: The module I had uses a 25Q40 flash chip with only 4Mbits/512KBytes. You can also identity using esptool:
Line 74: Line 192:
 But again, this is just if you have only 4 Mbits (512KBytes) of flash. But again, this is just if you have only 4 Mbits (512KBytes) of flash.
 It is now also possible to get ESP-01 modules with 8 Mbits / 1 MByte of flash, which supports more recent AT firmwares. It is now also possible to get ESP-01 modules with 8 Mbits / 1 MByte of flash, which supports more recent AT firmwares.
 +
 +====== Orange Pi PC ======
 +
 +{{:spark_abacus:opi-01.jpg?0x200|Orange Pi PC, front side}}
 +{{:spark_abacus:opi-02.jpg?0x200|Orange Pi PC, without heat sink}}
 +{{:spark_abacus:opi-03.jpg?0x200|Orange Pi PC, back side}}
 +
 +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 (SBC) is based on an [[https://linux-sunxi.org/H3|Allwinner H3 (sun8iw7p1)]] SoC with ARM Cortex-A7 @ 1.2GHz (often over-clocked), and 1 GB of RAM.
 +
 +For this price the hardware is unbeatable, but the software support is really poor.
 +Also only Android supports the video hardware acceleration currently.
 +The official [[http://www.orangepi.org/downloadresources/|images]] are quite old (e.g. Android 4.2.2), but there are a bit newer images made available by the community:
 +  * [[http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=755|Android]] (often ROMs from other Allwinner based products), with a 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]] distributions
 +Since I'll only use it as server I decided to go with an [[https://www.armbian.com/orange-pi-pc/|armbian]] debian jessie image.
 +
 +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]], but seeing the support of the OS I wouldn't rely on the hardware drivers.
 +I am only using this SBC a cheap computer rather than hardware platform.
 +Also, don't forget to put a heat sink on the CPU, else they will be slowed down quite often because of the high temperatures.
 +
 +On it I've installed an [[https://www.influxdata.com/|InfluxDB]] time-series database to store the values (using the HTTP API), and [[http://grafana.org/|Grafana]] to visualize them.
 +
 +{{:spark_abacus:grafana.png?1000x0|simple display of the power consumption}}
spark_abacus.1475312579.txt.gz · Last modified: 2024/01/07 17:49 (external edit)