I tested the code to get variables like voltage and current and it works normally. My question is how can I get the Battery status, Array status, Charging status, Load status and Array Power(W) data correctly?
@feikzinho, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem
In future, please post your code in a post instead of as an attachment. Not everybody can open ino files on e.g. a cell phone so your missing out on knowledgeable people.
OP's code
#include <ModbusMaster.h>
#include <SPI.h>
#include <SD.h>
#define MAX485_DE 2
#define MAX485_RE_NEG 2
ModbusMaster node;
File myFile;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init no modo de recepção
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial1.begin(115200);
Serial.begin(9600);
node.begin(1, Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
if (!SD.begin(53)) {
while (1);
}
}
bool state = true;
void loop()
{
uint8_t result;
uint16_t data[6];
result = node.writeSingleCoil(0x0002, state);
state = !state;
result = node.readInputRegisters(0x3100,20);
myFile = SD.open("alex.txt", FILE_WRITE);
if (result == node.ku8MBSuccess)
{
Serial.print("Array Current(A): ");
Serial.print(node.getResponseBuffer(0x01)/100.0f);
Serial.print(";");
}
delay(1000);
}
A little wiring, drawn by pen and paper is preferred. Word built wirings often hide away the reason for error. It's what's not told that often matters.