Go Down

Topic: Using Arduino with Modbus RTU to read registers of Schneider power meter Acti 9 (Read 423 times) previous topic - next topic

AlvaroAmos1

Hello guys, does anyone know how to actually use modbus protocol through Arduino to read registers from a power meter? I'm using a Schneider Acti 9 iEM3155 and the <ModbusMaster.h> library by Doc Walker. I connect my Arduino Uno to the power meter using the MAX485 module. When I load it up, it always returns E2 which I observe means that it's request has timed out. Below is the code:

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

#define RS485_DE 3
#define RS485_RE_NEG 2

//#define DEBUG true
//#define ESP_RX 8
//#define ESP_TX 7

ModbusMaster node;

//SoftwareSerial esp8266(ESP_RX,ESP_TX);

void preTransmission()
{
  digitalWrite(RS485_DE, 1);
  digitalWrite(RS485_RE_NEG, 1);
}

void postTransmission()
{
  digitalWrite(RS485_DE, 0);
  digitalWrite(RS485_RE_NEG, 0);
}
void setup()
{
  pinMode(RS485_RE_NEG, OUTPUT);
  pinMode(RS485_DE, OUTPUT);
 
  //Initialized in receive mode
  digitalWrite(RS485_DE, 0);
  digitalWrite(RS485_RE_NEG, 0);

  Serial.begin(9600);
  //esp8266.begin(9600);

  node.begin(001, Serial);

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

void loop()
{
  uint16_t result;

  Serial.println("Here");
  result = node.readHoldingRegisters(0x1845,1);
 
  //if (result == node.ku8MBSuccess)
  {
    Serial.println("---------------------");
    Serial.println(result, HEX);
    Serial.println(node.ku8MBSuccess);
    Serial.println(node.getResponseBuffer(0x00));
  }
  /*else
  {Serial.println("Failed");}*/

  delay(1000);
}

Please help, I'm very new to modbus and only just begun to explore Arduino.

Juraj


AlvaroAmos1

Is there a way to overcome that? Like, from what I'm understanding from what you said, this means that I need to have separate serial lines, right? One for debug printing and one for sending info to the meter? But how do I do that?

Juraj

Is there a way to overcome that? Like, from what I'm understanding from what you said, this means that I need to have separate serial lines, right? One for debug printing and one for sending info to the meter? But how do I do that?
if not you can try SoftwareSerial

AlvaroAmos1

Okay, so I've changed my code to the one below, and at first it seemed to work since there were no random characters appearing unlike previous attempts. But the output in the serial monitor is still the same, request time out (E2).

The new code:

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

#define RS485_DE 3
#define RS485_RE_NEG 2

#define DEBUG true
#define RX 8
#define TX 7

ModbusMaster node;

SoftwareSerial Modbus(RX,TX);

void preTransmission()
{
  digitalWrite(RS485_DE, 1);
  digitalWrite(RS485_RE_NEG, 1);
}

void postTransmission()
{
  digitalWrite(RS485_DE, 0);
  digitalWrite(RS485_RE_NEG, 0);
}
void setup()
{
  pinMode(RS485_RE_NEG, OUTPUT);
  pinMode(RS485_DE, OUTPUT);
 
  //Initialized in receive mode
  digitalWrite(RS485_DE, 0);
  digitalWrite(RS485_RE_NEG, 0);

  Serial.begin(9600);
  Modbus.begin(9600);

  node.begin(1, Modbus);

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

void loop()
{
  uint8_t result;

  Serial.println("Here");
  result = node.readHoldingRegisters(0x1845,1);
 
  //if (result == node.ku8MBSuccess)
  {
    Serial.println("---------------------");
    Serial.println(result, HEX);
    Serial.println(node.ku8MBSuccess);
    Serial.println(node.getResponseBuffer(0x00));
  }
  /*else
  {Serial.println("Failed");}*/

  delay(1000);
}

AlvaroAmos1

It still doesn't work though. The output is attached, but I dont understand why it's still giving off E2 (response timeout).

Go Up