Where to begin communicating with RS232 using an ESP32 ?

Hello !

I want to take the readings(output) from a Radar that has RS232 interface using an Olimex ESP32-POE. I am planning to use the UEXT connector of the ESP to connect to the RS232 interface.

The problem is that this is the first project in which I am trying to use the serial communication of the ESP and I have no idea what to write in code.

This is the only relevant piece of code I found:

#define RXD2 16
#define TXD2 17
char c;
String readString;
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);
  Serial2.println("serial2test");
  Serial.println("Serial Txd is on pin: " + String(TX));
  Serial.println("Serial Rxd is on pin: " + String(RX));

}

void loop() {
  while (Serial2.available()) {
    c = Serial2.read();
    readString += c;
  }
  if (readString.length() > 0) {
    Serial.print(readString);
    Serial2.print(readString);
    //server.print(readString);
    readString = "";
  }
}

Here we can see that GPIO 16 and 17 are used for communicating with the RS232 interface. But, as I previously said, I want to use the UEXT Connector. What pins do I define ? Any advice ?

Can somebody point me in the right way ? Thank you !

Here we can see that GPIO 16 and 17 are used for communicating with the RS232 interface. But, as I previously said, I want to use the UEXT Connector. What pins do I define ? Any advice ?

According to Olimex example code it's 36 (RX) and 4 (TX).

pylon:
According to Olimex example code it's 36 (RX) and 4 (TX).

Which makes it UART 1, Pins 2 and 9 on the connector:

It just take a little effort to do the digging info. If this going to be your hobby be prepared for it.

You've got 3 serial ports you can use (0), (1), (2), at this point forget about using (0).

You will need to include #include <HardwareSerial.h>

Then you will want to define your serial ports like
HardwareSerial GPSSerial ( 1 );
HardwareSerial LIDARSerial ( 2 );

(2) is the easiest to use. The natural GPIO pins for (2) are Rx = GPIO16 and TX is GPIO17.

In setup() you initialize the serial port; LIDARSerial.begin ( SerialDataBits );
To receive serial you can make something like this:

void fReceiveSerial_LIDAR( void * parameters  )
{
  bool BeginSentence = false;
  sSerial.reserve ( StringBufferSize300 );
  char OneChar;
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
    {
      while ( LIDARSerial.available() )
      {
        OneChar = LIDARSerial.read();
        if ( BeginSentence )
        {
          if ( OneChar == '>')
          {
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
            {
              xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
              //
            }
            BeginSentence = false;
            break;
          }
          sSerial.concat ( OneChar );
        }
        else
        {
          if ( OneChar == '<' )
          {
            sSerial = ""; // clear string buffer
            BeginSentence = true; // found beginning of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
    //            Serial.print( "fReceiveSerial_LIDAR " );
    //        Serial.print(uxTaskGetStackHighWaterMark( NULL ));
    //            Serial.println();
    //        Serial.flush();
  }
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

I do the serial parsing in a different task.
If you need to change your pin numbers from the natural default you'd just initialize with the pin numbers like so LIDARSerial.begin ( SerialDataBits, SERIAL_8N1, 26, 25 );

The ESP32 does not have Serial1, Serial2, SerialXXXXXX

Out of curiosity I entered the words "esp32 serial" into my internet search engine to find a cht load of available examples on ESP32 Serial.