Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added registers #3

Merged
merged 1 commit into from
Oct 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 75 additions & 26 deletions SDM220_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,84 @@
#include <Arduino.h>
#include <SoftwareSerial.h>
//------------------------------------------------------------------------------
#define SDM_BAUD 4800 //baudrate
#define MAX_MILLIS_TO_WAIT 1000 //max time to wait for responce from SDM
#define SDM_READ_EVERY 1000 //read SDM every ms
#define SDM_BAUD 4800 //baudrate
#define MAX_MILLIS_TO_WAIT 1000 //max time to wait for responce from SDM
#define SDM_READ_EVERY 1000 //read SDM every ms

#define SDMSER_RX 12 //RX-D6(wemos)-12
#define SDMSER_TX 13 //TX-D7(wemos)-13
#define SDMSER_RX 12 //RX-D6(wemos)-12
#define SDMSER_TX 13 //TX-D7(wemos)-13

#define FRAMESIZE 9 //size of out/in array
#define FRAMESIZE 9 //size of out/in array
//------------------------------------------------------------------------------
#define SDM_B_01 0x01 //BYTE 1
#define SDM_B_02 0x04 //BYTE 2
//BYTES 3 & 4 (BELOW)
#define SDM_VOLTAGE 0x0000 //V
#define SDM_CURRENT 0x0006 //A
#define SDM_POWER 0x000C //W
#define SDM_ACTIVE_APPARENT_POWER 0x0012 //VA
#define SDM_REACTIVE_APPARENT_POWER 0x0018 //VAR
#define SDM_POWER_FACTOR 0x001E //
#define SDM_PHASE_ANGLE 0x0024 //DEGREE
#define SDM_FREQUENCY 0x0046 //Hz
#define SDM_IMPORT_ACTIVE_ENERGY 0x0048 //Wh
#define SDM_EXPORT_ACTIVE_ENERGY 0x004A //Wh
#define SDM_IMPORT_REACTIVE_ENERGY 0x004C //VARh
#define SDM_EXPORT_REACTIVE_ENERGY 0x004E //VARh
#define SDM_TOTAL_ACTIVE_ENERGY 0x0156 //Wh
#define SDM_TOTAL_REACTIVE_ENERGY 0x0158 //VARh

#define SDM_B_05 0x00 //BYTE 5
#define SDM_B_06 0x02 //BYTE 6
#define SDM_B_01 0x01 //BYTE 1
#define SDM_B_02 0x04 //BYTE 2
//BYTES 3 & 4 (BELOW)
#define SDM120C_VOLTAGE 0x0000 //V
#define SDM120C_CURRENT 0x0006 //A
#define SDM120C_POWER 0x000C //W
#define SDM120C_ACTIVE_APPARENT_POWER 0x0012 //VA
#define SDM120C_REACTIVE_APPARENT_POWER 0x0018 //VAR
#define SDM120C_POWER_FACTOR 0x001E //
#define SDM120C_FREQUENCY 0x0046 //Hz
#define SDM120C_IMPORT_ACTIVE_ENERGY 0x0048 //Wh
#define SDM120C_EXPORT_ACTIVE_ENERGY 0x004A //Wh
#define SDM120C_TOTAL_ACTIVE_ENERGY 0x0156 //Wh

#define SDM220T_VOLTAGE 0x0000 //V
#define SDM220T_CURRENT 0x0006 //A
#define SDM220T_POWER 0x000C //W
#define SDM220T_ACTIVE_APPARENT_POWER 0x0012 //VA
#define SDM220T_REACTIVE_APPARENT_POWER 0x0018 //VAR
#define SDM220T_POWER_FACTOR 0x001E //
#define SDM220T_PHASE_ANGLE 0x0024 //DEGREE
#define SDM220T_FREQUENCY 0x0046 //Hz
#define SDM220T_IMPORT_ACTIVE_ENERGY 0x0048 //Wh
#define SDM220T_EXPORT_ACTIVE_ENERGY 0x004A //Wh
#define SDM220T_IMPORT_REACTIVE_ENERGY 0x004C //VARh
#define SDM220T_EXPORT_REACTIVE_ENERGY 0x004E //VARh
#define SDM220T_TOTAL_ACTIVE_ENERGY 0x0156 //Wh
#define SDM220T_TOTAL_REACTIVE_ENERGY 0x0158 //VARh

#define SDM630_VOLTAGE1 0x0000 //V
#define SDM630_VOLTAGE2 0x0002 //V
#define SDM630_VOLTAGE3 0x0004 //V
#define SDM630_CURRENT1 0x0006 //A
#define SDM630_CURRENT2 0x0008 //A
#define SDM630_CURRENT3 0x000A //A
#define SDM630_CURRENTSUM 0x0030 //A
#define SDM630_POWER1 0x000C //W
#define SDM630_POWER2 0x000E //W
#define SDM630_POWER3 0x0010 //W
#define SDM630_POWERTOTAL 0x0034 //W
#define SDM630_VOLT_AMPS1 0x0012 //VA
#define SDM630_VOLT_AMPS2 0x0014 //VA
#define SDM630_VOLT_AMPS3 0x0016 //VA
#define SDM630_VOLT_AMPS_TOTAL 0x0038 //VA
#define SDM630_VOLT_AMPS_REACTIVE1 0x0018 //VAr
#define SDM630_VOLT_AMPS_REACTIVE2 0x001A //VAr
#define SDM630_VOLT_AMPS_REACTIVE3 0x001C //VAr
#define SDM630_VOLT_AMPS_REACTIVE_TOTAL 0x003C //VAr
#define SDM630_POWER_FACTOR1 0x001E
#define SDM630_POWER_FACTOR2 0x0020
#define SDM630_POWER_FACTOR3 0x0022
#define SDM630_POWER_FACTOR_TOTAL 0x003E
#define SDM630_PHASE_ANGLE1 0x0024 //Degrees
#define SDM630_PHASE_ANGLE2 0x0026 //Degrees
#define SDM630_PHASE_ANGLE3 0x0028 //Degrees
#define SDM630_PHASE_ANGLE_TOTAL 0x0042 //Degrees
#define SDM630_VOLTAGE_AVERAGE 0x002A //V
#define SDM630_CURRENT_AVERAGE 0x002E //A
#define SDM630_FREQUENCY 0x0046 //HZ
#define SDM630_IMPORT_ACTIVE_ENERGY 0x0048 //Wh
#define SDM630_EXPORT_ACTIVE_ENERGY 0x004A //Wh
#define SDM630_IMPORT_REACTIVE_ENERGY 0x004C //VARh
#define SDM630_EXPORT_REACTIVE_ENERGY 0x004E //VARh
#define SDM630_TOTAL_SYSTEM_POWER_DEMAND 0x0054 //W
#define SDM630_MAXIMUM_TOTAL_SYSTEM_POWER 0x0056 //W

#define SDM_B_05 0x00 //BYTE 5
#define SDM_B_06 0x02 //BYTE 6

//------------------------------------------------------------------------------
template <long _speed = SDM_BAUD, int _rx_pin = SDMSER_RX, int _tx_pin = SDMSER_TX>
struct SDM220 {
Expand Down