ESP32C3 Bluetooth Example Code not working

I am a complete noob so I apologize if this is a dumb question! I have a Xiao ESP32C3. I’m trying to get started learning to use the Bluetooth functions.

What is the exact name of the library I need to use to run the Bluetooth example codes here (https://wiki.seeedstudio.com/XIAO_ESP32C3_Bluetooth_Usage/)

It won’t compile in the online Arduino Editor. I always get an error saying: ringbuf_type_t has not been declared

From the error output the problem seems to be that multiple libraries were found for “BLEDevice.h”

Here’s the last few lines of output I get:

Multiple libraries were found for “BLEDevice.h”

Used: /home/builder/opt/libraries/arduinoble_1_3_6

Not used: /home/builder/opt/libraries/esp32_ble_arduino_1_0_1

Not used: /home/builder/opt/libraries/bleperipheral_0_4_0

Not used: /home/builder/opt/libraries/seeed_arduino_rpcble_1_0_0

Not used: /home/builder/opt/libraries/stm32duinoble_1_2_5

Not used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/BLE

Multiple libraries were found for “BLEUtils.h”

Used: /home/builder/opt/libraries/esp32_ble_arduino_1_0_1

Not used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/BLE

Error during build: exit status 1

Which library is the correct one to use?

Thank you!!!

do you have the XIAO ESP32C3 board selected in the Arduino IDE?

Yes

For the first sample, try this.

void loop() {
  // put your main code here, to run repeatedly:
//  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  BLEScanResults *foundDevices = pBLEScan->start(scanTime, false);  
  Serial.print("Devices found: ");
//  Serial.println(foundDevices.getCount());
  Serial.println(foundDevices->getCount());
  Serial.println("Scan done!");
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
  delay(2000);
}

For the second sample, try this.

//      std::string value = pCharacteristic->getValue();
      String value = pCharacteristic->getValue();

I’ve tried commenting out the includes at the beginning, but then I get a completely different error I don’t know what to do with. :frowning_face:

/usr/local/bin/arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32C3:CDCOnBoot=default,CPUFreq=160,DebugLevel=none,EraseFlash=none,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,UploadSpeed=921600 --build-cache-path /tmp --output-dir /tmp/829461094/build --build-path /tmp/arduino-build-FE3D5490E5CF9C92416316CF44A15618 --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/Adafruit GFX Library --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/Adafruit PCD8544 Nokia 5110 LCD library --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/DualG2HighPowerMotorShield --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/SdFat --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/SerialPort --library /mnt/create-efs/webide/bc/56/bc562b2744b6180fc883d8139f02552e:bfree42/libraries_v2/SparkFun MPL3115A2 Altitude and Pressure Sensor Breakout --library /home/builder/opt/libraries/esp32_ble_arduino_1_0_1 /tmp/829461094/Bluetooth_Server_Example_fromSeeed

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:12:54: error: expected class-name before ‘{’ token

class MyCallbacks: public BLECharacteristicCallbacks {

^

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:13:18: error: ‘BLECharacteristic’ has not been declared

void onWrite(BLECharacteristic *pCharacteristic) {

^~~~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino: In member function ‘void MyCallbacks::onWrite(int*)’:

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:14:44: error: request for member ‘getValue’ in ‘* pCharacteristic’, which is of non-class type ‘int’

std::string value = pCharacteristic->getValue();

^~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:24:8: error: ‘uy777777777777fg55555’ was not declared in this scope

}uy777777777777fg55555

^~~~~~~~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino: In function ‘void setup()’:

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:31:3: error: ‘BLEDevice’ has not been declared

BLEDevice::init(“MyESP32”);

^~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:32:3: error: ‘BLEServer’ was not declared in this scope

BLEServer *pServer = BLEDevice::createServer();

^~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:32:3: note: suggested alternative: ‘Server’

BLEServer *pServer = BLEDevice::createServer();

^~~~~~~~~

Server

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:32:14: error: ‘pServer’ was not declared in this scope

BLEServer *pServer = BLEDevice::createServer();

^~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:32:14: note: suggested alternative: ‘Server’

BLEServer *pServer = BLEDevice::createServer();

^~~~~~~

Server

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:32:24: error: ‘BLEDevice’ has not been declared

BLEServer *pServer = BLEDevice::createServer();

^~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:34:3: error: ‘BLEService’ was not declared in this scope

BLEService *pService = pServer->createService(SERVICE_UUID);

^~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:34:15: error: ‘pService’ was not declared in this scope

BLEService *pService = pServer->createService(SERVICE_UUID);

^~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:34:15: note: suggested alternative: ‘Serial’

BLEService *pService = pServer->createService(SERVICE_UUID);

^~~~~~~~

Serial

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:36:3: error: ‘BLECharacteristic’ was not declared in this scope

BLECharacteristic *pCharacteristic = pService->createCharacteristic(

^~~~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:36:3: note: suggested alternative: ‘Character_h’

BLECharacteristic *pCharacteristic = pService->createCharacteristic(

^~~~~~~~~~~~~~~~~

Character_h

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:36:22: error: ‘pCharacteristic’ was not declared in this scope

BLECharacteristic *pCharacteristic = pService->createCharacteristic(

^~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:36:22: note: suggested alternative: ‘Character_h’

BLECharacteristic *pCharacteristic = pService->createCharacteristic(

^~~~~~~~~~~~~~~

Character_h

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:38:42: error: ‘BLECharacteristic’ is not a class, namespace, or enumeration

BLECharacteristic::PROPERTY_READ |

^~~~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:39:42: error: ‘BLECharacteristic’ is not a class, namespace, or enumeration

BLECharacteristic::PROPERTY_WRITE

^~~~~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:47:3: error: ‘BLEAdvertising’ was not declared in this scope

BLEAdvertising *pAdvertising = pServer->getAdvertising();

^~~~~~~~~~~~~~

/tmp/829461094/Bluetooth_Server_Example_fromSeeed/Bluetooth_Server_Example_fromSeeed.ino:47:19: error: ‘pAdvertising’ was not declared in this scope

BLEAdvertising *pAdvertising = pServer->getAdvertising();

^~~~~~~~~~~~

Error during build: exit status 1

I swapped out the example loop() for the one you sent. I’m afraid the result is no different.

‘ringbuf_type_t’ has not been declared

Multiple libraries were found for “BLEDevice.h”

Used: /home/builder/opt/libraries/arduinoble_1_3_6

Not used: /home/builder/opt/libraries/bleperipheral_0_4_0

Not used: /home/builder/opt/libraries/seeed_arduino_rpcble_1_0_0

Not used: /home/builder/opt/libraries/esp32_ble_arduino_1_0_1

Not used: /home/builder/opt/libraries/stm32duinoble_1_2_5

Not used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/BLE

Multiple libraries were found for “BLEUtils.h”

Used: /home/builder/opt/libraries/esp32_ble_arduino_1_0_1

Not used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/BLE

Error during build: exit status 1

In my environment, I get a compile error if the ArduinoBLE library is installed.

Is there a different library that should be installed? I tried commenting out the include lines but then I get this error with the code you gave me.

In my experience, “arduinoble_1_3_6” seems to conflict with the ESP32 BLE library.
Since you don’t need ArduinoBLE, why don’t you remove “/home/builder/opt/libraries/arduinoble_1_3_6”?