Forum Replies Created

Viewing 1 - 4 of 4 posts
  • Nestor973

    Member
    November 7, 2021 at 5:06 pm

    The problem was in the Parity , i set it to
    master.begin(19200,SERIAL_8E1);

    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.

  • Nestor973

    Member
    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

    Member
    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() {

    Serial.begin(9600);
    while (!Serial){}
    Serial.println(“Connecting to Serial3 “);
    master.begin(19200);
    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

    break;

    case 1:

    master.query(telegram); // send query (only once)
    u8state++;
    break;

    case 2:

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

    }

    break;

    }

    delay(200);

    }

    • This reply was modified 3 years, 1 month ago by  Nestor973.
    • This reply was modified 3 years, 1 month ago by  Nestor973.
    • This reply was modified 3 years, 1 month ago by  Nestor973.
  • Nestor973

    Member
    November 7, 2021 at 9:23 am

    Hi,

    i’m facing some simular problem. Can you share your code?

Viewing 1 - 4 of 4 posts