I bought an arduino nano esp32 to get started and am currently trying ble programming.
Initially I tried to build a bluetooth connection with the code called LED and also EnhancedAdvertising from the arduino ble libary to have a code base.
Of course I also used the recommended apps for ble (nRF Connect or Lightblue). Unfortunately, nothing is found by the smartphone. Uploading the code didn't cause any problems either.
Previous programmes such as button-controlled led traffic lights also worked great, but somehow ble doesn't want to be displayed. Unfortunately there is not much information about the nano esp 32 as it is still quite new and I couldn't really find much on the net.
I now found my "mistake". The code example under ESP32 BLE Arduino -> BLE_server works. But just when the arduino ble libary is deinstalled. Seems like the ble libary wont work on the nano esp32. I tried it before with the code examples from the arduino ble libary, like the led example. So if there is trouble with the libary the rest cant work either.
I tested this example using the BLE library on Linux and Windows, and on Linux everything works as expected. I did run into some issues on Windows that seem related to the timing and initialization of the serial communication. We are currently looking into it.
Can you try uploading the example I linked above and open the serial port with something that is not the IDE? (e.g. Putty)
Now that I've connected Putty, everything works fine. Could be because in the code, the serial is sort of an indicator for the rest. Unfortunately, I just realized it now. Better late than never. For my excuse, I just heard about the serial connection. No one in the tutorials I watched before ever used it.
But I noticed two things that make me wonder if they work right.
The script runs even when the serial connection is closed (is that intended?)
and the ESP32 BLE Arduino Example named BLE_server won't install if the Arduino BLE library is installed. The error says that multiple libraries for BLEDevice.h were found. Exit status 1 and Compilation error: 'init' is not a member of 'BLEDevice'. Which don't appear when the Arduino BLE library is not installed.
Hello,
Where should the libraries be? I found the library in a folder called "Hardware" and also on other places. Confusing... and the complier complains.
Regards, André
Hi @andre_alm10. I'll provide instructions you can follow to uninstall the "ArduinoBLE" library:
Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
Type ArduinoBLE in the "Filter your search..." field.
Scroll down through the list of libraries until you see the "ArduinoBLE" entry.
Hover the mouse pointer over the "ArduinoBLE" entry.
You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
A context menu will open.
Select "Remove" from the context menu.
An "Uninstall" dialog will open.
If you don't see a "Remove" item in the menu, that means you never had the "ArduinoBLE" library installed in the first place and you can stop following these instructions.
Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
The dialog will close.
Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:
Hello, I'm trying to compile BLE_server and when I have the ArduinoBLE library installed the compiler complains "Multiple libraries were found for "BLEUtils.h" " and "Multiple libraries were found for "BLEDevice.h" ". And also " Compilation error: 'init' is not a member of 'BLEDevice'" . If I remove the ArduinoBLE library it only complains "Multiple libraries were found for "BLEDevice.h" ".
I wonder if I'm using the latest libraries and code.
Inspect the lines that follow this message. It will show the list of the libraries that contain a header file of that name.
The first item in the list, which is prefixed with "Used:", is the library that was chosen for compilation by the Arduino sketch build system.
The subsequent items in the list, which are prefixed with "Not used:", are the other candidate libraries that were not compiled.
As long as the build system chose the intended library, you can safely ignore the message. The presence of multiple candidate libraries won't cause any harm in this case. The build system uses a sophisticated algorithm to decide which library is "best" so it does usually get it right.
If you suspect that a different library than intended was chosen, let us know and we'll provide guidance for influencing the build system to choose the right library.
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
Ported to Arduino ESP32 by Evandro Copercini
updates by chegewara
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("Long name works now");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setValue("Hello World says Neil");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
I investigated and found that this is a case where the Arduino sketch build system chose the wrong library. Your code is written for use with the "BLE" library that comes bundled with the "Arduino ESP32 Boards" platform installation. But when you have the "ArduinoBLE" library installed, the build system uses that library instead, which results in the compilation error.
As mentioned previously in this thread, the most simple solution is to uninstall the "ArduinoBLE" library. However, that is not a good solution if you are using the "ArduinoBLE" library in other project (as I suspect you are doing from some of your other posts).
In this case the solution is to influence the sketch build system to pick the intended "BLE" library instead of "ArduinoBLE". We can do that by adding an #include directive to the sketch for a header file that is unique to the "BLE" library. This #include directive must be placed above the ambiguous #include directives. The first #include directive forces the build system to choose the "BLE" library, after which it will also use that library when processing the subsequent #include directives.
I arbitrarily chose the library's header file named BLEEddystoneTLM.h as a suitable candidate for this purpose. So add this line to the top of the sketch:
#include <BLEEddystoneTLM.h>
After that compile the sketch again. Hopefully this time it will be successful.
In file included from /Users/andrealm/Documents/Arduino/libraries/ESP32_BLE_Arduino/src/BLEAdvertising.h:15,
from /Users/andrealm/Documents/Arduino/libraries/ESP32_BLE_Arduino/src/BLEServer.h:19,
from /Users/andrealm/Documents/Arduino/libraries/ESP32_BLE_Arduino/src/BLEDevice.h:18,
from /Users/andrealm/Documents/Arduino/BLE_server_rest/BLE_server_rest.ino:7:
/Users/andrealm/Documents/Arduino/libraries/ESP32_BLE_Arduino/src/FreeRTOS.h:61:28: error: 'ringbuf_type_t' has not been declared
Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
^~~~~~~~~~~~~~
Multiple libraries were found for "BLEEddystoneTLM.h"
Used: /Users/andrealm/Documents/Arduino/libraries/ESP32_BLE_Arduino
Not used: /Users/andrealm/Library/Arduino15/packages/arduino/hardware/esp32/2.0.13/libraries/BLE
exit status 1
Compilation error: exit status 1
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
Ported to Arduino ESP32 by Evandro Copercini
updates by chegewara
*/
#include <BLEEddystoneTLM.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("Long name works now");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setValue("Hello World says Neil");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
A solution I have used is to modify the Arduino BLE library properties to not include the esp32 in the architectures.
This change is overwritten with library version upgrades.
Modify this file to remove the esp32.
name=ArduinoBLE
version=1.3.6
author=Arduino
maintainer=Arduino <info@arduino.cc>
sentence=Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, Arduino Nano 33 BLE, Nicla Sense ME and UNO R4 WiFi.
paragraph=This library supports creating a Bluetooth® Low Energy peripheral & central mode.
category=Communication
url=https://www.arduino.cc/en/Reference/ArduinoBLE
architectures=samd,megaavr,mbed,apollo3,mbed_nano,mbed_portenta,mbed_nicla,esp32,mbed_giga,renesas,renesas_portenta,mbed_opta,renesas_uno
includes=ArduinoBLE.h
This repository is kept for archive. BLE code is now included in Arduino directly.
What they mean by "included in Arduino directly" is that the developers of the "esp32" boards platform decided to bundle this library with the platform installation. This means that there is no reason to install the standalone version of the "ESP32 BLE Arduino" library as you have done. The "ESP32 BLE Arduino" library is no longer maintained so you end up with an outdated version of the library that may not be compatible with the modern version of the "esp32" boards platform.
So in this case the best solution will be to simply uninstall the "ESP32 BLE Arduino" library. I'll provide instructions you can follow to do that:
Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
Type ESP32 BLE Arduino in the "Filter your search..." field.
Scroll down through the list of libraries until you see the "ESP32 BLE Arduino" entry.
Hover the mouse pointer over the "ESP32 BLE Arduino" entry.
You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
A context menu will open.
Select "Remove" from the context menu.
An "Uninstall" dialog will open.
Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
The dialog will close.
Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:
ⓘ Successfully uninstalled library ...
After you have done that, try compiling your sketch again. Hopefully this time it will compile without any errors.
Hi Per,
Now that I have uploaded the code to Nano ESP32 what will happen? I cannot see the device with the LightBlue app or under Bluetooth setting on Mac OS.
Should it show up like a device?