SerialBT not declared (though it should be)

i'm having some issues with the BluetoothSerial library, i'm pretty sure my code should be okay, but when i compile it, it says that SerialBT was not declared in this scope

here's my bluetooth configuration code: (my other code basically just runs those functions)

#include <BluetoothSerial.h>

void BT_setup(){
  // put your setup code here, to run once:
  Serial.begin(115200);
  BluetoothSerial SerialBT;
  SerialBT.begin("Luna", true);
}

void connection(){
  if(SerialBT.connect()){
    lcd.setCursor(3, 1);
    lcd.print("Connected!");
    int connection_status = 1;
  }
    else{
    lcd.setCursor(0, 1);
    lcd.print("Connection error");
  }
}

void connection() has the same problem as BT_setup()

the problem it spits out is:

C:\Users\Luna\Documents\Arduino\lcd_and_soundboard\BTSerial_config.ino: In function 'void connection()':
C:\Users\Luna\Documents\Arduino\lcd_and_soundboard\BTSerial_config.ino:16:6: error: 'SerialBT' was not declared in this scope
   if(SerialBT.connect()){
      ^~~~~~~~
C:\Users\Luna\Documents\Arduino\lcd_and_soundboard\BTSerial_config.ino:16:6: note: suggested alternative: 'Serial2'
   if(SerialBT.connect()){
      ^~~~~~~~
      Serial2
Multiple libraries were found for "BluetoothSerial.h"
  Used: C:\Users\Luna\Documents\Arduino\libraries\BluetoothSerial
  Not used: C:\Users\Luna\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\libraries\BluetoothSerial
exit status 1

Compilation error: 'SerialBT' was not declared in this scope
void BT_setup()
{
    // put your setup code here, to run once:
    Serial.begin(115200);
    BluetoothSerial SerialBT;
    SerialBT.begin("Luna", true);
}

SerialBT is a local object in the BT_setup() function hence it is not accessible in other scopes

Make it a global instance instead

how do i make it global?

Create the instance of the object outside of any function just like any global variable

Please post a complete sketch should you have any further questions

i just tried
int BluetoothSerial SerialBT;

but i got the same error, did i do it right or did i completely get it wrong?

full sketch:

lcd_and_soundboard.zip (1,3,KB)

It is not an int variable or, indeed, a variable of any type. Remove the data type from the declaration

Did you miss my request ?

From this and your other topic it would seem that you need to read up on basic C/C++

2 Likes

just tried straight-up BluetoothSerial SerialBT; and it worked, thanks guys, also thanks for the tip! i'll read some C/C++ docs to see if i understand things better

I am glad that you got it working

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.