Activity Forums Questions & Troubleshooting Modbus with temperature/humidity/gas sensor .

  • Modbus with temperature/humidity/gas sensor .

  • Nestor973

    November 6, 2021 at 3:47 pm


    i have to say i’m pretty new to the modbus protocol. I Have a Controllino Maxi that should communicatie with this sensor :

    According to the LED’s on the sensor, it should be powered OK. I did supply it with 24vDC+ and i split the ground to the main ground and the ground of the RS485 port (not sure if that is ok, but i think so?)

    Anyhow, i tried the ModbusMaster demo in the arduino IDE and it gives me nothing. The device slave address is 1 as stated in the PDF.

    I think the demo code should at least be able to read something from the sensor?

    Thanks in advance for any input on this.

  • Nestor973

    November 7, 2021 at 3:03 pm

    #include <Controllino.h>
    #include “ModbusRtu.h”
    #define MasterModbusAdd 0
    #define SlaveModbusAdd 1
    #define RS485Serial 3

    String result;
    uint16_t au16data[16];
    uint8_t u8state;

    Modbus master(SlaveModbusAdd, RS485Serial, 0);

    modbus_t telegram;

    unsigned long u32wait;

    void setup() {

    while (!Serial){}
    Serial.println(“Connecting to Serial3 “);
    master.setTimeOut(5000); // if there is no answer in 5000 ms, roll over
    u32wait = millis() + 2000;
    u8state = 0;
    telegram.u8id = 1; // slave address
    telegram.u8fct = 4; // function code (this one is registers read)
    telegram.u16RegAdd = 1; // start address in slave
    telegram.u16CoilsNo = 1; // number of elements (coils or registers) to read
    telegram.au16reg = au16data; // pointer to a memory array in the Arduino


    void loop() {

    switch( u8state ) {

    case 0:

    if (millis() > u32wait) u8state++; // wait state


    case 1:

    master.query(telegram); // send query (only once)

    case 2:

    master.poll(); // check incoming messages
    if (master.getState() == COM_IDLE) {
    u8state = 0;
    u32wait = millis() + 1000;
    Serial.print(“ontvangen data: “);






    • This reply was modified 2 years, 8 months ago by  Nestor973.
    • This reply was modified 2 years, 8 months ago by  Nestor973.
    • This reply was modified 2 years, 8 months ago by  Nestor973.
  • Nestor973

    November 7, 2021 at 3:09 pm

    This is what i’ve come up with so far. I have no idea but i think this should result something.
    What i don’t know if is my sensor is correctly wired. I did order a USB-RS485 dongle to check if it really
    works at all. Hope someone can confirm if the code below should come up with a result.

    The address of the sensor is 1 , that’s for sure, the input register for temperature is also 1, so..

  • Nestor973

    November 7, 2021 at 5:06 pm

    The problem was in the Parity , i set it to

    and now i get data out of the sensor. Data is still a bit weird (about 50°C where it should read 20 or so),but that’s another issue that has nothing to do with controllino.

    • Lukas

      January 4, 2022 at 2:44 pm


      thanks for sharing! Have you also resolved the issue with the wrong temperature?


Viewing 1 - 4 of 4 replies

Log in to reply.

Original Post
0 of 0 posts June 2018