Go Down

Topic: Reading Sensor values digitally with RS485 (Read 929 times) previous topic - next topic

Lena_dV

Feb 05, 2019, 02:17 pm Last Edit: Feb 05, 2019, 02:19 pm by Lena_dV
Hello everyone,
I don't have much experience with the Arduino yet and am currently trying my first bigger project. However, I'm reaching my programming limits and look for advice in the forum.

The setting is as follows:
I have a pressure sensor from Keller and want to read it digitally via RS485 with the Arduino Mega. The MAX RS485 module is available and connected as shown in the picture.

The code I'm currently using is this:

int pressure = 0;

void setup() {

pinMode(19,INPUT); //RX
pinMode(18, OUTPUT); //TX
pinMode(13, INPUT);
Serial.begin(9600);
Serial1.begin(9600);
}

void loop() {

pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial1.print(2741467);

pinMode(13, INPUT);
digitalWrite(13, LOW);
delay(101);

if(Serial1.available()){
 pressure = Serial1.read();
 Serial.println(pressure);
}

However, I do not understand the data that I get displayed in the serial monitor. With Serial1.print I want to send the request for data to the sensor. But I don't know if I'm sending the right request and can't figure out the communication protocol of the sensor.

Can someone help me optimize the code so that I see the pressure values of the sensor?

I am looking forward to many answers.

Many greetings
L.

MarkT

pin13 must always be an output, or the RS485 transceiver will be switching between RX and Tx at random.

Have you read the protocol description document you posted?  You need to drive MODBUS requests and gather the responses. Have you looked at https://playground.arduino.cc/Code/ModbusMaster
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Lena_dV

Thank you for your answer.
I changed the code as you recommended (see below).

Code: [Select]

int pressure = 0;

void setup() {

 pinMode(19,INPUT); //RX
 pinMode(18, OUTPUT); //TX
 pinMode(13, OUTPUT);
 Serial.begin(9600);
 Serial1.begin(9600);
}

void loop() {
 
 digitalWrite(13, HIGH);
 Serial1.print(2741467);
 
 digitalWrite(13, LOW);
 delay(10);

 if(Serial1.available()){
  pressure = Serial1.read();
  Serial.println(pressure, BIN);
 }
 


And yes, I red the communication protocol, but I didn´t totally understand. There are functions to request different parameters from the sensor but I don´t know how to send those request with the arduino via the RS485 Module to the sensor.

What is meant with the Modbus? Is the RS485 Module also a Modbus?

Thanks a lot.

MarkT

[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up