# MODBUS RTU USING arduino Modbus libarray

**URL:** <https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939>\
**Category:** Libraries\
**Created:** [February 24, 2024, 2:47pm UTC](https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939 "2024-02-24T14:47:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilkumar55](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@sunilkumar55](https://forum.arduino.cc/u/sunilkumar55)\
**Post date:** [February 24, 2024, 2:47pm UTC](https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939/1 "2024-02-24T14:47:51Z")

</div>

Hii there,

1. i have a question regarding the compatibility of this library, is thhis library compaitible with arduino UNo ?
2. I was exploring the rs485 library on which this library is dependent for RTU,

```arduino
#ifndef RS485_DEFAULT_TX_PIN
#ifdef PIN_SERIAL1_TX
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
#else
#define RS485_DEFAULT_TX_PIN 1
#endif
#endif

#ifdef **AVR**
#define RS485_DEFAULT_DE_PIN 2
#define RS485_DEFAULT_RE_PIN -1
#elif ARDUINO_NANO_RP2040_CONNECT
#define RS485_DEFAULT_DE_PIN A1
#define RS485_DEFAULT_RE_PIN A0
#elif ARDUINO_SAMD_ZERO
#define RS485_DEFAULT_DE_PIN A4
#define RS485_DEFAULT_RE_PIN A5
#else
#ifndef RS485_DEFAULT_DE_PIN
#define RS485_DEFAULT_DE_PIN A6
#define RS485_DEFAULT_RE_PIN A5
#endif
#endif

```

here i copuldnt find the pin number on which tx, rx pin is cxonnected, however de/re pin is mentiond there

1. Also does this library needs HARDWARE SERIAL ONMLY, can we run it using software serial ?
2. Can u please help me finding where is the exact implementation of transmitting and receiving data as i couldnt find it either in modbus / rs485 blibrary.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [February 24, 2024, 5:31pm UTC](https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939/2 "2024-02-24T17:31:32Z")

</div>

> [@sunilkumar55](#):
>
> this library

As a note for the forum helpers, I'll explain that by "this library", @sunilkumar55 is referring to " **ArduinoModbus**" (I happen to have the missing context since I triaged @sunilkumar55's issue in that repository):

> **[GitHub - arduino-libraries/ArduinoModbus](https://github.com/arduino-libraries/ArduinoModbus)**
>
> Contribute to arduino-libraries/ArduinoModbus development by creating an account on GitHub.

> [@sunilkumar55](#):
>
> is thhis library compaitible with arduino UNo ?

Which Uno are you referring to specifically? Arduino has manufactured multiple boards that contain "Uno" in their name, each of which have significant relevant technical differences:

- [**UNO**](https://docs.arduino.cc/hardware/uno-rev3) (R1, R2, R3) or [**Uno Mini**](https://docs.arduino.cc/hardware/uno-mini-le)
- [**UNO R4 Minima**](https://docs.arduino.cc/hardware/uno-r4-minima)
- [**UNO R4 WiFi**](https://docs.arduino.cc/hardware/uno-r4-wifi)
- [**UNO WiFi**](https://docs.arduino.cc/retired/boards/arduino-uno-wifi)
- [**UNO WiFi Rev2**](https://docs.arduino.cc/hardware/uno-wifi-rev2)

Since it is the most common, I'll proceed to answer on the assumption you mean **Uno R3** (or any of the other ATmega328P-based boards):

Arduino does not provide official support for using this library on the **Uno R3**. The reason was explained by a developer when the decision was made to do so:

[https://github.com/arduino-libraries/ArduinoModbus/pull/106](https://github.com/arduino-libraries/ArduinoModbus/pull/106)

> ## Drop official support for AVR for this library.
> 
> This is imho necessary since even one of our own examples does not link anymore, due to the required memory exceeding the available ressources of the ATMEGA328P based Arduino Nano.

So the reason is not that there is some known technical incompatibility between the library and the **Uno R3** , but instead that Modbus applications tend to require a significant amount of memory and the AVR boards like the Uno R3 have limited amounts of memory.

So the answer to your question is: "it is probably compatible, but there are no guarantees".

> [@sunilkumar55](#):
>
> i copuldnt find the pin number on which tx, rx pin is cxonnected

> <https://github.com/arduino-libraries/ArduinoRS485/blob/1.0.5/src/RS485.cpp#L209-L209>

> <https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/boards.txt#L106-L106>

> <https://github.com/arduino/ArduinoCore-avr/blob/1.8.6/variants/standard/pins_arduino.h#L252-L252>

> <https://github.com/arduino-libraries/ArduinoRS485/blob/1.0.5/src/RS485.h#L29-L29>

Or in other words: 1 and 0

> [@sunilkumar55](#):
>
> does this library needs HARDWARE SERIAL ONMLY, can we run it using software serial ?

At this time, it is hardcoded to use the primary hardware serial object. The request for addition of the capability for an arbitrary Stream object to the library is tracked by the developers here:

> <https://github.com/arduino-libraries/ArduinoModbus/issues/29>
>
> I've been reading \[this good article\](https://www.stderr.nl/Blog/Hardware/Electr…onics/Arduino/ModbusLibrary.html). He's been testing some libraries across the web and make some good comparison points.
> Let me quote some for this particular library:
> 
> \> https://github.com/arduino-libraries/ArduinoModbus
> \> - Official library from Arduino.
> \> - Master and slave.
> \> - Uses the RS485 library to communicate, but does not offer any way to pass a custom RS485 instance, so it is effectively hardcoded to a specific serial port.
> \> - Offers only single value reads and writes.
> \> - Slave stores value internally and reads/writes directly from those, without any callback or way to detect that communication has happened.
> 
> More on the page, and I hope this reference makes a good study for further improvement.
> So, for my personal request, Any chance to implement to softwareSerial? \*\*So many other boards can use this library later.\*\*
> 
> Because I want the official library can cover it all.
> 
> Thanks in advance.

> [@sunilkumar55](#):
>
> Can u please help me finding where is the exact implementation of transmitting and receiving data

I'm not able to provide assistance with that. Hopefully one of the other forum members will be able to help.

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [February 24, 2024, 5:44pm UTC](https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939/3 "2024-02-24T17:44:26Z")

</div>

I believe that the general approach to Modbus RTU using an Arduino UNO is to use a software serial port and the [ModbusMaster](https://github.com/4-20ma/ModbusMaster) library which you should be able to install via the library manager.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 22, 2024, 5:45pm UTC](https://forum.arduino.cc/t/modbus-rtu-using-arduino-modbus-libarray/1227939/4 "2024-08-22T17:45:26Z")

</div>

Closed on August 22, 2024, 5:45pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
