After uploading the code I want my ESP to be then connected to the transceiver module which is then connected to LED.
My question is, can I reuse the transmit pin or can is it okay to use other GPIO in order for my ESP to transmit the data to LED over the transceiver module?
Any help is appreciated, I am not that familiar with working on pins input/output and Arduino ide in general.
#define RXD2 16
#define TXD2 17
void setup()
{
// Note the format for setting a serial port is as follows:
// Serial2.begin(baud-rate, protocol, RX pin, TX pin);
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial Txd is on pin: "+String(TX));
Serial.println("Serial Rxd is on pin: "+String(RX));
}
void loop()
{
while (Serial2.available())
{
Serial.print(char(Serial2.read()));
}
}
the serial.begin(115200) - it is for the baud rate of ESP communication right?
then the serial2.begin(9600) is for the transmission of data to RS485 transceiver?
should I include the rx pin on the parameter of serial2.begin even if I will only send the data to the transceiver? can it be that I will only use this:
Serial2.begin(9600, SERIAL_8N1, TXD2);
also, inside the loop, should I use serial.write if I wanted to send my data to the transceiver?
Serial is for SerialMonitor.
Serial2 is, yes, the peripheral.
Include both vs one or the other - Not hard to try that.
In the loop use Serial2.write or Serial2.print depending whether you're sending a number or the representation of a number (the value 100 vs "100").
As for me, I will be using ESP WROOM-02 and not ESP32 and the only thing ESP do is to send and it does not need to receive feedback from LED. And I am planning to use the TXD pin of the ESP to send a packet of data to LED.
And AFAIK, Serial.begin is by default 8N1, but still I can declare this parameter, but my question is, Serial2.begin(baud-rate, protocol, RX pin, TX pin); in this sample code, I don't have to set my RX pin so can I just get rid of that in the parameter?
I have this as my connections. I just came to realize that the Serial is for the computer and arduino communication mainly and using it to let my ESP send data to transceiver might be tricky.
So I will be trying to use Serial1 or Serial2 instead.