Activity › Forums › Questions & Troubleshooting › Modbus with temperature/humidity/gas sensor .
-
Modbus with temperature/humidity/gas sensor .
-
Hi,
i have to say i’m pretty new to the modbus protocol. I Have a Controllino Maxi that should communicatie with this sensor :
https://www.goveco.com/en/products/sensing/368809/odvcm-multifunctional-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.
-
#include <Controllino.h>
#include “ModbusRtu.h”
#define MasterModbusAdd 0
#define SlaveModbusAdd 1
#define RS485Serial 3String 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 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..
-
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.
-
Hi,
thanks for sharing! Have you also resolved the issue with the wrong temperature?
Lukas
-
Log in to reply.