Hi everyone,
Newbie trying to read from EPSOLAR charge controller using MODBUS as per following details:
Arduino: Mega
Library used: ModbusMaster
Display Device: Liquid Crystal Display
Circuit: Max485 module connected as follows:
- MAX485_DE --> Pin 3 of Arduino
- MAX485_RE_NEG --> Pin 2 of Arduino
- MAX485_RO --> RX Pin of Arduino
- MAX485_DI --> TX Pin of Arduino
#include <LiquidCrystal.h>
#include <ModbusMaster.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 53, en = 51, d4 = 49, d5 = 47, d6 = 45, d7 = 43;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Using MAX485 based Module, following configuration should be used:
// 1. MAX485_DE --> Pin 3 of Arduino
// 2. MAX485_RE_NEG --> Pin 2 of Arduino
// 3. MAX485_RO --> RX Pin of Arduino
// 4. MAX485_DI --> TX Pin of Arduino
#define MAX485_DE 3
#define MAX485_RE_NEG 2
#define PANEL_VOLTS 0x00
#define PANEL_AMPS 0x01
#define PANEL_POWER_L 0x02
#define PANEL_POWER_H 0x03
#define BATT_VOLTS 0x04
#define BATT_AMPS 0x05
// instantiate ModbusMaster object
static const uint16_t ku16MBResponseTimeout = 3000;
ModbusMaster node;
//static const uint16_t ku16MBResponseTimeout = 3000;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 4);
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 115200 baud
Serial1.begin(115200,SERIAL_8N1);
// Modbus slave ID 1
node.begin(1, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
node.clearResponseBuffer();
node.clearTransmitBuffer();
}
int loopcount=0;
void loop() {
// set the cursor to column 0, l. Line 1 is the second row, since counting begins with 0.
uint8_t result=1;
// Read 1 register starting at 0x3100)
result = node.readInputRegisters(0x3100,1);
if (result == node.ku8MBSuccess)
{
float pV = node.getResponseBuffer(PANEL_VOLTS)/100.0f;
//float pI = node.getResponseBuffer(PANEL_AMPS)/100.0f;
//float pP = (node.getResponseBuffer(PANEL_POWER_L) |
//(node.getResponseBuffer(PANEL_POWER_H) << 8))/100.0f;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("VPanel:");
lcd.print(pV);
//lcd.print("IPanel:");
//lcd.print(node.getResponseBuffer(PANEL_AMPS)/100.0f);
//lcd.print("PPanel:");
//lcd.println((node.getResponseBuffer(PANEL_POWER_L) |
//(node.getResponseBuffer(PANEL_POWER_H) << 8))/100.0f);
} else {
lcd.setCursor(0, 0);
lcd.print("Miss read: ");
lcd.print(result, HEX);
}
delay(5000);
}
I have tested the sketch and the hardware with software by (www.modbustools.com) and it works OK. When connected to the Charge Controller the response is consistently E2 ( slave timed out).
Please help.
TIA
azhaque





