Growatt PV Inverter , Arduino uno ,modbus input registers data monitoring

hi
I am using a 2.5kw Growatt PV solar inverter connected to an Rs485 TTL converter through Modbus protocol which is further connected to Arduino Uno.I want to form a solar data monitoring system and want to monitor or get values of input registers to the serial monitor using Arduino but unable to get so.
Instead, I am getting some symbol of square boxes and question marks as the output on Serial Monitor.
need help anxiously!!

also in code, I have a query that address at last section in Serial.println to get or read input register value, should we use 0x04 or 0x03?

Pls PLs, help.......Also haven't used softwareserial.h library anywhere in the code, don't know why wrote it!!

#include<SoftwareSerial.h>
#include<ModbusMaster.h>
#define m485a 3
#define m485b 2
ModbusMaster node;

void preTransmission()
{
  digitalWrite(m485a,1);
  digitalWrite(m485b,1);
 
}

void postTransmission()
{
  digitalWrite(m485a,0);
  digitalWrite(m485b,0);
}
void setup() {
  // put your setup code here, to run once:
pinMode(m485a,OUTPUT);
pinMode(m485b,OUTPUT);
 digitalWrite(m485a,0);
  digitalWrite(m485b,0);
  Serial.begin(9600);


  node.begin(1,Serial);
  node.preTransmission(preTransmission);
   node.postTransmission(postTransmission);

}

void loop() {
  // put your main code here, to run repeatedly:
uint8_t resultmain;
resultmain = node.readInputRegisters(0x3100,33);
if (resultmain==node.ku8MBSuccess)
{
Serial.println("---------");
Serial.print("Pv voltage :");
Serial.println(node.getResponseBuffer(0x00)/100.0f);
Serial.print("Pv current :");
Serial.println(node.getResponseBuffer(0x01)/100.0f);
Serial.print("battery voltage :");
Serial.println(node.getResponseBuffer(0x04)/100.0f);
Serial.print("battery charge current :");
Serial.println(node.getResponseBuffer(0x05)/100.0f);
  
}
delay(1000);
}

If you copy these two lines to "setup"

Serial.println("---------");
Serial.print("Pv voltage :");

Do they get displayed on the serial monitor?

Paul

Paul_KD7HB

Yes, "------" and "PV voltage " gets displayed on the serial monitor when written in setup
but I am still getting that square boxes and question mark
I have attached the screenshot of serial monitor output
plz, help!!

deepanshu25:
Paul_KD7HB

Yes, "------" and "PV voltage " gets displayed on the serial monitor when written in setup
but I am still getting that square boxes and question mark
I have attached the screenshot of serial monitor output
plz, help!!

Ok, the serial monitor will show test you send using Serial.println().

Now you can begin to debug your code by inserting BEFORE a compare, a line such as "Serial.printline("AT LINE # ___". Put the line number of your code in the message.

Also, you may need to put a similar line before a compare, printing the values of whatever you are comparing.

This will let you narrow the search for what is causing the problem.

Paul

I am sorry, but what is needed to compare, can you please illustrate it as I am not able to get it.
How this will gonna solve my problem.
Please help me out.

Have you tried the basic example that comes with the modbusmaster code on GitHub? You would need to adapt it a bit, but there's a lot of code in your sketch that I don't see in their example.

Yeah, you are right, I have edited some bit code but it almost resembles the Modbusmaster library example of half duplex on GitHub.I also tried the basic example too in Modbusmaster library still couldn't get the output I desire..still getting those square boxes and symbols as output . need help!!!