First of all, thanks @ptillisch for your help in this problem. I was started to think that maybe I did this post too confusing.
Just to summarize!
Basically the construction of the object helps the library (since core API don’t do it by itself) to determine the use of the correct pin to do/send break signals.
So declaring a HardwareSerial object sets the way of communication between the hardware and software and the library’s constructor hwSerial lets the library know wich pins to use.
And that’s totally true, completely misleads to understand the functioning of the library. For example I just checked again the example for the Waveshare module I used first:
#include <SoftwareSerial.h>
SoftwareSerial RS485(2, 8); // RX, TX
int RS485_E = 7;
int i=0;
String comdata = "";
void setup()
{
Serial.begin(9600);
Serial.println("*** RS485 CAN Shield Receive Test Program ***\r\n");RS485.begin(9600);
pinMode(RS485_E,OUTPUT);
digitalWrite(RS485_E,LOW);
}void loop() // run over and over
{
while(RS485.available() > 0)
{
comdata += char(RS485.read());
delay(2);
}
if(comdata.length() > 0)
{
Serial.println("RS485 Receive: "+comdata);
comdata = "";
}
}
And reading what you just explained is really makes sense, In this code basically creates a serial object, because uses the dedicated one to print the data through the usb port, and also declares a GPIO as a enable since isn’t using any other library and the chip in the module does the conversion and I read again all the examples for the UNO SPE Shield (Getting Started) and this caught my attention:
And the code for the arduinos R4 as transducer node wich:
Serial.begin(115200);
Serial1.begin(9600);
delay(1000);
Serial.print("\nGateway Node ");
Serial.println(MY_ID);
pinMode(7, OUTPUT); // RS485_DE
pinMode(8, OUTPUT); // RS485_RE
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
Declares the Serial1 as the pins for communication and pins 7 and 8 as enablers
Then after reading the information from the central with the SPE protocol just uses serial port for normal communication sending the data
if (cmd == "LED " + String(MY_ID)) {
Serial1.println("T");
Serial1.flush();
Serial.println("Toggle sent");
}
And this makes me understand that I just need to declare Serial1, wich is physically connected to those pins (TX, RX) and also the enablers to control the RS485 chip and send and read the data using the serial port as usual.
Thanks again, your answer brought light to my doubts
