RS485

I apologize if this question has been answered elsewhere. I have tried to use the Arduino485 library (end goal is to use with Modbus library) but I am stopped in my tracks. The library by Sandeep Mistry is missing any information for actually using this library with different pins (like SoftwareSerial does).

There is a setPins method but on my Uno does nothing. Here is the simple piece of code:

#include <SoftwareSerial.h>
#include <ArduinoRS485.h>

void setup() {

RS485.begin(9600);
RS485.setPins(10,11,12);

}

void loop() {

RS485.beginTransmission();
RS485.print("hello ");
RS485.endTransmission();

delay(1000);
}

The above code makes no attempt to use the pins 10,11,12 and still flashes the TX LED. I also see that attempting to instantiate another RS485 object does not allow me to change serial pins. What am I doing wrong???

dr_when1955:
I apologize if this question has been answered elsewhere. I have tried to use the Arduino485 library (end goal is to use with Modbus library) but I am stopped in my tracks. The library by Sandeep Mistry is missing any information for actually using this library with different pins (like SoftwareSerial does).

There is a setPins method but on my Uno does nothing. Here is the simple piece of code:

#include <SoftwareSerial.h>
#include <ArduinoRS485.h>

void setup() {

RS485.begin(9600);
RS485.setPins(10,11,12);

}

void loop() {

RS485.beginTransmission();
RS485.print("hello ");
RS485.endTransmission();

delay(1000);
}

The above code makes no attempt to use the pins 10,11,12 and still flashes the TX LED. I also see that attempting to instantiate another RS485 object does not allow me to change serial pins. What am I doing wrong???

Every one else uses standard serial communications with a TTL to RS-485 adapter board. What function does the RS-485 library give you that normal serial does not?

Paul

Hi, Thank you for your reply.

"Every one else uses standard serial communications with a TTL to RS-485 adapter board. What function does the RS-485 library give you that normal serial does not?"

Good question. I assume that using the RS485 library offers "beginTransmission(), etc for controlling DE pin, and it was made to supposedly be easy to change serial pins for Modbus library. Easy enough using regular serial. So my next question is, how well does SoftwareSerial work with Modbus library? I need to use alternative pins for serial instead of the main serial pins (usb).

Bob

dr_when1955:
Hi, Thank you for your reply.

"Every one else uses standard serial communications with a TTL to RS-485 adapter board. What function does the RS-485 library give you that normal serial does not?"

Good question. I assume that using the RS485 library offers "beginTransmission(), etc for controlling DE pin, and it was made to supposedly be easy to change serial pins for Modbus library. Easy enough using regular serial. So my next question is, how well does SoftwareSerial work with Modbus library? I need to use alternative pins for serial instead of the main serial pins (usb).

Bob

I have no experience with modbus, except we build batches of modbus boards for a customer.

Paul

dr_when1955,

I am trying to find the same thing as you, did you ever find an answer on this thread?

Thanks,

Nick

NRobinson2:
dr_when1955,

I am trying to find the same thing as you, did you ever find an answer on this thread?

Thanks,

Nick

I'm not OP, but I have similar issues.
The library is hardcoded to use the hardware serial - it looks like this:

RS485Class::RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin) :

So it looks like you can redefine the pins that control the driver state, but not the rx/tx pins. (The txPin definition here is used to force the TX pin low at the end of a transmission, releasing the bus.)
I'm sure that this can be reworked to use software serial, but that's not something I am going to wade into tonight. :slight_smile: