I have run the modbustools software and linked it up with the prototype. A short video is linked below that clearly shows the data exchange between the software running on the laptop and the prototype:
#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
ModbusMaster node;
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);
// Modbus slave ID 1
node.begin(1, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
int loopcount=0;
void loop() {
// set the cursor to column 0, l. Line 1 is the second row, since counting begins with 0.
lcd.setCursor(0, 0);
uint8_t result;
//uint16_t data[6];
// Read 1 registers starting at 0x3100)
result = node.readInputRegisters(0x3100, 6);
if (result == node.ku8MBSuccess)
{
float pV = node.getResponseBuffer(PANEL_VOLTS);
float pI = node.getResponseBuffer(PANEL_AMPS);
float pP = (node.getResponseBuffer(PANEL_POWER_L) |
(node.getResponseBuffer(PANEL_POWER_H) << 8))/100.0f;
float bV = node.getResponseBuffer(BATT_VOLTS);
//float bI = node.getResponseBuffer(BATT_AMPS);
lcd.setCursor(0, 0);
lcd.print("VSolar :");
lcd.print(pV);
lcd.setCursor(0, 1);
lcd.print("ISolar :");
lcd.print(pI);
lcd.setCursor(0, 2);
lcd.print("SolarP:");
lcd.print(pP);
lcd.setCursor(0, 3);
lcd.print("BattV :");
lcd.print(bV);
//lcd.setCursor(0, 2);
//lcd.print(bI);
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Miss read: ");
lcd.print(result, HEX);
lcd.print(loopcount);
}
loopcount++;
delay(3000);
lcd.clear();
}