Hi everyone,
This is my first post on a Arduino Forum, first i would like to thank everyone in here for any input received regarding my query and would like to point out that i am really appreciative that there is a resource like this available on the Web.
My query pertains to a project i am doing where i would like to read the data from a sound sensor that works on MODBUS RTU.
Using Modbusmaster library i have incorporated my sensor parameters as per below but wanted to confirm if this approach is adequate since i have not received any input from sensor yet.
the sensor parameters are as follows:
Transmission mode
: MODBUS RTU Baud rate : 9600bps Data bits: 8 Stop bit: 1 Check bit: no
Slave address
:the factory default is 01H (set according to the need,00H to FFH
The 03 H Function Code Example: Read The Noise value
Host Scan Order
(slave address:0x01)
01
03 00 00 00 01 840A
Slave Response
01
03 02 02 55 791B
Noise:(
0255) H= (597) D , 597 /10 =59.7db
and the code i got so far is the following:
#include <Arduino.h>
#include <ModbusMaster.h> //Library for using ModbusMaster
#define MAX485_DE 3
#define MAX485_RE_NEG 2
ModbusMaster node; //object node for class ModbusMaster
void preTransmission() //Function for setting stste of Pins DE & RE of RS-485
{
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);
digitalWrite(MAX485_RE_NEG, 0); // Init in receive mode
digitalWrite(MAX485_DE, 0);
Serial.begin(9600); // Modbus communication runs at 9600 baud
node.begin(1, Serial); //Slave ID as 1
//Callback for configuring RS-485 Transreceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
bool state = true;
void loop() {
uint8_t result;
uint16_t data[6];
result = node.readHoldingRegisters(0x30001, 1); //Read 1 Holding starting from 840A
state = !state;
if (result == node.ku8MBSuccess)
{
Serial.print("Noise (db): ");
Serial.println(result);
}
delay(1000);
}
i believe that to read holding registers i need the fixed bits to be displayed:
result = node.readHoldingRegisters(0x30001, 1); //Read 1 Holding starting from 840A
The problem is that i don't get any interaction between rs485 and sensor, i have also tried 0000 instead of 30001 as sometimes sensors start from 0.
-Should i use a better rs485 to ttl converter?
-Is there a direction or resource i can look for where i could perhaps get the code to work?
(sensor datasheet attached)
Kind Regards