Hi I'm using an arduino Mega2560 and a standard RS485 module to connect to a Schneider PowerMeter PM2120 with the Official Arduino Library ArduinoModbus, I need to know where can I change the Modbus Serial Port, I was looking on the reference but I don't found a function to do that; After this I was looking on the libraries files directly but I dont found where to change that.
By default when I use "ModbusRTUClient.begin(9600)" It uses Serial RX0 and TX0 by default. I need to use another serial port like Serial3.
Changing SERIAL_PORT_HARDWARE to SERIAL_PORT_HARDWARE1 (or 2 or 3) should do the trick.
SERIAL_PORT_HARDWARE is defined in pins_arduino.h (for the mega on a windows install C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
Changing SERIAL_PORT_HARDWARE to SERIAL_PORT_HARDWARE1 (or 2 or 3) should do the trick.
Hi sterretje, I did the change you suggest but it don't works. Which other library can I use to manage Modbus communication with an Arduino Mega/Uno/Nano?
pylon:
That library is designed for the MKR Arduino series. Don't use it on AVR type Arduinos (e.g. UNO, Mega2560, etc.).
I think this is incorrect. The library properties architectures field is set to *, which indicates compatibility with all architectures. The same goes with its dependency of the ArduinoRS485 library.
it is compatible with our MKR RS485 Shield and with our network enabled products like the Ethernet shield, the MKR family of boards and the Arduino UNO WiFi Rev 2 just to name a few.
Sometimes it's worth a little extra typing to make sure the message gets across. I'm guessing we all have a very high WPM (unless using some worthless mobile touchscreen stupidity) so it should only take a matter of seconds to do so.
I think this is incorrect. The library properties architectures field is set to *, which indicates compatibility with all architectures. The same goes with its dependency of the ArduinoRS485 library.
That's correct, the library author doesn't mask the library for other platforms but a quick look at the code shows you that the library is definitely not intended to be used on the AVR platform. It uses RAM as if there is no limit for that resource and makes also use of the String class which definitely shouldn't be used on AVRs.
Read this topic yesterday while researching, dropped back to confirm that the first slave RTU library I have found to work for serial3 on a mega2560 is not in the repository.
Seems solid so far. I have modified the incoming addresses and have the "full" example working and no comms errors showing on the display.
Most of the libarys are aimed at the arduino being the master obviously and the only slave library (GitHub - lucasso/ModbusRTUSlaveArduino: ModbusRTU Slave) does not compile with an unmodified example for the mega. Probably an easy fix but did not inspire confidence.