Code: Select all
1~⸮226
Code: Select all
PV Voltage:
0.00
PV Current:
0.00
Battery Voltage:
12.47
The connection of MAX3485 and Heltec WS is:
RO -> RX (GPIO 44)
RE| -> 46
DE -> 45
DI -> TX (GPIO 43)
The registers are definitely defined correctly, so the problem must be in the communication between Wireless Stick and converter for RS485.
I also tried the Heltec WiFi LoRa32 V3 board, and it still didn’t work.
I am attaching the code that I was trying with Heltec Wireless Stick V3:
Code: Select all
#include <ModbusMaster.h>
#define MAX485_DE 45
#define MAX485_RE_NEG 46
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()
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, LOW);
// put your setup code here, to run once:
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
Serial.begin(115200);
//Modbus slave ID 1
node.begin(1, Serial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
Serial.println("test");
}
void loop()
{
// put your main code here, to run repeatedly:
uint8_t resultMain;
resultMain = node.readInputRegisters(0x3100, 6);
Serial.println( resultMain );
if (resultMain == node.ku8MBSuccess)
{
Serial.println(" - - - - - - - - ");
Serial.println("PV Voltage: ");
Serial.println(node.getResponseBuffer(0x00) / 100.0f);
Serial.println("PV Current: ");
Serial.println(node.getResponseBuffer(0x01) / 100.0f);
Serial.println("Battery Voltage: ");
Serial.println(node.getResponseBuffer(0x04) / 100.0f);
Serial.println("Battery Charge Current: ");
Serial.println(node.getResponseBuffer(0x05) / 100.0f);
}
delay(1000);
}
When I open the serial monitor in the arduino IDE, only periodic nonsense strings are displayed.
Do you see a bug in the code or do you know how to make the communication work? Thanks