Serial Monitor to Bluetooth terminal communication problem

Hello everyone,

I am working on a project but the problem is,
The data I send from the Bluetooth terminal is not visible on the Serial monitor...


#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;




const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {

   Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");

    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
    
    while (SerialBT.available() > 0 && newData == false) {
        rc = SerialBT.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

The sketch works fine for me

What baud rate do you have the Serial monitor set to and do you see a message on it of any kind when you run the sketch ?

Hiii,

Thanks for your reply UKHeliBob,

The code is working for SERIAL monitor...

while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

but when I use SerialBT instead
Serial monitor does not show messge...

while (SerialBT.available() > 0 && newData == false) {
        rc = SerialBT.read();

This is the problem

& also I have chaeked BAUD rate of my serial monitor.
Serial monitor prints all other message like

The device started, now you can pair it with bluetooth!

<Arduino is ready>

It is just not printing message I send from SERIAl monitor Bluetooth.

Presumably the ESP32 can be paired with the 'phone and the device can be selected in the Bluetooth monitor app ?

Yes sir,

I connect the ESP32 to my mobile...
& then tried to send a number from mobile to ESP32 but the received data is not visible on the SERIAL MONITOR

I apologise for being pedantic, but please describe exactly the steps you used to pair the ESP32 with the mobile (Ardroid or IOS ?), which app you are using on the mobile, how you selected the device to use in the app and how you sent the data from the app

I am using Android.
I am using a app name ArduTooth.

then I selected my device named 'ESPtest'

then I select for TERMINAL option.
& entered serial terminal...
then I typed 12345

and after I send data.

THAT'S all.

My SERIAL-MONITOR is just showing this.

I can't find that app in the Play Store by that name. Its actually appears to be called "Arduino Bluetooth Terminal" by Frederik Hauke. I have installed it but, like you, it does not work for me unless I expressly end the message with a carriage return, which is what the sketch is looking for

Can you spot any mistake in the code I am using ???

Yes I am using same app.

Are you ending the message with a Carriage Return in the app ? The sketch will not work without it because it will never know that the message is complete

No I am not using any Carriage Return

Then the sketch will never know that the end of message has been reached and print it

Try ending the message with a Carriage Return.

Press
image
in the app before you press
image
to send the message

STILL no change

Odd

Let's try an experiment

In the sketch change this line

    char endMarker = '\n';

to

    char endMarker = '.';

upload the revised code and when you enter the message in the Bluetooth Terminal end it with a full stop before you send it

Report back what happens

Hey it worked :upside_down_face:

Thanks for your help :grinning:

What exactly worked ?

It should work with '\n' as the end marker as long as you send it from the Bluetooth terminal using the
image
button at the end of the message before you send it

1 Like

Ok :upside_down_face: