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?