Serial Monitor prints unreadable symbols

Hello,
I have issue with the serial monitor and could not solve it even though I was searching for solution on the internet as well as here. My serial monitor should print IP adress of my ESP32 but instead of that it prints unreadable marks. In platformio.ini, I set monitor_speed = 9600 and in my source code in setup Serial.begin(9600). I try it in terminal with pio device monitor as well as with pio device monitor --raw, but without success (see screenshot). My you please help.
Thank you
Gabriel

Full source code? Maybe it gets overwritten?

Is it a normal ESP32 dev board with built-in USB-UART converter or a custom board?

#include <WiFi.h>

#include <ESPAsyncWebServer.h>

#include <Adafruit_Sensor.h>

#include <DHTesp.h>

const char* ssid = "xxx";  //see WLAN setting

const char* password = "xxx"; // WLAN password

int dhtPin= 16;

DHTesp dht;

// Code from library which works with Arduino but not ESP32

/*#define DHTPIN 27           // Digital pin connected to the DHT sensor

#define DHTTYPE DHT22       // DHT 22 (AM2302)

DHTesp dht(DHTPIN, DHTTYPE);*/

AsyncWebServer server(80);  // Create an AsyncWebServerobject on port 80

void initWiFi(){

  WiFi.mode(WiFi_STA);   //station mode: the ESP32 connects to an access point

  WiFi.begin(ssid, password);

  Serial.println("Connecting to WiFi..");

  while (WiFi.status() != WL_CONNECTED) {

    Serial.print('.');

    delay(1000);

  }

  Serial.println(WiFi.localIP());

}

String readDHTTemperature() {

  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

  // Read temperature as Celsius (the default)

  float t = dht.getTemperature();

  // Read temperature as Fahrenheit (isFahrenheit = true)

  //float t = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).

  if (isnan(t)) { 

    Serial.println("Failed to read from DHT sensor!");

    return "--";

  }

  else {

    Serial.println(t);

    return String(t);

  }

}

float t = dht.getTemperature();

String readDHTHumidity() {

  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

  // Read temperature as Celsius (the default)

  float h = dht.getHumidity();

  // Read temperature as Fahrenheit (isFahrenheit = true)

  //float t = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).

  if (isnan(h)) { 

    Serial.println("Failed to read from DHT sensor!");

    return "--";

  }

  else {

    Serial.println(h);

    return String(h);

  }

}

float h= dht.getHumidity();

const char index_html[] PROGMEM = R"rawliteral(

<!DOCTYPE HTML><html>

<head>

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">

  <style>

    html {

     font-family: Arial;

     display: inline-block;

     margin: 0px auto;

     text-align: center;

    }

    h2 { font-size: 3.0rem; }

    p { font-size: 3.0rem; }

    .units { font-size: 1.2rem; }

    .dht-labels{

      font-size: 1.5rem;

      vertical-align:middle;

      padding-bottom: 15px;

    }

  </style>

</head>

<body>

  <h2>ESP32 DHT Server</h2>

  <p>

    <i class="fas fa-thermometer-half" style="color:#059e8a;"></i> 

    <span class="dht-labels">Temperature</span> 

    <span id="temperature">%TEMPERATURE%</span>

    <sup class="units">&deg;C</sup>

  </p>

  <p>

    <i class="fas fa-tint" style="color:#00add6;"></i> 

    <span class="dht-labels">Humidity</span>

    <span id="humidity">%HUMIDITY%</span>

    <sup class="units">&percnt;</sup>

  </p>

</body>

<script>

setInterval(function ( ) {

  var xhttp = new XMLHttpRequest();

  xhttp.onreadystatechange = function() {

    if (this.readyState == 4 && this.status == 200) {

      document.getElementById("temperature").innerHTML = this.responseText;

    }

  };

  xhttp.open("GET", "/temperature", true);

  xhttp.send();

}, 10000 ) ;

setInterval(function ( ) {

  var xhttp = new XMLHttpRequest();

  xhttp.onreadystatechange = function() {

    if (this.readyState == 4 && this.status == 200) {

      document.getElementById("humidity").innerHTML = this.responseText;

    }

  };

  xhttp.open("GET", "/humidity", true);

  xhttp.send();

}, 10000 ) ;

</script>

</html>)rawliteral";

// Replaces placeholder with DHT values

String processor(const String& var){

  //.println(var);

  if(var == "TEMPERATURE"){

    return readDHTTemperature();

  }

  else if(var == "HUMIDITY"){

    return readDHTHumidity();

  }

  return String();

}

void setup(){

//initialize the Serial Monitor for debugging purposes

Serial.begin(9600);

//Initialize the DHT sensor

/*dht.begin(); - works only with DHT Arduino library*/

dht.setup(dhtPin, DHTesp::DHT11);

/*

//Connect to your local network and print the ESP32 IP address

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

  delay(1000);

  Serial.println("Connecting to WiFi..");

  WiFi.begin(ssid, password);

  */

initWiFi();

//Finally, add the next lines of code to handle the web server

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){

  request->send_P(200, "text/html", index_html, processor);

});

server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){

  request->send_P(200, "text/plain", readDHTTemperature().c_str());

});

server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){

  request->send_P(200, "text/plain", readDHTHumidity().c_str());

});

//Lastly, we can start the server

server.begin();

}

void loop(){

 // Serial.println(WiFi.localIP());

}

It is normal ESP32-WROOM-32 from Espressif with 30pins in total.

Hello,
I wrote down in platformio.ini the futher following setting for serial monitor and now it works.

Thank you