Problem opening the USB serial tool

Hi
I’m having a problem using the serial USB function, when I open the tool, it closes immediately

Details :
• Arduino Mega 2560 +USB Serial communicacion.
• iPhone 7 (iOS 11.4)

#define BLYNK_PRINT DebugSerial


#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>


char auth[] = "*****************************";


void setup()
{
  // Debug console
  DebugSerial.begin(9600);


  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void loop()
{
  Blynk.run();
}


What tool?

And what closes?

OK, I think you are trying to use the USB link script that turns your PC into a serial-to-network adapter (for the Blynk connection)… If so, then you cannot use the Serial monitor in the IDE… as that will automatically try to use the same USB port that the programming and USB link will use (although not at the same time), and thus interfere with the Blynk connection.

That is what the DebugSerial is for… however you will need a TTL-USB adapter and another program like termite to act as the serial monitor on another USB port.

Also note that the MEGA has multiple hardware based serial ports, so using Serial1 (pins 18 & 19) instead of softserial is usually the prefered way to do it.

https://examples.blynk.cc/?board=Arduino%20Mega%202560&shield=Serial%20or%20USB&example=GettingStarted%2FBlynkBlink