ESP32: undefined reference to `BluetoothSerial::BluetoothSerial()'

Hi All

This code will not compile. I’m needing some help to unblock this situation.

I have a FireBeetle Board V2.0 attached using a micro USB cable. As yet, no external power source is connected. The purpose of this step is to create a BTClassic link to my Android. My Arduino IDE version is 1.8.5.

On the boad a blue LED is flashing once every second, 1 Hz. A fainter LED is flashing red at two Hz.

The code, below, is straight from the internet:

This is my compiler error message:

/tmp/cczxi4wY.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
/home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:14: undefined reference to `BluetoothSerial::BluetoothSerial()'
/tmp/cczxi4wY.ltrans0.ltrans.o: In function `setup':
/home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:19: undefined reference to `BluetoothSerial::begin(String)'

Similar errors apply to the loop(){}. But I feel they are errors with a common source.

This is my code.

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
// Documentation: https://techtutorialsx.com/2018/03/13/esp32-arduino-bluetooth-over-serial-receiving-data/
// also: https://github.com/espressif/arduino-esp32/pull/1144
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#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;

void setup() {
  // EGB: changed to 9600 Baud Serial.begin(115200);
  Serial.begin(9600);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
  // https://www.arduino.cc/en/Serial/Available
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}

About the libraries: I have down loaded the Arduino Master Bluetooth libraries, in arduino-esp32-master.zip, from:

The installation of the libraries does actually concern me.

    1. I use a linux/fedora28 environment. Documentation based on Windows leaves me guessing about really what to do.
    1. The code: #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED); #error Bluetooth is not enabled! Please run make menuconfig to and enable it; #endif, Seems to be okay, no errors. But it makes me wonder about the make menuconfig. I never did any of that. And don’t understand how to actually execute the make menuconfig.
    1. I don’t see any ESP32 options in the Arduino IDE menus, maybe 'cos of 2).

Well! I look forward to your help and ideas.

Regards
EGB

When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages”. Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

Okay @pert, here is the full error/log message from the compile:

[code] Arduino: 1.8.5 (Linux), Board: "Arduino/Genuino Uno"

/home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/arduino-builder -dump-prefs -logger=machine -hardware /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/hardware -hardware /home/graham/.arduino15/packages -tools /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/tools-builder -tools /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr -tools /home/graham/.arduino15/packages -built-in-libraries /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries -libraries /home/graham/Arduino/libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path /tmp/arduino_build_308016 -warnings=none -build-cache /tmp/arduino_cache_30820 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.arduinoOTA.path=/home/graham/.arduino15/packages/arduino/tools/arduinoOTA/1.1.1 -prefs=runtime.tools.avrdude.path=/home/graham/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9 -verbose /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/arduino-builder -compile -logger=machine -hardware /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/hardware -hardware /home/graham/.arduino15/packages -tools /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/tools-builder -tools /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr -tools /home/graham/.arduino15/packages -built-in-libraries /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries -libraries /home/graham/Arduino/libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path /tmp/arduino_build_308016 -warnings=none -build-cache /tmp/arduino_cache_30820 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2 -prefs=runtime.tools.arduinoOTA.path=/home/graham/.arduino15/packages/arduino/tools/arduinoOTA/1.1.1 -prefs=runtime.tools.avrdude.path=/home/graham/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9 -verbose /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino Using board 'uno' from platform in folder: /home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21 Using core 'arduino' from platform in folder: /home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21 Detecting libraries used... "/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR  "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino" "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/variants/standard" "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp" -o "/dev/null" "/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR  "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino" "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/variants/standard" "-I/home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries/arduino-esp32-master" "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp" -o "/dev/null" Generating function prototypes... "/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR  "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino" "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/variants/standard" "-I/home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries/arduino-esp32-master" "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp" -o "/tmp/arduino_build_308016/preproc/ctags_target_for_gcc_minus_e.cpp" "/home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/tmp/arduino_build_308016/preproc/ctags_target_for_gcc_minus_e.cpp" Compiling sketch... "/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR  "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/cores/arduino" "-I/home/graham/.arduino15/packages/arduino/hardware/avr/1.6.21/variants/standard" "-I/home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries/arduino-esp32-master" "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp" -o "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp.o" Compiling libraries... Compiling library "arduino-esp32-master" Compiling core... Using precompiled core Linking everything together... "/home/graham/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p  -o "/tmp/arduino_build_308016/ESP32_SerialToSerialBT.ino.elf" "/tmp/arduino_build_308016/sketch/ESP32_SerialToSerialBT.ino.cpp.o" "/tmp/arduino_build_308016/../arduino_cache_30820/core/core_arduino_avr_uno_70804f713e9eb5598383346a5427ef57.a" "-L/tmp/arduino_build_308016" -lm /tmp/cczxi4wY.ltrans0.ltrans.o: In function __static_initialization_and_destruction_0': /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:14: undefined reference toBluetoothSerial::BluetoothSerial()' /tmp/cczxi4wY.ltrans0.ltrans.o: In function setup': /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:19: undefined reference toBluetoothSerial::begin(String)' /tmp/cczxi4wY.ltrans0.ltrans.o: In function loop': /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:26: undefined reference toBluetoothSerial::write(unsigned char)' /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:28: undefined reference to BluetoothSerial::available()' /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:29: undefined reference toBluetoothSerial::read()' /tmp/cczxi4wY.ltrans0.ltrans.o: In function _GLOBAL__sub_D_SerialBT': /home/graham/monitoring/ArduinoUno/HRV_shells/ESP32_SerialToSerialBT/ESP32_SerialToSerialBT.ino:14: undefined reference toBluetoothSerial::~BluetoothSerial()' collect2: error: ld returned 1 exit status Using library arduino-esp32-master in folder: /home/graham/monitoring/ArduinoUno/arduino-1.8.5-linux64/arduino-1.8.5/libraries/arduino-esp32-master (legacy) exit status 1 Error compiling for board Arduino/Genuino Uno. [/code]

Regards EGB

I couldn't find any information on the FireBeetle v2.0. Is it the one with the ESP32 or the one with the ESP8266. If you can post a link to where you bought the board from that would answer all questions.

pert:
… If you can post a link to where you bought the board from that would answer all questions.

The order details are: RB-Dfr-755, FireBeetle ESP32 IOT Microcontroller, Product Code: RB-Dfr-755. Maufactured by DFRobot.

The chip is ESP-WROOM-32. An image is appended.

Purchased from RobotShop.com, a Canadian outlet.

Hope that helps
EGB

firebeetle-esp32-iot-microcontroller-1_1.jpg

You are trying to compile for the Arduino/Genuino Uno board, which is completely different from your FireBeetle. You need to install the ESP32 core for Arduino following these instructions: https://github.com/espressif/arduino-esp32#installation-instructions

I can see you tried to install that package as a library. It contains libraries but it's not a library. It's a hardware package. The installation process is completely different.

I also recommend you to undo your bumbled library installation attempt as that's bound to cause problems down the road.

After installing the ESP32 hardware package you can select Tools > Board > FireBeetle-ESP32, then try compiling again.

pert: You are trying to compile for the Arduino/Genuino Uno board, which is completely different from your FireBeetle. You need to install the ESP32 core for Arduino following these instructions: https://github.com/espressif/arduino-esp32#installation-instructions

I can see you tried to install that package as a library. It contains libraries but it's not a library. It's a hardware package. The installation process is completely different.

I also recommend you to undo your bumbled library installation attempt as that's bound to cause problems down the road.

After installing the ESP32 hardware package you can select Tools > Board > FireBeetle-ESP32, then try compiling again.

You are trying to compile for the Arduino/Genuino Uno board - ... nice to know

Re-install the ESP32 core for Arduino following your instructions in the link - will do!

Then select Tools > Board > FireBeetle-ESP32, then try compiling again - will do!

Okay @pert. Thanks a million.

I'll report back! EGB

Hi All.

Success. Making progress. But another step to go!

Tasks completed:
In Preferences, in the field Additional Boards Manager URL’s, I added two more links:

From the Tool>Boards Manger, I installed ESP32 by DFRobot DFRDuino v1.0.0-rc4 by espressif.
From the Tool>Boards Manger, I installed Firebeetle-ESP32 Mainboard by DFRobot DFRDuino v0.0.7

Re: Espressif code, the link proposed was: https://dl.espressif.com/dl/package_esp32_index.json. This gave a 404. By Googling I found an alternative link: https://dl.espressif.com/dl/package_esp32_dev_index.json. This worked.

As you advised, I have removed the arduino-esp32-master muddled-up folders. This eliminated many library errors.

Two implementations:

1)In Tools>Board I selected FireBeetle-ESP32, which then specified my Baud rate (921600) and the Flash Frequency (80MHz).
It compiled, but the upload failed.
The device hangs. The last compiler messages show:

Leaving...
Hard resetting via RTS pin...

And, the blue LED is now continually off; the red still flashes a 2Hz. The device is not visible from the Android.

  1. Then I switched the Tools>Board to: ESP32-Dev-Module from espressif.

That compiles, too!!! But,
The device appears to hang, aswell. The last compiler messages show:

Leaving...
Hard resetting via RTS pin...

And, as above, the blue LED is now continually off. The device is not visible from the Android.

In summary, both the ESP32-Firebeetle and the ESP32 from espressif compile. The headers and compiler codes actually appear the same, based on the compiler messages. Both compiles result in the device hanging.

Can you help point me on further?

Thanks
EGB

Attached is just one example of the compiler messages, from FireBeetle.

