Print function doesn't work

Hi! I have an ESP32 board, and I use Bluetooth to communicate with the Serial Bluetooth Terminal on my phone, in my code I need to print a message but using the SerialBT.print/SerialBT.println function doesn't print anything, the code is working and is doing what it should but it does not print any message...

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

int FlightTime = 0;

int step = 1;

int onetime = 0;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32");

}

void ProgramMode() {
  
  while(step == 1) {

    if(onetime == 0) {
      SerialBT.print("1.Flight Time Programming");
      onetime = 1;}

    if(SerialBT.available()) {
      char FlightTime = SerialBT.read();
      SerialBT.write(FlightTime);}}

}

void loop() {
  
  ProgramMode();

}

What are you expecting to be "printed" and where?

This

Is your phone connected/paired to the BT device?

Yes I can see the output of the "FlightTime"

This is the problem.

Arduino framework relies on handling some background work like serial monitors and comminucations after each loop is done. Your program doesn't allow the loop to finish even once leading to the serial protocol not being handled properly.

void loop()
{
   if(onetime == 0) {
      SerialBT.print("1.Flight Time Programming");
      onetime = 1;}

    if(SerialBT.available()) {
      char FlightTime = SerialBT.read();
      SerialBT.write(FlightTime);}}
}

use void loop as mentioned above or delete the while loop and continue with a non-blocking function. void loop() repeates infinitely no need for another while.

but I will have more cases, like step == 1 , step == 2 and so on till 4

You can if/else your way through all that, but since you mentioned cases, you might benefit from using the C/C++ switch/case statement.

https://www.arduino.cc/reference/en/language/structure/control-structure/switchcase/

a7

Serial I/O is handled entirely by interrupts. You can spend ALL your time in loop and Serial monitor I/O will still work just fine. BlueTooth may behave differently, depending on exactly which BT module and board is being used, and how they are connected.

The board is a Wemos Loli32

Oh mb, I mixed it up with serialEventRun() for a moment... Sorry for the inconvenience.

yeah just use switch case.

Wait so you're able to see the values and not the start text? That could be caused due to your serial monitor not displaying first packet that arrives. (happened to me on rp2040 and vscode terminal) If so, you might wanna send a single garbage packet at setup like helloWorld and then you might be able to see the "1.Flight Time Programming"