Modbus RTU communication between ESP32 and particle counter not working

Hi, I'm trying to receive numeric data (falling particle count) from a particle counter (Shinyei AES-LPM) and have my ESP32 (ESP32-WROOM-32E) board log it on the Serial Monitor of the Arduino IDE.

Circuit

The messaging standard is Modbus RTU and the physical standard is RS485, which is why I purchased a MAX485 module to receive data from the particle counter.

Connected pins

  • ESP32 16 - MAX485 DI
  • ESP32 17 - MAX485 RO
  • ESP32 26 - MAX485 DE
  • ESP32 27 - MAX485 RE
  • ESP32 3V3 - MAX485 VCC
  • ESP32 GND - MAX485 GND
  • MAX485 A - Particle counter D+
  • MAX485 B - Particle counter D-
  • Particle counter GND - ESP32 GND

Programming

Input registers

I wanted to test whether the code worked so I went for address 30,001 according to the documentation for the particle counter (or 0 since input registers start from 30,001). However, the addresses I would be reading are 30,008 and 30,009 for the particle concentration data.

Code

The documentation for the particle counter does not mention anything about what the slave ID for the counter would be, which is why I looped through all possible slave IDs (1-255) to identify it. However, all of them printed error messages.

External dependencies

Program

#include <ModbusMaster.h>

#define DI 16
#define RO 17
#define DE 26
#define RE 27

ModbusMaster node;

void setup() {
  Serial.begin(115200);

  // RX=16, TX=17
  Serial2.begin(9600, SERIAL_8N1, DI, RO);

  pinMode(DE, OUTPUT);
  digitalWrite(DE, 0);

  pinMode(RE, OUTPUT);
  digitalWrite(RE, 0);
}

void loop() {
  uint8_t id = 1;

  while (i < 256) {
    node.begin(id, Serial2);

    uint8_t result = node.readInputRegisters(0x0000, 1);
    Serial.printf("Slave id: %u", id);

    if (result == node.ku8MBSuccess) {

      uint16_t value = node.getResponseBuffer(0);

      Serial.print("Input Register 30001 = ");
      Serial.println(value);
    } else {
      Serial.print("Modbus Error: ");
      Serial.println(result);
    }

    delay(100);

    i++;
  }
}

Output

...
Slave id: 53Modbus Error: 226
Slave id: 54Modbus Error: 226
Slave id: 55Modbus Error: 226
Slave id: 56Modbus Error: 226
Slave id: 57Modbus Error: 226
Slave id: 58Modbus Error: 226
Slave id: 59Modbus Error: 226
...

I'm not very knowledgeable with electronics and could use some assistance in figuring out where this setup is going wrong. Thank you!

Since the company offers free monitoring software, did you try it and does it work? Their documentation seems to be only available to the actual purchasers of their equipment you will not get much help from the forum as you are the only one with access to the documents.