ModbusRTUMaster RS485 half duplex

Good morning,

I'm working on an Arduino project that requires a communication between Arduino and multiple pressure sensors. The master is an Arduino UNO (or Mega 2560) that communicates to different slaves (the sensors) and sends data to a pc.

The communication will be via RS485 half duplex and the protocol will be Modbus RTU.

Could you please, indicate to me some link for the ModbusMaster library built for RS485 half duplex?

Thank you, Rue

Thank for the suggestion,

I have already red the post. I opened this new one because I am using the library:SimpleModbusMasterV2rev2

The communication doesn't work fine ....I was wondering if the library is built for RS485 half-duplex.

If I have to redirect my questions and to the post you indicated to me I will do that.

I use this library in my ModBus projects. I've chosen it mainly because it provides support for both master and slave modes and because it's quite slim.

Choose the Mega as the Arduino basis if you need the serial channel to the PC. A hardware serial interface is much more reliable than the software emulations (especially the SoftwareSerial library) in the first place but they also support parity bit setups as required by the ModBus specification (although some devices does not conform to the standard in this point).

Thank you for the suggestions,

I have written my program using SimpleModbusMasterV2rev2 library and I fixed the problem.

Now I can read the pressure value, but a question still remains.
Some garbage comes on the request message. There is a way to eliminate it and optimize the communication?

I attached the program, the hardware set-up, the serial monitor screen shoot and the pressure manual.

At present I only read the pressure value (0x0002), but in the future I would also like to read out the temperature value (0x0008)…in order to do this I have to use PACKET2, or it is enough to use PACKET1 changing the register index in the function modbus_construct ()?

Any suggestion or useful link will be really appreciated.

Regards

SimpleModbusMasterArduinokeller.ino (3.96 KB)

comm_protocol_e.pdf (873 KB)

  modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS,readRegsPress);   // Initialize the Modbus Finite State Machine

You're using the same serial interface for the RS-485 (ModBus) as you use for the debugging information. So I'm not surprised that some information doesn't transmit as you expect it. Although the driver should be disabled during that the ModBus library expects to rule the serial interface without disturb.

Ok, Thank you so much for the help.

I will try to implement all the suggestions and we will keep you updated.

Regards, Rue

Good morning,

My program is working now, but for my application I think it is better to keep the two communications separated (sensor-board and board-pc).So, I’ve decided to switch to Arduino Mega 2560, mainly to avoid collisions on data.

For the future evolution of my project , should I use the Arduino Mega to read out signals via an RS485 to 4-20mA converter?

Thank you

RUE writes:

RS485 to 4-20mA converter?

TIA-485 is digital and 4-20mA is analogue, so you would need to specify the data protocol used on the TIA-485 side, and what are you driving the 4-20mA signal into ?

Or do you mean a 4-20mA to TIA-485 Modbus converter, where you connect a 4-20mA signal, such as sensor and then read the data using Modbus RTU from a controller or computer ?

If the above is correct, then what converter do have in mind to use and would it not be possible just to use the Arduino Mega to connect to the sensor directly ?

If your sensor is already 4-20mA, then it is not difficult at all to interface this into an analogue port of either the Arduino or better still a little ADC board, such as MCP3242 or ADS1115 type for better accuracy.

Sorry, I didn’t put a lot of details about the project.

I am preparing a temporary solution for a client that wants to read out the sensor’s data in 4-20mA.

I thought to use an Arduino board because I have to do a pretty long elaboration on the data before converting them in the desired format (4-20mA).

Surfing on internet I have found from WAYJUN a TIA485 to 4-20mA that supports Modbus RTU, so I decided to go ahead with it.

Attached you can see the block diagram of my current system and the final system.

Do you think the choice of Arduino Mega 2560 should be fine?

Okay, I understand better now.

One problem I see which doesn't really effect your end goal, is that there is a lot of conversions between the analogue and digital realm, ADC and DAC.

As long as you know the details of each conversion process to know that you will have a faithful 4-20mA representation of final signal, which I guess will again go into another analogue to digital converter, such as PLC for further processing or to SCADA, correct ?

Would it not be possible to read the the sensor signal directly as analogue with as I mentioned using a quality ADC such as MCP3234 and then do all the processing you need using the Arduino board of choice or other micro-controller ?

If you are indeed sending to a device like a PLC, then why not send the processed data using digital, say, using Modbus, either Modbus TCP on Ethernet or Modbus RTU on TIA-485 or RS-232 ?

An Arduino Mega 2560 will be fine, but there is little cost difference between many of the boards. You may be able to use a UNO style or go 1284 which is a sort of Goldilocks thing, or in fact a DUE, where you do have the on-board 12 bit ADC and DAC if you choose.

You mention multiple pressure sensors, what sort are they, do you have a part number ?

Just a few thoughts and methods I have used in the past.

Thank you for the inputs.

You are right about the different conversions...probably I will loose accuracy, but I will take the risk.

The sensor is from Keller, I have appended the datasheet post #5: it has an already integrated electronic, so I can only adapt the existing output.

If you confirm to me that an Arduino Mega 2560 should be ok for my prototype, I will go ahead with it. I already have it on my desk ;-)

For me Arduino will be the mean to make elaboration of data before the conversion to the final formal.

This seems to me the best and compact solution to get things working in short time, keeping in mind that it is only a temporary solution.

Hello,

I still have a question…I changed my program for Arduino Mega.

Attached you can find the programs for UNO (TestUNO) and the the program for Mega, it seems that something is wrong with the version for Mega.

Could you please, say to me what I am doing wrong?

Thank you,
Rue

Test_UNO.ino (3.61 KB)

Test_Mega.ino (3.17 KB)

Sorry, I forgot to put the schematics of both.

Thank you so much, you are right, now it is working.

If I remove the conditions:

if(packets[PACKET1].successful_requests > last_successful_requests1)
{
last_successful_requests1 = packets[PACKET1].successful_requests;

if(packets[PACKET2].successful_requests > last_successful_requests2)
{
last_successful_requests2 = packets[PACKET2].successful_requests;

The parameters come in a strange way, as you can see from the screen shoot.

I am obliged to keep the conditions (see screenshoot), but if I want to put both the parameters in a unique formula like:
Y=temperature +pressure

How can I do ?

Here you are the program that doesn’t work.

Test_Mega.ino (3.29 KB)

Hi guys,

It is a long time I didn't write...

The program I made now is working: I am able to read data from the pressure sensor using the serial monitor. I am using the arduino Mega 2560.

Now my question is concerning the conversion from the pressure value (sensor data) into 4-20mA format (client format).

When I surfed on internet I have found RS485 to 4-20mA converter and I bought one just check how to use it. Here you have the link:

http://www.wayjun.net/index.php?main_page=product_info&products_id=41

It support Modbus.

In the final hardware configuration, I willMy idea is to add an RS485-to TTL module to Arduino an connect the converter.

In this case, I have to use the Arduino as a master and writing on the Modbus? Any suggestions about the topic or link where I can collect more info, will be really appreciated.