Can the inquiry frame for an RS485 modbus based pH sensor be changed?

Greetings,

I have a pH sensor that operates using RS485 modbus protocol (image attached).

I connected it to a UART to RS485 converter with Tx and Rx pins and used an ESP32 to send commands to get the pH value.

I amended a very simple code used previously on an anemometer project (Arduino / ESP8266 RS485 MODBUS Anemometer - Hackster.io). This previous project used a MAX485 module with DE and RE pins. I replaced that pin with an LED in this code.

#include <SoftwareSerial.h>  // https://github.com/PaulStoffregen/SoftwareSerial
 
#define RX        16    //Serial Receive pin 16
#define TX        17    //Serial Transmit pin 17
#define RTS_LED    26    //LED
#define RS485Transmit    HIGH
#define RS485Receive     LOW
 
SoftwareSerial RS485Serial(RX, TX);
 
void setup() {
   pinMode(RTS_LED, OUTPUT);  
 
   Serial.begin(115200);
 
   RS485Serial.begin(9600);   
   delay(1000);
}
 
void loop() {
 
   digitalWrite(RTS_LED, RS485Transmit);     // init Transmit
 
   byte RS485_request[x] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A}; //the one commonly seen online
 
   //to find out what I am sending 
   for( byte a=0; a<8; a++ ) {
     Serial.print(RS485_request[a], HEX);
  }
   Serial.println(); 
    
   RS485Serial.write(RS485_request, sizeof(RS485_request));
   RS485Serial.flush();
   
   digitalWrite(RTS_LED, RS485Receive);      // Init Receive
   byte RS485_received[8];
   RS485Serial.readBytes(RS485_received, 8);
  
   Serial.print("Result : ");
   for( byte i=0; i<8; i++ ) {
   Serial.print(RS485_received[i], HEX);
   Serial.print(" ");
   }
   Serial.print(" = ");
   Serial.print(RS485_received[4]);
   Serial.print(" something");
   Serial.println();                  
   delay(1000);
 
}

I get absolutely no reading from the pH sensor though. The Rx and Tx pins have LEDS connected and the Tx LED does not blink at all. All I get on my serial monitor are zeros. The inquiry frame byte RS485_request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A} is the one commonly used for RS 485 sensors, according to projects online and according to a random manual I saw (also attached).

This sensor has been sold by another company after being bought from the original manufacturer. I wanted to know if it is possible for this other company to change to inquiry frame? Or will it always be the factory define value? If so, what might be causing the sensor to not output any data?

A RS-485 adapter won't work without connecting the DE and RE pins! In the code you define pin 26 to have that connection but the schematics doesn't show that.

And you should use a Modbus library do the protocol.

Please correctly mark your code as code, otherwise the forum system mangles it (as it did with your code).

Apologies about incorrectly marking the code. Still getting used to this new Arduino Forum.

I will need to point out a few things that I didn't previously mention. I'll edit the original post if possible as well. I didn't use the normal MAX485 module (Figure 1).


Figure 1: Commonly used MAX485 module

I used a different device known by different names (Known as 'HW-0519', 'MAX485', 'XY-017', and 'XY-K485'). This module has the MAX485 IC, but uses Tx and Rx pins and has no enable buttons (Figure 2), making the enable feature unnecessary. The 'RTS_pin 26' in my code actually points to an LED.


Figure 2: The MAX485 IC with Rx and Tx pins, known as 'HW-0519'/'MAX485'/'XY-017'/'XY-K485'

Regarding the modbus library, do you mean this one? Will it work with ESP microcontrollers as well?

That's just one of the available libraries, there are also simpler ones using less memory. But that one should work with ESPs it's just using to much resources for the AVR series of Arduinos.

I guess your board just connect the DE/RE to the TX pin. This might work but doesn't match the wiring diagram you posted.

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