Reading values from a digital PH sensor

Hello everyone
i have a digital PH sensor which measures PH, Temperature, Resistance, ORP. i want to communicate to over modbus-RTU with a esp8266 but i cant understand the manual. could you please help me to how send registery to sensor for each parameter?

here is the manual

Some manuals give examples of the command message and the expected response message. This can be useful if you are handling the raw comms yourself.

There are Modbus libraries for various Arduino boards. There's one called ModbusMaster which may work with an ESP8266 but I've no experience with Modbus on an ESP8266 so can't guide you much.

The image you provided shows that the sensor has a default address of 1 and a baudrate of 9600 baud.

Your sensor understands function code 3 (ReadHoldingRegisters) and function code 6 (WriteSingleRegister).

The ModbusMaster library I mentioned comes with some examples to get the user started.

I would suggest trying to read register 0 or register 3 as these would hold values that you are likely to know beforehand.

could you please send a 8 bit register like this ? to better undestand what you mean

const byte temp [] = {0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A};

Ah, a canned Modbus message.

So:

01 = the device address
03 = is the function code
00 }
03 } = these 2 bytes are the register address
00 }
01 } = these 2 bytes are the number of registers to read
07 }
0A } = these 2 bytes are the CRC-16 checksum of the message (low byte first)

I use the CRCCalc website to calcuate the checksums.

do you think these CRC are correct for PH value?

0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x5E, 0xF4

CRC:
0x5E, 0xF4

I get 0xCA25 which would be 0x25 0xCA in the last 2 bytes.

i write the rigistery on crccalc.com like this and i got this result

how should i put it on the website?

You need to select hex as the input - like you have.

Add the values as:

01 03 00 02 00 01

So no 0x or commas, but spaces between each of the values Then click the CRC16 button. Scroll down the list to find the CRC-16/MODBUS line and look at the value in the Result column.

That's your CRC16 checksum you need for your message. It goes in the message low byte first.

thanks mark . the datasheet says that the ORP value has a range of -10000 to +10000. how can i read the sign ? 3&4 and 5&6 are for reading values

here is the code that i read the values

const byte orp[] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA};
byte orp_values[8];



void multi_sensor_orp_detect(){

uint32_t startTime;
  uint8_t i;
  uint32_t checkserial;


  checkserial = millis();
  while (millis() - checkserial <= 100UL) {
    while (mod.available()) mod.read();
  }




  mod.write(orp, sizeof(orp));
  mod.flush();

  i = 0;
  startTime = millis();

  while (millis() - startTime <= 1500UL) {
    if (mod.available() && i < sizeof(orp_values)) {
      orp_values[i++] = mod.read();
      //      if(i>2&&i<5){
      if (orp_values[1] == 3 && orp_values[2] == 2) {
        float orp_reg3and4 = word(orp_values[3],orp_values[4]);
        orp_reg3and4 = orp_reg3and4 / 10;
        pubORP = orp_reg3and4;

          Serial.println("ORP : " + (String)orp_reg3and4 + "");

      }
      //      }
    }
  }
  int orp;
  orp = (int)(pubORP * 10L);
  if (orpcomp != orp) {
    orpcomp = orp;
    client.publish(toCharArray("/angizeh/" + SerialNumber + "/08/ORP"), toCharArray(String(pubORP)));
    Serial.println("Published");
    // oneWillHUMID = true;
  }
  



}

Have a look at:

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