Facing a problem with data transfer between NodeMCU and MAX485 over ModScan software

I want to establish Modbus RTU communication between the NodeMCU-ESP8266 (Amica) and ModScan software. On the NodeMCU side, I'm using a TTL MAX485, but I'm not getting any values. Whenever I try to establish communication on ModScan software, it shows 'Invalid response.'
Please help with my project.

#include <ModbusRTU.h>
#include <SoftwareSerial.h>

SoftwareSerial s(D3, D2);  // RX, TX pins for SoftwareSerial communication

#define SLAVE_ID 1           // Modbus Slave ID
#define NUM_REGS 10          // Number of Modbus registers to handle

ModbusRTU mb;  // ModbusRTU instance

// Array to store register values (optional if using multiple registers)
uint16_t holdingRegs[NUM_REGS];

void setup() {
  Serial.begin(9600);  // Initialize serial monitor for debugging
  s.begin(9600, SWSERIAL_8E1);  // Initialize SoftwareSerial

  mb.begin(&s, D0);  // Initialize Modbus RTU communication with SoftwareSerial and RX pin D0

  mb.slave(SLAVE_ID);  // Set the Modbus slave ID
  for (int i = 0; i < NUM_REGS; i++) {
    mb.addHreg(i);  // Add holding registers from 0 to NUM_REGS-1
  }
}

void loop() {
  mb.task();  // Handle Modbus task, processing any incoming requests
  mb.Hreg(0, 100);  // Example: Write value 100 to the first register (index 0)

  // Read the holding register value (e.g., register 0) and print it to Serial Monitor
  uint16_t readHoldingRegister = mb.Hreg(0);  // Read from register index 0
  Serial.print("Holding Register 0: ");
  Serial.println(readHoldingRegister);
  
  delay(100);  // Small delay between readings
}

I moved your topic to a more appropriate forum category @sanjeeeev1425.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

Thank you

1 Like

What library are you using to have SWSERIAL_8E1 parameter? Do you really need even parity?
Does your rs485 have automatic direction control? How's your wiring?

I’m using modscan software and i have to set the baud rate, parity bit, bit length and stop bit.
I’m using modbus-esp8266 by alexander emelianov v4.1.0

Wiring
Max. Esp8266
RO: (RX)
DI: (TX)
DE: D0
RE: D0
VCC: Power supply
GND: Ground
A: RS-485 differential data line
B: RS-485 differential data line

If you can help me then please let me know….

You didn't answer about the softwareserial library, the normal one doesn't have that SWSERIAL_8E1 parameter.
You didn't answer if the parity needs to be even for some reason.

RX,TX but your code says D3, D2.
Which is correct?

What power supply?
Do you have common ground between Esp and Rs485?

For software serial library may be I'm using in build software serial library.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.