Error logging data in serial monitor from esp 32 with SDM120ct single phase analyzer as the sensor

Hi i need help whenever i try to get the reading showed on my single phase analyzer (SDM120ct-Eastron).I upload my code in ESP32 Dev Kit V1.I also used RS485 TTL convertor but it seems the serial monitor gives output such as FV�Q�\Q��x�x�x�x�xx������xx��xx�x��x�x��x��x��x��x

This is my final year project and really need help

my project code is
#include "REG_SDM120.h"
#include <ModbusMaster.h>

HardwareSerial Mod(2); //use uart 2

ModbusMaster node;
//01 04 00 00 00 02 71 3F // Test 30001
//------------------------------------------------
// Convent 32bit to float
//------------------------------------------------
float HexTofloat(uint32_t x) {
return ((float)&x);
}

uint32_t FloatTohex(float x) {
return ((uint32_t)&x);
}
//------------------------------------------------

float Read_Meter_float(char addr , uint16_t REG) {
float i = 0;
uint8_t j, result;
uint16_t data[2];
uint32_t value = 0;
node.begin(addr, Mod);
result = node.readInputRegisters (REG, 2); ///< Modbus function 0x04 Read Input Registers
delay(500);
if (result == node.ku8MBSuccess) {
for (j = 0; j < 2; j++)
{
data[j] = node.getResponseBuffer(j);
}
value = data[0];
value = value << 16;
value = value + data[1];
i = HexTofloat(value);
//Serial.println("Connec modbus Ok.");
return i;
} else {
Serial.print("Connec modbus fail. REG >>> "); Serial.println(REG, HEX); // Debug
delay(1000);
return 0;
}
}

void GET_METER() { // Update read all data
delay(1000); //
for (char i = 0; i < Total_of_Reg ; i++){
DATA_METER [i] = Read_Meter_float(ID_meter, Reg_addr[i]);// ID_METER_ALL=X
}
}

//**************************************************************************************************************
void setup() {
Serial.begin(2400);
Serial.println("program started");
Serial.println();
Serial.println();
Serial.println(F("RS485 RTU SDM120***"));
}

void loop() {
//float x = Read_Meter_float(ID_meter,Reg_Volt);
GET_METER();
Serial.println();
Serial.print("Voltage = "); Serial.print(DATA_METER[0]);Serial.println(" VAC");
Serial.print("Current = "); Serial.print(DATA_METER[1]);Serial.println(" Amps");
Serial.print("Active Power= "); Serial.print(DATA_METER[2]);Serial.println(" Watts");
Serial.print("Power Factor = "); Serial.println(DATA_METER[3]);
Serial.print("Frequency = "); Serial.print(DATA_METER[4]);Serial.println(" Hz");
Serial.print("Total Active Energy = "); Serial.print(DATA_METER[5]);Serial.println(" kWh");
delay(5000);
}

the REG_SDM120.h

#define ID_meter 0x01
#define Total_of_Reg 6

#define Reg_Volt 0x0000 // 0.
#define Reg_Current 0x0006 // 1.
#define Reg_ActivePower 0x000C // 2.
#define Reg_PowerFactor 0x001E // 3.
#define Reg_Frequency 0x0046 // 4.
#define Reg_TotalActiveEnergy 0x0156 // 5.

uint16_t const Reg_addr[6] = {
Reg_Volt,
Reg_Current,
Reg_ActivePower,
Reg_PowerFactor,
Reg_Frequency,
Reg_TotalActiveEnergy
};

float DATA_METER [Total_of_Reg] ;

This usually means your serial monitor is not set to the same baud rate as your program which in your case is: 2400

void setup() {
Serial.begin(2400);
Serial.println("program started");

thanks soo much now im starting to get

RS485 RTU SDM120***
Connec modbus fail. REG >>> 0
Connec modbus fail. REG >>> 6
Connec modbus fail. REG >>> C
Connec modbus fail. REG >>> 1E
Connec modbus fail. REG >>> 46
Connec modbus fail. REG >>> 156

Voltage = 0.00 VAC
Current = 0.00 Amps
Active Power= 0.00 Watts
Power Factor = 0.00
Frequency = 0.00 Hz
Total Active Energy = 0.00 kWh
Connec modbus fail. REG >>> 0
Connec modbus fail. REG >>> 6
Connec modbus fail. REG >>> C
Connec modbus fail. REG >>> 1E
Connec modbus fail. REG >>> 46
Connec modbus fail. REG >>> 156

is it due to my convertor problem?

currently im using this convertor but it seems only TXD is blinking my connection is

Sorry I can't help you here. I've never had occasion to work with ModBus :frowning:

it's ok and thanks so much for the previous solution to match the baud rate :hugs:.

Good evening boss, did you figure out the problem why there are error while logging data in serial monitor?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.