Hello
I am looking forward to learn modbus and how to use it on arduino.
I have a hum/temp sensor which has a modbus output ( i will attach the datasheet )
I have a RS485 to Serial TTL module and an Arduino one.
Following all documentation the Modbus output +/- is connected to the AB input on the RS485 to Serial TTL.
The RS485 to Serial TTL module connects to the Arduino as follows, DI--TX, DE -- D3, RE -- D2 and RO --Rx.
The code is as follows, I have copied bits and pieces from here and there, but I am not quite sure how everything works.
// include the library code:
#include <ModbusMaster.h>
#define MAX485_DE 3
#define MAX485_RE_NEG 2
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup() {
pinMode (MAX485_RE_NEG, OUTPUT);
pinMode (MAX485_DE, OUTPUT);
//init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite (MAX485_DE, 0);
Serial.begin (19200);
node.begin(254, Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
// int result = node.readHoldingsRegisters
uint8_t resultMain;
resultMain = node.readInputRegisters(0x101, 2);
if (resultMain == node.ku8MBSuccess)
{
Serial.println(node.getResponseBuffer(0x101));
}
delay(1000);
}
I get some strange characters instead of numbers, like a wrong baut rate. I already looked into it.
Any help provided will be highly Appreciate it.
Thanks.
Tony
HUMIDITY TRANSMITTER.pdf (875 KB)