Using ArduinoRS485
Hi all,
Since we are using ArduinoModbus for our Modbus TCP interfacing (Thanks again, Tom), I thought a good idea to try and use ArduinoRS485 as my regular Modbus RTU master / slave library through the "Serial" (RS485) port of the IndIO.
I had to change a bit my RS485.cpp file so :
// Original Code ------------------------------------------------------------------------- Modified DD.28/06/2021
// RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
// Modified Code ------------------------------------------------------------------------- Modified DD.28/06/2021
RS485Class RS485(Serial, 1, 0, 9);
//End of changes ------------------------------------------------------------------------- Modified DD.28/06/2021
I tried every permutation of the pin numbers, and I get this :
RS485Class RS485(Serial, 9, 0, 1); : No communication, break condition every read or write
RS485Class RS485(Serial, 9, 1, 0); same-o
Any other combination : 1 "break condition error" every 2 read / write from / to the slave.
Something I did not get right in the RS485 file or what ?
This is using the Arduino RTU "kitchensink" examples straight from the library, except a "Serial" to "SerialUSB" change for the messages.
Hi Didier,
Thanks for pointing to that library, i have not used it myself but maybe this suggestion will help. In the usual Arduino setup with MAX485 the RE and DE pins are joined, and used as TxEnable, which is D9 on the INDIO. The txPin in the library is only used for the break functions, i'm not sure what their use is, they are not mentioned in the examples. So my best bet for the 3 pins:
- txPin: 1
- dePin: 9
- rePin: 9
(the library has a function setPins() so you don't have to edit the .cpp)
Works perfectly, back to the original .cpp code with a "RS485.setpins(1,9,9);" instruction before the ModbusRTUServer.begin, and with the middle jumper on in the D21G to activate the termination resistor.
I'll get to the master side now. Thanks, Tom !
Didier, DG2R
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 6/28/21, 5:15 PM |
Seen: 3028 times |
Last updated: 7/1/21, 8:58 AM |
After some rather tedious trouble shooting this library still works fine, but has some troublesome aftereffects : 1 : RTU Modbus will only work on Serial1. I tried tinkering with the library code, but to no avail so I quit there. No big trouble on Industruino anyway 2 : If you intend to use DHCP on your Ethernet Module, just forget it. I spent 2 days trying to get my Blynk connection to get online due to an installed RTU slave on the RS485. This probably is the reason why an Arduino MKR GSM will connect to ArduinoCloud until you try and use it as a Modbus to Cloud interface, since ArduinoCloud is an MQTT-based, DHCP connexion. I don't really have the time to dive in the depths of the ArduinoModbus and ArduinoRS485 library, but stopping the Modbus RS485 connection makes the Blynk connection possible. Didier