Heltec Wireless Stick V3: Modbus RS485 not working

Hello,I am trying to set up communication with the Epever MPPT controller via Modbus. Unfortunately, with Heltec Wireless Stick V3 the communication does not work - on the serial port it says something like:
1~⸮226

I tried the same code on the ESP32 Wroom kit, where the communication works properly and I get data from the controller as:

PV Voltage:
0.00
PV Current:
0.00
Battery Voltage:
12.47

I am using MAX3485 converter, pins DE and RE_NEG are defined and wired the same. I have connected the RO and DI pins of the converter to the RX and TX pins of the Heltec Wireless Stick V3 board.

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 works for the ESP32 Wroom kit:

#include <ModbusMaster.h>

#define MAX485_DE     4
#define MAX485_RE_NEG 2

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()
{
  // 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);
  if (resultMain == node.ku8MBSuccess)
  {
    Serial.println(" - - - - - - - - ");
    Serial.println("PV Voltage: ");
    Serial.println(node.getResponseBuffer(0x00) / 100.0f);
    Serial.println(node.getResponseBuffer(0x00) / 100.0f);
    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);

}

Could you please help me find out where the problem is?

Use another serial port pin instead of 43, 44.

And how to do this? Which pins will work correctly?

I’d recommend not using Serial but Serial1 to keep a clear separation between the USB lines and the Modbus lines.
Then you can use e.g. pins 47 & 48 or any of 4-7: they should be completely fine in any way.
So for example:

Serial1.begin(115200, 47, 48)

Of course make sure your wires match the pin numbers. Then you can replace all calls to Serial with Serial1.

Hello, so I tried replacing the pins to connect the converter to WiFi LoRa32 V3 as:

RO -> 47
RE| -> 46
DE -> 45
DI -> 48

I modified the source code as follows:

#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()
{
  // 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);
  Serial1.begin(115200, 47, 48);
  node.begin(1, Serial1);

  //Modbus slave ID 1
  //node.begin(1, Serial);
  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

  Serial1.println("test");
}

void loop()
{
  // put your main code here, to run repeatedly:
  uint8_t resultMain;

  resultMain = node.readInputRegisters(0x3100, 6);
  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, nothing from the solar controller is displayed.

Do you see a bug in the code or do you know how to make the communication work? Thanks

I have zero experience with Modbus / RS485, but I would like to warn you in using GPIO45 and GPIO46; these have extra behaviour on the ESP32-S3. GPIO 4-7 are always safe on Heltec / ESP32-S3 boards.
And are you sure that the TX / RX order is also right, i.e. not swapped? Just some thoughts…

Also, you may want to change Serial to USBSerial, or change the correct USB CDC / JTAG values in the dropdown menus. I don’t know the correct settings for Arduino IDE, I just have the compile flags for PIO.

So I tried several combinations of GPIO 4-7 but the result is same - no data from MPPT controller on the serial port.

Any other ideas?
Thanks