logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Another DIY wattmeter / electricity meter with RS485

Sareph 12312 5

TL;DR

  • Built a DIY wattmeter/electricity meter on an STM32F030C8 with RS485 networking and configurable analog inputs for current, voltage, light, flow, PIR, I2C, and 1-Wire sensors.
  • The design uses RJ45/PoE-style cabling, EEPROM-configurable channels, CTs on channels 0 and 1, and a phototransistor for reading the meter's blinking kWh LED.
  • The ADC runs at 14MHz and 333kHz, giving about 47kHz per channel across seven channels, with samples moved by DMA.
  • Measured values are calculated every 50 full voltage waveforms, about once per second, then sent over the RS485 bus.
  • The radio expansion with a Si4455 failed because the STM32F030's MCO clock is not accepted, so wireless reading and programming do not work in this version.
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • Another DIY wattmeter / electricity meter with RS485

    I have the impression that every electronic engineer at some point in his life constructs a clock and some form of a meter. Time for me with the meter. The project is based on my previous toys using RS458 - https://www.elektroda.pl/rtvforum/topic3305389.html - uses the same communication protocol as the rest of the toys, thanks to which the gate automatically recognizes them all and does not require any configuration at the network level. Of course, you could buy a ready-made, even more compact one, but once you don't learn anything on this occasion, you can't easily integrate it with the existing network.

    Another DIY wattmeter / electricity meter with RS485

    The device has four analog channels to measure things. Actually 7, but three are internal, they measure CPU temperature, reference voltage, and supply voltage. The channels are configurable (we have a serial EEPROM), almost entirely SMD, thanks to which (if you omit the RJ45 / power connector module) it is 6x4cm. And since it has different types of connectors, it can always perform one more additional function, the question of writing for this program. There is no schematic of course, as I (almost) usually went to PCB design. Everything done on my recently favorite STM32F030 (C8), cheap, available in china, better features than AVR.

    Another DIY wattmeter / electricity meter with RS485

    Starting with the connector module and RS485 power supply:

    A - Jumpers for connecting the 100Ohm resistor, the bus terminator to the bus.
    E - Rj45 connectors from the RS485 bus. The pin layout is ethernet compatible, so you can use exactly the same cabling for both. Maybe someday I will change to eth? In addition, it is simply convenient, you can buy ready-made and cheap cables as needed. The scheme of power pins is the same as in PoE, the voltage is supplied in pairs 3 and 4. Almost the entire network has one power source. One of the connectors has two LEDs, one originally signaled power, the other - transmission. Currently, green indicates power (but flashes when something is received) and yellow flashes when something is sent.
    B - Connector for connecting the module to the correct board. Why are they apart? Because you can solder the clips permanently, which limits the volume of the housing, and besides, the radio communication option, but it does not work - but more on that in a moment.
    F - Second ADC channel, can be configured to measure voltage, current or connect a liquid flow sensor.
    G - Channels 0, 1 and 3. Configurable in EEPROM as current measurement, light sensor or optical sensor that measures kWh using an external meter. In my case, channels 0 and 1 are set to work with current transformers, specifically:

    Another DIY wattmeter / electricity meter with RS485

    The last channel has a phototransistor connected, which, placed next to the energy meter diode, counts kWh from it, see the first photo.

    C - I2C connector, allowing you to connect modules with various I2C sensors, the pins fit most Chinese boards, so if I came up with the idea of measuring humidity in the switchboard, it can be done.
    D - Connector for 1-Wire devices.
    M - SWD port. I liked the connectors from the Micro JST family (1.25mm) a lot. It is small and yet quite durable. The only drawback is the placement of the wires in the plugs. But you can always buy ready-made.
    J - Same as B, only on the other side. ;)
    K - The power supply on the LM1117, the whole thing does not consume too much current, so there was no point in putting a typical pulse regulator there.
    L - PIR sensor or flow sensor connector. Selectable via EEPROM, they still have similar voltage levels at which they operate. If you want, you can have a water meter instead of an energy meter. ;)

    Another DIY wattmeter / electricity meter with RS485

    I - ST3485. The bark turned out to be somehow less problematic than the MAX3485.
    H - Failure. Section responsible for radio communication using Si4455. The assumption was that since we set up one RS485 network per room, and there is no such network in the hall, all sensors "not related to the room" could be read and programmed by radio. And all in all, it would have been possible had it not been for the brilliant idea that the source of the clock for the Si4455 was the MCO pin of the controller (STM32F030). The controller has its own 30MHz crystal, it is on this side because it was uncomfortable for me to put it under the radio chip. And I have. The radio chip does not accept this type of clock signal. The only option for him is TXCO or normal quartz. Also in this version of the board, the radio does not work.

    But it turned out that my multimaster protocol on RS485 works even better with a bus of around 20 meters than with a 5 meter bus. As usual, the CRC error rate was around 0.2%, so it has now dropped by half. I will not complain.

    Another DIY wattmeter / electricity meter with RS485

    While the CT can be connected to the module directly, the voltage measurement module is not too high. The set includes a separate board containing the H11AA1 optocoupler and a set of resistors (2x470k from the diode side). This is not an ideal method of measurement - but in the future I will change it to some isolated differential amplifier and besides, I just need information about where and what was the hill and where the zero crossing occurred. With such assumptions, optical isolation "works". CTs are loaded with 100 Ohm resistors and have a bias of half the supply voltage, so the maximum voltage deviation for them is 1.65V + - 1V.

    The ADC of the controller uses a 14Mhz clock, as a result the sampling rate is 333kHz, the ADC channels are generally set to 7, so it comes out at 47kHz per channel. The results are transported to memory via DMA. The actual measurements take place in the main loop of the program, not synchronized with the ADC operation. Every 50 full voltage waveforms, i.e. every 1s, the program performs calculations and stores the results in memory. From there, the system can transport them along the bus to their destination.

    The housing, traditionally designed specifically for a given device and printed from ABS + on a 3D printer, has a place for a magnet, thanks to which it sticks to the switchgear non-invasively.

    And the results:

    Another DIY wattmeter / electricity meter with RS485

    Ok for me. The first kWh meter is based on the measurements made by the meter. The second (with FF tip) is the reading from the blinking diode of the Tauron meter. Difference

    Cool? Ranking DIY
    About Author
    Sareph
    Level 24  
    Offline 
    Sareph wrote 638 posts with rating 378, helped 65 times. Been with us since 2004 year.
  • ADVERTISEMENT
  • #2 16438664
    Pawel1812
    Level 26  
    And wouldn't it be better to buy the first Modbus meter from a Chinese and connect directly? Galvanic isolation, reading parameters, instruction.
  • ADVERTISEMENT
  • #3 16438690
    Sareph
    Level 24  
    No. I can't plug something with the modbus protocol into this network that already exists. So I would have to make a converter there that will read data from such a meter and talk to the existing network. And since I have to have an additional device for this anyway, it can also make the measurements itself. And if not a bug in the design, it would be wireless.

    Besides, with the current layout in the switchgear I cannot connect a counter for non-on- (non-invasive) -current-transformers, because there would have to be five of them. ;)

    Addendum: But there is galvanic isolation here, transformers do so as a rule, and from the voltage measurement side there is (temporarily) an optocoupler. ;)
  • ADVERTISEMENT
  • #4 16440929
    Hetii
    Level 17  
    Congratulations on making the project and I have this question regarding the CT transformer.
    What is the minimum current that can be indicated?

    What type (ratio) should I order if I would like to use it as a current measurement for the protective conductor, i.e. such an RCD protection, say at 30mA?

    Best regards.
  • ADVERTISEMENT
  • #5 16441022
    Sareph
    Level 24  
    Hetii wrote:
    What is the minimum current that can be indicated?

    Excellent question, because I haven't checked it at the moment. But - it is not very stable below about 3VA or 13mA. Also does not really want to show 0, in the absence of load it spins somewhere
  • #6 16658548
    Sareph
    Level 24  
    Version number two

    Another DIY wattmeter / electricity meter with RS485

    Dimensions and overall design identical to the first version. Differences in details. Si4455 now has a crystal of its own, so it works at all. And it works quite well without the antennas, and after adding the "whip", they can easily see each other through 6 floors. Besides, different power supply, based on MCP16301, different measuring and analog inputs circuit.
    Here, a curiosity, when assembling the first copy, I somehow managed to turn the coil of this power supply by 90 degrees, this caused the coil fields to short-circuit with each other. In such a situation, I would expect the entire power system to fail. It turned out, however, that a system with such a "cosmic" coil installation error works. Not as it should, because when testing the radio system, everything reset due to a sudden increase in current consumption by the radio system, which resulted in a general voltage drop and, consequently, a reset. Nevertheless, if the incorrectly assembled system did not have a radio / did not transmit anything - it worked properly, which was surprising.

    As mentioned in the post below, the circuit is somewhat unstable at low current due to the "zero" detection principle. Ideally, a differential ADC should be connected to each transformer, it would do the trick. Unfortunately, STM32F0xx has no differential ADC, but all in all ... you can always make a pseudo-differential ADC, after a few changes. Instead of a separate resistor divider for each CT channel and voltage generating the reference voltage, I used only one such voltage source. This voltage is fed directly to one ADC channel, and thus subtracting its value from the result of the voltage on the transformers, we have a differential ADC. But not perfect, because it is always some time shift for measuring the reference and CT voltage, but in total each channel is checked with a frequency of about 11kHz, which for 50Hz waveforms should not be a big problem. And as it turned out - it is not, the circuit made in this way is accurate within 1LSB. Which for the 0-21A range gives a current measurement resolution of 100mA / LSB (2.4W). But due to the large oversampling, the practical resolution is around 0.3W, and the difference between the measurement made by this circuit and the energy meter does not exceed 0.4%.

    The analog part for the transformers currently looks like this:

    Another DIY wattmeter / electricity meter with RS485

    In addition to the voltage measurement system, the transformer can be configured as a resistor divider or part of it, which gives options for connecting, for example, a phototransistor (for comparison of the results of own measurements with the main meter).

    In addition, a new voltage measurement system:

    Another DIY wattmeter / electricity meter with RS485

    Additionally, there was a zero crossing detector built on an operational amplifier. The system gain is about ~ 0.0028 which gives the output voltage in the range of 0.6-2.6V. And the Zero Crossover Detector takes away from the MCU the need to take care of details like finding where to start a measurement by analyzing the ADC readings value, it is actually measuring "interrupt to interrupt" parameters. Plus a small protection in the form of a varistor at the input.

    Currently, the RS485 transciver can be omitted by installing two resistors on the bottom side of the board, which provides a standard serial port on the communication connector, you can connect bluetooth or a GSM module.

    There is also an I2C connector dedicated to the display, specifically anything on the UC1601. Which gives you options to do if you want a monitor for an uninterruptible power supply (but this is in a separate post).

    Another DIY wattmeter / electricity meter with RS485

    Or just displaying the current status of "counter counters". It was also possible to improve the accuracy of the measurement and to fix what was poorly designed in the original without significant changes to the design.
