Problems with the UART communication between Nicla and Arduino Mega

I tried to make a UART communication between a Arduino Mega and a Nicla Sense Me and after exactly 51 seconds the Arduino stops to received the information of the Nicla, I don´t know what is wrong.
After searching I en the middle of the process between the ground and the 5 volts I put a capacitor of 100 uF and the Arduino keep the communication indefinitely.

// Arduino Mega Code
#include <SoftwareSerial.h>

const byte Nicrxpin = 11;
const byte Nictxpin = 10;

SoftwareSerial niclaser(Nicrxpin, Nictxpin);

void setup() {

  pinMode(Nicrxpin, INPUT_PULLUP);
  pinMode(Nictxpin, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  niclaser.begin(9600);
  delay(500);
}

void loop() {

  while(niclaser.available()){
  delay(2);
  char NiclaS = niclaser.read();
  String ValN = String (NiclaS);
  switch (tolower(ValN[0])){
    case '1':
      digitalWrite(LED_BUILTIN, HIGH);
      //Serial.println(NiclaS);
      niclaser.flush();      
      break;
    case '2':
      digitalWrite(LED_BUILTIN, LOW);
      //Serial.println(NiclaS);
      niclaser.flush();
      break;
  }
}

// Nicla sense me code
#include "Arduino.h"
#include "Arduino_BHY2.h"
#include "Nicla_System.h"


void setup() {
  nicla::begin();
  nicla::leds.begin();

 Serial1.begin(9600,SERIAL_8N1);
 nicla::leds.setColor(green);
 delay(500);
 nicla::leds.setColor(off);
}

void loop() {
  String LedOn ="1";
  String LedOff = "2"; 
 
 Serial1.println(LedOn);
 nicla::leds.setColor(red);
 Serial1.flush();
 delay(1000);
 Serial1.println(LedOff);
 nicla::leds.setColor(blue);
 Serial1.flush();
 delay(1000);
}

You have an Arduino Mega with 4 hardware serial ports. It may not solve your problem, but why are you using a software serial port?

I tried this code too but its the same thing

void setup() {
  // Open serial communications and wait for port to open:
  pinMode(LED_BUILTIN, OUTPUT);

  Serial2.begin(9600, SERIAL_8N1);
  delay(500);

}

void loop() { // run over and over

while(Serial2.available()){
  delay(2);
  char NiclaS = Serial2.read();
  String ValN = String (NiclaS);
  switch (tolower(ValN[0])){
    case '1':
      digitalWrite(LED_BUILTIN, HIGH);
      Serial2.flush();      
      break;
    case '2':
      digitalWrite(LED_BUILTIN, LOW);
      Serial2.flush();
      break;
  }
 }
}

Thats a 3.3V device, are its serial ports compatible\safe with the 5V Mega ?

How about starting with something really simple like:

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600, SERIAL_8N1);
  delay(500);
}

void loop() { // run over and over
  while(Serial2.available()){
    Serial.write( Serial2.read() );
  }
}

If i've typed it in correctly, it should print out on your IDE serial monitor the characters/bytes coming from your Nicla board.

When i use a 3.3V, the Nicla didn´t turn on

I use this code and still nothing.

I would suggest that you establish if the Nicla is transmitting data first.

**I am trying to communicate a Nicla SENSE ME with an Arduino Uno through SPI, I2C, and UART, and in none of the cases has it been possible. The Nicla Sense seems to have a different encoding for each standard (it is supposed to be standard but it is not for the Nicla Sense - it seems that Bosch complicates everything and they do not respond in their forums). For this reason, I want to know if someone has already solved this problem, or how to file a formal complaint.