Hi everyone, I've been stuck on this for a while and would really appreciate a second pair of eyes.
Goal: Read N, P, K values from a soil NPK sensor (RS485/Modbus RTU) using an ESP32 + MAX485 module.
Hardware:
- ESP32 DevKit (38-pin, standard pinout diagram - possibly a WROVER variant with PSRAM, still confirming)
- Generic MAX485 RS485-to-TTL module (separate RE and DE pins, not auto-flow)
- Soil NPK sensor, RS485 output, powered separately at 12V DC
Wiring:
- MAX485 RO -> ESP32 GPIO33
- MAX485 DI -> ESP32 GPIO32
- MAX485 RE -> ESP32 GPIO4
- MAX485 DE -> ESP32 GPIO5
- MAX485 VCC -> ESP32 5V
- MAX485 GND -> ESP32 GND (shared with sensor power supply GND)
- Sensor A -> MAX485 A
- Sensor B -> MAX485 B
- Sensor VCC -> separate 12V DC power supply
- Sensor GND -> shared common ground
(I originally tried GPIO16/17 for RX2/TX2 since that's the default UART2 on ESP32, but switched to GPIO32/33 after reading that GPIO16/17 can be reserved for PSRAM on WROVER-based boards. Switching pins didn't change the outcome.)
Code (using ModbusMaster library):
#include <ModbusMaster.h>
#define MAX485_RE 4
#define MAX485_DE 5
#define RXD2 33
#define TXD2 32
#define SLAVE_ID 1
#define BAUD_RATE 9600
ModbusMaster node;
void preTransmission() {
digitalWrite(MAX485_RE, HIGH);
digitalWrite(MAX485_DE, HIGH);
}
void postTransmission() {
digitalWrite(MAX485_RE, LOW);
digitalWrite(MAX485_DE, LOW);
}
void setup() {
Serial.begin(115200);
pinMode(MAX485_RE, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE, LOW);
digitalWrite(MAX485_DE, LOW);
Serial2.begin(BAUD_RATE, SERIAL_8N1, RXD2, TXD2);
node.begin(SLAVE_ID, Serial2);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop() {
uint8_t result = node.readHoldingRegisters(0x001E, 3);
if (result == node.ku8MBSuccess) {
Serial.println("Success!");
} else {
Serial.print("Error: 0x");
Serial.println(result, HEX);
}
delay(3000);
}
Result: Always get 0xE2 (ku8MBResponseTimedOut) - zero bytes received, every single time.
What I've already tried:
- Baud rates: 2400, 4800, 9600, 19200, 38400
- Slave IDs: 0, 1, 2, 3, 4, 5
- Swapped A/B wires (both orientations)
- Different GPIO pairs for RX/TX (16/17, then 32/33, then 13/33)
- Loopback test on A/B (shorting A to B directly) to verify the MAX485+ESP32 side independent of the sensor - haven't gotten a clear result yet, still in progress
- Verified sensor gets 12V on its power wires with a multimeter
What I haven't fully ruled out yet:
- Whether my MAX485 module itself might be defective
- Whether my exact sensor genuinely speaks Modbus RTU over RS485 (it's a generic/OEM sensor without a fully confirmed datasheet)
Has anyone run into a similar "alwa
ys 0xE2, zero bytes ever received" situation? Any diagnostic steps I might be missing, or common rookie mistakes with MAX485 wiring (DE/RE logic, floating pins, etc.) that could cause a complete silence like this? Happy to share more details/photos if needed. Thanks in advance!






