Schneider EM1200 with arduino uno via max485 to ttl module

i have face issue in this project please someone help me .here the code of it

#include #include

#define MAX485_DE 2
#define MAX485_RE 3
#define SOFT_RX 10 // SoftwareSerial RX pin
#define SOFT_TX 11 // SoftwareSerial TX pin

// Instantiate ModbusMaster and SoftwareSerial objects
ModbusMaster node;
SoftwareSerial modbusSerial(SOFT_RX, SOFT_TX);

void preTransmission() {
digitalWrite(MAX485_DE, HIGH);
digitalWrite(MAX485_RE, HIGH);
}

void postTransmission() {
digitalWrite(MAX485_DE, LOW);
digitalWrite(MAX485_RE, LOW);
}

void setup() {
// Start the software serial port
modbusSerial.begin(19200);

// Initialize Modbus communication over SoftwareSerial
node.begin(modbusSerial);

// Set up transmission control pins
pinMode(MAX485_DE, OUTPUT);
pinMode(MAX485_RE, OUTPUT);
digitalWrite(MAX485_DE, LOW);
digitalWrite(MAX485_RE, LOW);

// Callbacks to control transmission
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);

// Start the default serial port for debugging
Serial.begin(19200);
}

void loop() {
uint8_t result;
uint16_t data[2];

// Read Power (register 3003)
result = node.readInputRegisters(1,3003, 2); // Starting at register 3003, reading 2 registers
if (result == node.ku8MBSuccess) {
data[0] = node.getResponseBuffer(0);
data[1] = node.getResponseBuffer(1);
float power = convertToFloat(data[0], data[1]);
Serial.print("Power: ");
Serial.println(power);
} else {
Serial.print("Failed to read power, error: ");
Serial.println(result, HEX);
}

// Read Power Factor (register 3007)
result = node.readInputRegisters(1,3007, 2); // Starting at register 3007, reading 2 registers
if (result == node.ku8MBSuccess) {
data[0] = node.getResponseBuffer(0);
data[1] = node.getResponseBuffer(1);
float powerFactor = convertToFloat(data[0], data[1]);
Serial.print("Power Factor: ");
Serial.println(powerFactor);
} else {
Serial.print("Failed to read power factor, error: ");
Serial.println(result, HEX);
}

delay(1000);
}

float convertToFloat(uint16_t highWord, uint16_t lowWord) {
uint32_t combined = (uint32_t)highWord << 16 | lowWord;
return ((float)&combined);
}

//
EM1200 Series SE 6.0.1.9 ENG.zip (6.5 MB)
Test5_EM1200.ino (2.1 KB)

output:


Failed to read power, error: E2

Failed to read power factor, error: E2

please guide me

why did you post in the Emergency Response: Covid-19 Projects catgeory?

I moved your topic to an appropriate forum category.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

You'll also see how to post code correctly using code tags. Please fix your post by clicking on the little pencil below the post and adding the code tags.

Finally, if you add the necessary documentation for your ask like your exact circuit and power supply, links to components etc, you are more likely to get an answer. Comments like "i have face issue in this project..." does not mean much... What issue exactly ? What are you trying to do, what does the code do that you don't want?

Thanks in advance for your cooperation.

Check this schneider document How to read active power....
As you can see uses 'read holding register', if you have an usb/485 converter try using the software modscan32 ( or open modscan which has a logging option ) to verify register content and address ( you never know the exact address! )

From what I can make of the gibberish posted as code it has hardware involved. Read the forum guidelines then re-post your code and an annotated schematic showing exactly how you have wired it.

yes i had use same register address

Please fix your first post.

You are joining a community for help, showing some respect by adhering to simple rules seems the minimum to me and it will help you.

Good... by the way which consideration I made did you reply by saying "yes i had use same register address" because in the example linked:

  • they used 'read holding register' and you are using 'read input register'
  • they used device id = 5 and you use 1 ( I don't know which is right, but did you verify? )
  • did you verify via modscan32 ( or open modscan ) the real address transmitted ( I leave this to you as an exercise ) because it is different from the one you specify in their software ( on the contrary the arduino modbusmaster is 'true to address' )

So, you have 32bit float register 403003 in decimal, that translates to holding register 0x0BBA and 0x0BBB.
result = node.readHoldingRegisters(0x0BBA, 2);
and
float power = convertToFloat(node.getResponseBuffer(0x00), node.getResponseBuffer(0x01));

Your default slave address is 1, default baud rate 19200 and default parity even 8E1
Default parity in softwareserial is 8N1 and as far as I know, you can't change it. Try with some alternative softwareserial library.

Or use usb-rs485 adapter + pc-software and change those default settings. Also baud rate would be better at 9600 for softwareserial.
Edit:
Or maybe you can change them with onboard display menu?
Edit: corrected hex addresses

yes, I will see again after changing it.

Ok, but the address is 3002 decimal, not hexadecimal

I don't follow you. 403003 is 3003 in 1-based decimal, 0x3002 in HEX.
Edit: I mean 0xBBA in HEX. My mistake.

will see it again after changes

no change.

with 8N1 on settings?

Correct register addresses are secondary, device is responding anyway.
But you get no response so you have either
-Wrong slave address
-wrong parameters
-wrong wiring

yes

did you set the baudrate to 9600 on both, device and your code?
and control that slave is set 1 on device?

should be
node.begin(1, modbusSerial);

Compilation error: no matching function for call to 'ModbusMaster::begin(int, SoftwareSerial&)'

Post your last code here

I expect you have some bridge wire from pin2 to RE and DE?
Try with this:

#include <ModbusMaster.h>
#include <SoftwareSerial.h>

#define MAX485_DE 3
#define MAX485_RE 2
#define SOFT_RX 10 // SoftwareSerial RX pin
#define SOFT_TX 11 // SoftwareSerial TX pin

// Instantiate ModbusMaster and SoftwareSerial objects
ModbusMaster node;
SoftwareSerial modbusSerial(SOFT_RX, SOFT_TX);

void preTransmission() {
digitalWrite(MAX485_DE, HIGH);
digitalWrite(MAX485_RE, HIGH);
}

void postTransmission() {
digitalWrite(MAX485_DE, LOW);
digitalWrite(MAX485_RE, LOW);
}

void setup() {
modbusSerial.begin(9600); // Change to 19200 if required
node.begin(1, modbusSerial); // Pass only the SoftwareSerial object

pinMode(MAX485_DE, OUTPUT);
pinMode(MAX485_RE, OUTPUT);
digitalWrite(MAX485_DE, LOW);
digitalWrite(MAX485_RE, LOW);

node.preTransmission(preTransmission);
node.postTransmission(postTransmission);

Serial.begin(9600);
}

void loop() {
  uint8_t result;
  uint8_t j;
  
 
  result = node.readHoldingRegisters(0x0BBA, 10);
  
  if (result == node.ku8MBSuccess)
  {
    
for (j = 0; j < 10; j++)
    {
      Serial.println(node.getResponseBuffer(j));
    }

  } 
  else 
  {
    Serial.print("Modbus Error: ");
    Serial.println(result);
  }

  Serial.println("\n ------------  \n ");

  delay(2000);
}