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.