Problem with reading the temperature from the device via RS485 Modbus

Hi everyone

I've tried various methods, but I still get a reading error. I've switched the A/B cables, but nothing helps.

There's a diagram on the device. I'm not sure if I understand correctly, but I connected A and B to the top pins, then swapped them around, and nothing helped.

pic

In the documentation it says that register 30001 is the temperature value and I set the device to mode "1" RS485.

I have ERROR: E2

/*
RS485    ESP
vcc      vcc
gnd      gnd
TX       D1
RX       D2

*/

#define SSERIAL_RX_PIN 4
#define SSERIAL_TX_PIN 5

#include <ModbusMaster.h>
#include <SoftwareSerial.h>
SoftwareSerial RS485Serial(SSERIAL_RX_PIN, SSERIAL_TX_PIN);
ModbusMaster node;


void Read_Sensor() {
  static uint32_t timestamp = 0;

  if (millis() - timestamp >= 1000) {
    timestamp = millis();  


    // Request 2 registers starting at 0x0001
     uint8_t result = node.readInputRegisters(0x0000, 1);
    //uint8_t result = node.readHoldingRegisters(0x0000, 3);

    if (result == node.ku8MBSuccess) {
      // Get response data from sensor
      Serial.print("Read Success !!!: ");
      Serial.println(float(node.getResponseBuffer(0) / 10.00F));

    } else {
      Serial.print("ERROR: ");
      Serial.println(result, HEX);  
    }
  }
}


void setup() {

  Serial.begin(115200);
  RS485Serial.begin(9600);

  // Modbus slave ID 1
  node.begin(1, RS485Serial);
}
void loop() {

  Read_Sensor();
}


Only the TX LED on the RS converter flashes. The RX LED only flashes once upon connection or reset. If the RX LED flashes once, does that mean the wiring is OK?

Why the top pins? Why not the bottom pins or one of the top and one of the bottom?

How do you know it's RS485 and not prokey?

I don't understand the manufacturer markings on the housing.
I thought that the RS485 markings at the top meant the top pins.
I don't know what strategy to use?

Tłumacz rozmowy

SoftwareSerial cannot send and receive at the same time.
This can (and often will) give problems in reliability.

Have you tried to use a HardwareSerial for the RS485.
If this doesn't work either, it reduces the number of possible causes.

I have other RS485 sensors that I use with an ESP8266 with software serial, and they work fine, sending and receiving requests.
Yes, I tried with an ESP32 on hardware Serial 2, and the same thing happens.
I have no idea, I keep getting an error​:pensive_face:

Note you mention 2 different devices.
Have you got the other RS485 sensors working on the ESP32?

Error E2 is a timeout IIRC

  • double check the pins and wiring

I wrote a simple rs485 sniffer long ago, which might be useful to see if and what data is on the line. Just try to grab the raw bytes that go over the lines.
You might need an additional board.

RS485/examples/RS485_sniffer at master · RobTillaart/RS485 · GitHub.

Yes the same sensors work on esp8266 wemos d1 mini and d1 mini esp32.

Thank you, I'll check the wiring again. I need to find another board and test your code.

Well you have 12 dififferent combinations you could try, some may damage you Arduino and/or RS485 device.
You are shooting in the dark by not knowing the correct connections.

How should we read that?
And what is this board exactly that doesn't work?


I tried all 12 combinations and nothing.
When I switched the wires, I got errors E0 and E2.