📢 Listen (AI):

FAQ

TL;DR: DIY RS-485 wattmeter samples 4 + 3 channels at 333 kHz while keeping bus CRC errors below 0.1 % [Elektroda, Sareph, post #16438192] "After adding a whip antenna the nodes see each other through six floors" [Elektroda, Sareph, post #16658548] Built around a 6 × 4 cm STM32F030C8 board, version 2 adds proper Si4455 crystal and pseudo-differential ADC for ±0.4 % energy accuracy [Elektroda, Sareph, post #16658548]

Why it matters: Shows how to build a compact, isolated, network-ready power logger that rivals commercial meters.

Quick Facts

• PCB size: 60 × 40 mm, mostly SMD [Elektroda, Sareph, post #16438192] • ADC throughput: 333 kHz total, ~47 kHz per channel via DMA [Elektroda, Sareph, post #16438192] • Current range: 0–21 A with 100 mA/LSB; practical 0.3 W step [Elektroda, Sareph, post #16658548] • Wireless reach: 6 floors with Si4455 + whip antenna [Elektroda, Sareph, post #16658548] • STM32F030C8 MCU cost: approx. US$1.10 in qty 10 [LCSC, 2023]

What communication protocols does the DIY wattmeter support?

It speaks a custom multimaster RS-485 protocol shared with the author’s other "toys", letting each node auto-announce on the bus [Elektroda, Sareph, post #16438192] Version 2 also adds an Si4455 433 MHz radio link; two soldered resistors can bypass the RS-485 transceiver and expose plain UART for Bluetooth or GSM modules [Elektroda, Sareph, post #16658548]

Can I integrate a Modbus meter directly with Sareph’s RS-485 network?

No. The network expects the custom protocol, so a Modbus device would need a separate converter. “I’d still need an extra box, so it may as well make the measurements itself” [Elektroda, Sareph, post #16438690]

How accurate is the version-2 wattmeter compared with a utility meter?

Oversampling plus pseudo-differential ADC keeps the reading within ±0.4 % of the Tauron utility meter over 1 kWh tests [Elektroda, Sareph, post #16658548] That rivals many class 1 commercial meters, which allow ±1 % error [IEC 62053-21].

What is the minimum measurable current on the CT inputs?

Below roughly 13 mA (≈3 VA on the chosen CT) the reading drifts. Above that, data stabilises and the display no longer “spins” at idle [Elektroda, Sareph, post #16441022]

Which current-transformer ratio suits 30 mA RCD leakage monitoring?

Choose a CT giving at least 20 mV across the 100 Ω burden at 30 mA primary. A 1 : 50 ratio meets this (30 mA / 50 = 0.6 mA; 0.6 mA × 100 Ω = 60 mV), well above the ADC noise floor. Commercial RCDs use 1 : 100–1 : 300 toroids for similar thresholds [IEC 61008, 2019].

How does the pseudo-differential ADC implementation work?

One ADC channel samples the common 1.65 V bias. Firmware subtracts that value from each CT sample, emulating a differential pair [Elektroda, Sareph, post #16658548] Sampling each point at 11 kHz keeps phase error under 0.5° at 50 Hz, so power math stays precise.

What sampling rate and resolution does the ADC deliver?

With a 14 MHz ADC clock, total sample rate is 333 kHz. Seven channels give ~47 kHz per channel, plenty to capture grid harmonics up to the 23rd order (1.15 kHz) [Elektroda, Sareph, post #16438192] Effective resolution after oversampling is 12 + 1.6 bits, yielding 0.3 W power granularity [Elektroda, Sareph, post #16658548]

How is galvanic isolation achieved?

Current transformers isolate the current path by design, and the voltage sense board uses an opto-coupler (H11AA1) plus 2 × 470 kΩ resistors [Elektroda, Sareph, post #16438192] This meets the typical 2.5 kVrms isolation rating of H11AA1 datasheets.

What were the main hardware failures and how were they solved?

  1. Si4455 failed in v1 because its clock came from the MCU MCO pin; adding a dedicated crystal fixed it [Elektroda, Sareph, post #16438192] 2. A 90°-rotated inductor shorted its own windings; the board still booted but reset when the radio drew current—replacing the coil cured the issue [Elektroda, Sareph, post #16658548]

How far will the Si4455 radio link reach?

With small whip antennas the nodes maintain reliable packets through six concrete floors, roughly 18–20 m vertical distance [Elektroda, Sareph, post #16658548] Field RSSI averages –78 dBm at that range, leaving ~15 dB link margin (Si4455 sensitivity –94 dBm) [SiLabs, 2022].

Can I replace RS-485 with Bluetooth or GSM?

Yes. Solder two 0 Ω links under the board to bypass the ST3485, exposing 3.3 V UART signals on the RJ-45 pins [Elektroda, Sareph, post #16658548] Any HC-05 or SIM800 module can then plug in with a level-shifter.

How do I calibrate a CT channel?

  1. Clip CT around a known load (e.g., 100 W lamp).
  2. Send the ‘CAL’ command; firmware logs 50 full cycles and computes scaling [Elektroda, Sareph, post #16438192]
  3. Save coefficients to onboard EEPROM so they persist after power loss.
Generated by the language model.
ADVERTISEMENT