Skip to content

Arduino Nano substitute for a RS485 3 Phase DTSU666-H coil based power meter. Less resolution, but better display

License

Notifications You must be signed in to change notification settings

ArminJo/Arduino-DTSU666H_PowerMeter

Repository files navigation

Substitutes the RS485 modbus service of DTSU-H coil based 3 phase power meter for usage with a Deye hybrid inverter.
On phase L1 it reads every 4. current waves, on phase L2 and L3 it reads only every 8. half wave.

Badge License: GPLv3     Badge Version     Badge Commits since latest     Badge Build Status     Badge Hit Counter

If you find this program useful, please give it a star.

🌎 Google Translate


Features

  • Astonishing accuracy of 1% at my site.
  • Every watt-hour, the build-in LED flashes for 30 ms. On negative energy it flashes twice.
  • 2 buttons to set a correction percentage other than 100% - which was not required at my site :-).
  • Display of Power, Energy, Time for energy and correction percentage on a locally attached 1602 LCD.
  • Page button for switching 4 LCD display pages.
  • Debug button/switch for realtime monitoring analog current and voltage of 4 different half waves with Arduino Plotter.
  • Serial.print() is still available for monitoring and debugging.
  • Watchdog reset after 8 seconds. It resets the CPU, e.g. if zero voltage crossing cannot be determined, or the program hangs at another location.
  • Display of watchdog reset reason, which currently (3/2024) only works with optiboot 8.1 bootloader.

Modbus sniffer

For all, which want to see the values sent by a real DTSU666 or see the vlues sent by this program e.g. at the other end of the RS485 line, this repository contains a simple Modbus sniffer program. It displays the power values on a 1602 serial LCD.


Modbus sending and receiving

Modbus reply sending at 9600 baud is done by SoftwareSerialTX. This enables the usage of the Arduino Serial for monitoring and debugging.
Modbus receiving at 9600 baud is done by standard Arduino Serial at 9600 baud.
Monitoring output is done by switching Arduino Serial baudrate to 115200 baud, send data, flush it and reset Arduino Serial baudrate back to 9600 baud.
During monitoring output, receiving of modbus requests is therefore disturbed!


Principle of operation

We assume, that voltage waveform of the 3 phases are equal and negative and positive values are symmetric, so we take only one half wave as voltage reference.

Phase A is reference (the one, which supplies the voltage and which can be negative), phase B has a delay of 6.6 ms / 120 ° and C a delay of 13.3 ms / 240 °.

  1. Read "positive" part voltage values of phase A for 10 ms and store 385 values in RAM to be used as reference for all 3 phases. This starts 16 Bit timer 1 to keep track of the phase for the next current measurements.
  2. Wait 3.3 ms.
  3. After 10 + 3.333 ms do 10 ms phase C current measurement. Multiply values with voltage.
  4. Wait 3.3 ms.
  5. After 20 + 6.666 ms do 10 ms phase B current measurement. Multiply values with voltage.
  6. Wait 3.3 ms
  7. After 40 ms do 20 ms phase A current measurement, which will also cover negative current. Multiply values with voltage.
  8. 20 ms for math and reply to RS485 or output to LCD until starting again at 80 ms - x ms.

The Deye inverter sends a 9600 baud modbus request 01 03 15 1E 00 06 A1 C2 every 100 ms to 120 ms.
We send the reply at pin 2 with software serial at a 80 ms raster.
This means, around every 400 ms we have one loop where we do not need to reply and can update the LCD instead.
Sometimes the Deye sends the request, while we do a reply.


Pictures

My installation Display and buttons
My installation Display and buttons
Breadboard detail Automatic brightness
Breadboard detail Automatic brightness
Split-core current transformers used Deye settings
Split-coil Deye settings
DTSU666ModbusSniffer
DTSU666ModbusSniffer

Example on Wokwi

Also usable as connection schematic.


Screenshots

LCD pages

Power page Energy page
Power page Energy page
Time for Energy page Period page
Time for Energy page Period page

Arduino plotter output of measured currents

Reference phase - positive half wave Reference phase - negative half wave
Reference positive Reference negative
6.6 ms / 120 ° delayed phase 13.2 ms / 240 ° delayed phase
7 ms 13 ms
6.6 ms / 120 ° without low-pass 13.2 ms / 240 ° without low-pass
7 ms without low-pass 13 ms without low-pass

 Implemented with 3 x 30A split-core current transformers.
 2. order low pass 1600 Hz, to suppressthe high frequency modulation of current as seen above.
               ____         ____         _____
          o---|____|---o---|____|---o---|_____|---o-----> A1 (A2, A3)
          |     1k     |     1k     |     10k     |
 Split-   >            |            |             |
 core    <            ---          ---            | Schottky diode
 coil     >           --- 100 nF   --- 100 nF     o-|<|-o
         <             |            |                   |
        __|____________|____________|___________________|__ GND




Grid voltage divider for full range (1.1 V) at 400 V.

HIGH VOLTAGE - DANGER - use heat-shrink tubing
             ____     ____     ____     _____
230V~ L1 >--|____|---|____|---|____|---|_____|---o-----o-----> A0
              1M       1M       1M      630 k    |     |
                                                 _     |
                                                | |    | Schottky diode
                                                | |    o-|<|-o
                                                |_|          |
                                                 |           |
                                               __|___________|__ N (GND)




  # Automatic brightness control for 1602 LCD
   5V O------o------o
             |      |
             _      |
            | |     |
        LDR | |     |
            |_|     |
             |    |/
             o----|
                  |>
                    |
                    O To anode of LCD backlight


Compile with the Arduino IDE

Download and extract the repository. In the Arduino IDE open the sketch with File -> Open... and select the Arduino-DTSU666H_PowerMeter folder.
All libraries, especially the modified ones, are included in this project.


Libraries used

This program uses the following libraries, which are already included in this repository:


BOM

  • Breadboard.
  • Jumper wire and cables.
  • Pin header to connect cables to breadboard.
  • Arduino Nano.
  • TTL to RS485 converter module with 74HC04 and MAX485.
  • 10 nF capacitor to increase the C2 capacitor on the module, preventing the module (using 74HC04 instead of 74HC06) from ringing.
  • 4 Schottky diodes for the 4 analog pins used e.g. BAT 42, BAT 43, BAT 85.
  • 6 x 100 nF capacitors and 6 x 1 kOhm resistors for the 3 low-passes.
  • 3 x 1 MOhm + 630 (680) kOhm + 10 kOhm for the 230 V voltage divider.
  • Power supply.
  • 1602 LCD.
  • LDR for automatic LCD brightness control.
  • BC 549 or any NPN type for automatic LCD brightness control. The effect varies, depending on the LDR and the hFE of the transistor.

Tested Inverter

  • SUN-5K-SG05LP1-EU

Useful Links

Revision History

Version 1.1

  • Added reply to 0x2014 (Power in 0.1 W units) and 0x0006 (Current transformer rate IrAt).

Version 1.0

  • Initial version.

Sample Serial output

See also here.

START ../src/Arduino-DTSU666H_PowerMeter.cpp
Version 1.0 from Sep 19 2023_
If you connect periodically print pin A4 to ground, Serial plotter data is printed every 2000 ms
Power correction + pin is 5
Power correction - pin is 4
LCD data is printed every (8 * 80) ms
Reference line, which can be negative is 2
Line, with 6.6 ms delay is 1
Line, with 13.3 ms delay is 3
Waiting for requests to ID MODBUS_SLAVE_ADDR with _9600_ baud at pin RX. Reply / TX is on pin 2
First waiting for voltage at line2
Power correction is 100 %