ESP32_firebeetle_compiler_statements.txt (206 KB)

EGB: - https://git.oschina.net/dfrobot/FireBeetle-ESP32/raw/master/package_esp32_index.json

I don't think that was actually necessary since the ESP32 core has its own FireBeetle 32 board definition. I believe the dfrobot package is not well maintained and the ESP32 core is under active development. so using an outdated version is not advisable. Installing the dfrobot package won't actually cause any problems but you need to make sure you select the "FireBeetle-ESP32" board that's under the heading "ESP32 Arduino" in the Tools > Board menu, rather than the FireBeetle board entry from the dfrobot package

EGB: Re: Espressif code, the link proposed was: https://dl.espressif.com/dl/package_esp32_index.json. This gave a 404. By Googling I found an alternative link: https://dl.espressif.com/dl/package_esp32_dev_index.json. This worked.

This is because they haven't actually made a stable release of the ESP32 package yet. For some reason they decided to add installation instructions which are not yet valid: https://github.com/espressif/arduino-esp32/pull/1630 So you were correct to use the development URL.

EGB: It compiled, but the upload failed. The device hangs. The last compiler messages show:

Leaving...
Hard resetting via RTS pin...

That looks like the output of the end of a successful upload to me. Does the blue bar say "Done uploading"?

EGB: And, as above, the blue LED is now continually off. The device is not visible from the Android.

You're starting with something much too complex. There are an innumerable number of reasons the device might not be visible. You always need to start with something simple as a sanity check.

Do this:

  • File > Examples > 01.Basics > Blink
  • Sketch > Upload

Does it work?

pert: ... always need to start with something simple as a sanity check.

Do this:

  • File > Examples > 01.Basics > Blink
  • Sketch > Upload

Does it work?

Thanks @pert for your support.

I will do as you suggest! And report back.

Regards EGB

I took a look at the dfrobot hardware package and I think having it installed could definitely be problematic because they use the same Tools > Board menu section header and board name. So you really have no way of knowing whether you're using the official Espressif ESP32 package or dfrobot's outdated copy. I believe the idea was that, up until just a couple weeks ago, the installation process for the espressif/ESP32 package was fairly complex (they hadn't provided a Boards Manager installation yet) so it wasn't friendly for FireBeetle customers. dfrobot made a copy of the package, removed all the boards definitions other than the FireBeetle, and made it installable via Boards Manager. That was a reasonable approach but now that Espressif has Boards Manager installation also it doesn't provide so much of a benefit.

You can remove it like this:

  • Tools > Board > Boards Manager
  • Wait for the download to finish.
  • Scroll down until you see the entry for the dfrobot package. Click on it.
  • Click "Remove".
  • Wait for the removal to finish.
  • Click "Close".

The ESP32 Arduino project is still a bit rough around the edges. It's a complex project but I'm really surprised it's been 2.5 years and still no production release, considering the project had official support from Espressif.

Again, some success.

I ran the simple blink.ino sketch - as you suggested - on my FireBeetle device using Firebeetle-ESP32 v0.0.7. That blinked perfectly. I varied it just to test that it was my code that was dictating the pattern. Success.

EGB: From the Tool>Boards Manger, I installed ESP32 by DFRobot DFRDuino v1.0.0-rc4 by espressif. From the Tool>Boards Manger, I installed Firebeetle-ESP32 Mainboard by DFRobot DFRDuino v0.0.7

After a lot of experimenting, I removed this one: the ESP32 by DFRobot DFRDuino v1.0.0-rc4 by espressif. Now less confusion.

Other sources of confusion: - The FireBeetle-ESP32 board has been very inconsistent in their compilations - abending at different stages in the write stages. - Opening the serial monitor/screen stopped the device from blinking. By opening the serial monitor, that seems to divert the BT serial channels! Something for me to be aware of. For a newby, these confusions are not good.

I took my code - from the initial entry above - and added the blink.ino code:

added to the setup():
  pinMode(LED_BUILTIN, OUTPUT);
added to the loop():
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                       // wait for a second
  ... plus other lines making a distinct timing pattern

I got it blinking And, from my android - Found ESP32test on the BTClassic, with mac address - Connected and - Sent text.

Fantastic.

Thank all you so much for all your support - especially you @pert. Really appreciated!

My two HC05s and one HC06 have just arrived from Amazon. So, I'm switching to them.

Best regards Thanks EGB [SOLVED]

I'm very glad to hear you got it working. Keep that Blink example in mind for the future. It might seem like that sketch is for beginners only but I use it all the time as a "sanity check".

Hi, You might try if your upload problems are intermittent, to change the upload speed.

I had problems with my ESP32 and found the USB cable was substandard, only uploading at a lower speed fixed it. So it is now being used as a charging cable

I went to my office supplier and bought 1/2 dozen 1m budget USB cables and have not had a problem since.

Tom.. :)