Troubleshoot bluetooth with Leonardo

Hi there!

The problem with the code is that it only prints AFTER I open the serial monitor. Trying to make it so that I don’t have to open the serial monitor. Does the position of declaring the bluetooth device (BT) is the problem?

#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); 
    
char e;
       
void setup()  
{
    BT.begin(9600);
    BT.println("Hello");
    Serial.begin(9600);
    while (!Serial)
    {
      };
}
  
void loop() 
{    
    if (BT.available())
    {
    e=(BT.read());
        
    while (e=='1')
    {
  
      BT.println("HI");
    }
    }
}
 while (!Serial)
    {
      };

Are you using a Leonardo? If not, get rid of that piece of code.

groundFungus:
Are you using a Leonardo? If not, get rid of that piece of code.

Sorry probably should have stated, yes I am using Leonardo

Well, the piece of code that I posted will wait till the serial port is opened before exiting the while loop so you will need to omit that while loop in order to run the code without having to open the serial port.

groundFungus:
Well, the piece of code that I posted will wait till the serial port is opened before exiting the while loop so you will need to omit that while loop in order to run the code without having to open the serial port.

Problem is the while loop is needed, if not anything that in setup loop won't be print at all

Nowhere in that code is anything is printed by Serial in setup() or loop(), only by BT.print. Where do expect to see the prints?