ArduinoBLE: Connecting to a peripheral works with ArduinoIDE but not with PlatformioIDE

Hi!, I’m new to PlatformioIDE and i was converting my Arduino project, using the ArduinoBLE library, for a BLE central device into a Platformio one, the only issue is that the actual BLE connection between my central arduino and my other arduino peripheral, won’t work on PlatformioIDE while on ArduinoIDE it does. I’m using the same code for both cases, here is the code:

#include <Arduino.h>
#include <ArduinoBLE.h>

BLEDevice device;
bool is_device_connected = false;
String uuid = "my-service-uuid";

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        continue;
    Serial.println("Serial beginned!");

    while (!BLE.begin())
        continue;
    Serial.println("BLE beginned!");

    while (!is_device_connected)
    {
        while (!BLE.scanForUuid(uuid))
            continue;

        device = BLE.available();

        if (device)
        {
            Serial.println("Service found, connecting to device");

            if (device.connect())
                is_device_connected = true;
            else
                is_device_connected = false;
        }
        else
        {
            Serial.println("No advertised service was found with this UUID");
        }
        delay(1000);
    }
}

void loop()
{
    BLE.poll();
    device.poll();
    Serial.print(".");
}

And this is my current platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 115200
board_build.f_cpu = 240000000L
board_build.flash_mode = qio
board_build.f_flash = 80000000L
board_build.flash_size = 4MB
upload_port = COM5
lib_deps = 
    arduino-libraries/ArduinoBLE@^1.4.0

The boards I’m using:

  • CHEAP YELLOW DISPLAY JC2432W328 as an ESP32 DEV MODULE (Central)
  • ESP32 DEVKIT V1 as a DOIT ESP32 DEVKIT V1 (Peripheral)

As suggested by Gemini I tried also:

  • specifying “platform = espressif32@3.2.1” (same as the one used in arduino) in the platformio.ini, as a result it gave me an error with the ArduinoBLE library saying there was a file “freertos/stream_buffer.h” not found
  • adding the following settings (settings shown below) used by arduino in the platformio.ini, it compiles with no errors but nothing changes
upload_speed = 115200
board_build.f_cpu = 240000000L
board_build.flash_mode = qio
board_build.f_flash = 80000000L
board_build.flash_size = 4MB
upload_port = COM5

Here is what the serial monitor shows:

Serial beginned!
BLE beginned!
No advertised service was found with this UUID
Service found, connecting to device
Service found, connecting to device
No advertised service was found with this UUID
Service found, connecting to device
Service found, connecting to device
Service found, connecting to device
No advertised service was found with this UUID
Service found, connecting to device
Service found, connecting to device
Service found, connecting to device
Service found, connecting to device
No advertised service was found with this UUID
Service found, connecting to device
Service found, connecting to device
Service found, connecting to device
No advertised service was found with this UUID
Service found, connecting to device
...etc...

So thanks in advance for any feedback, and also sorry for bad english…

In the Arduino IDE’s board manager, what version of “esp32” do you have installed? The 3.x or 2.x version?

The latest version, 3.2.1

Then you need to change the platform = ... value to one pioarduino suggests, otherwise you will be compiling against Arduino-ESP32 2.x.

Soo, yesterday I tried what you told me, so now my platformio.ini have the platform flag set to this:

platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip 

After this, I tried running the build, but with no success, the error that i got (that I also forgot to copy) had a link redirecting me to a Platformio troubleshooting page, so i tried solution 3, rerunned the build from terminal but it gave me the same issue as on vscode.

Today I runned the build another time, and this is what i got:

Processing esp32dev (platform: https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip; board: esp32dev; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Timeout in idf_tools.py after 300s
Timeout in idf_tools.py after 300s
Verbose mode can be enabled via `-v, --verbose` option
Timeout in idf_tools.py after 300s
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (55.3.30) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - contrib-piohome @ 3.4.4
 - framework-arduinoespressif32 @ 3.3.0
 - framework-arduinoespressif32-libs @ 5.5.0+sha.b66b5448e0
 - tool-dfuutil-arduino @ 1.11.0
 - tool-esptoolpy @ 5.0.1
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 3.2.0
 - tool-mklittlefs4 @ 4.0.2
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa-esp-elf @ 14.2.0+20241119
*** Applied include path shortening for 290 framework paths ***
*** Path length reduced from 33565 to ~11617 characters ***
*** Estimated savings: 21460 characters ***
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 42 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoBLE @ 1.4.0
Building in release mode
Compiling .pio\build\esp32dev\lib236\ArduinoBLE\BLEAdvertisingData.cpp.o
Compiling .pio\build\esp32dev\lib236\ArduinoBLE\BLECharacteristic.cpp.o
"xtensa-esp32-elf-g++" not recognized as an internal or external command,
 an executable program or a batch file.
Compiling .pio\build\esp32dev\lib236\ArduinoBLE\BLEDescriptor.cpp.o
*** [.pio\build\esp32dev\lib236\ArduinoBLE\BLEAdvertisingData.cpp.o] Error 1
"xtensa-esp32-elf-g++" not recognized as an internal or external command,
 an executable program or a batch file.
*** [.pio\build\esp32dev\lib236\ArduinoBLE\BLECharacteristic.cpp.o] Error 1
"xtensa-esp32-elf-g++" not recognized as an internal or external command,
 an executable program or a batch file.
*** [.pio\build\esp32dev\lib236\ArduinoBLE\BLEDescriptor.cpp.o] Error 1
================================================================================ [FAILED] Took 911.01 seconds ================================================================================

After this i installed ESP-IDF tools on my pc, but still, no luck, same error, so now i don’t really know what else to try

No, something in the installation went wrong. Try removing the entire C:\Users\<user>\.platformio folder and restart VSCode. Let it reinstall itself fully and then build again.

It works now! Thanks for the help, I have to admit that I’m a bit embarassed that i didn’t had tried this myself. However, I also uninstalled esp-idf tools now, I guess it wasn’t necessary to install them in the first place.
I guess the initial problem was simply my bad internet connection, because this time I tried switching it and everything works fine.

edit:
Just to try, I’ve just switched the “platform” flag back to platform = espressif32 and it also works, so I think the problem here was only my installation…

If you do not set a specific version, the version with the highest version number that is already installed will be used, which in this case is the pioarduino espressif32 platform.

So this means that even if I specified espressif32 as the platform, I’m using the same platform as the one suggeted in the pioarduino repository?

Take a look at the output during the build:

PLATFORM: Espressif 32 (55.3.30) > Espressif ESP32 Dev Module

Given a complete fresh PlatformIO setup - no platform installed yet.
The platformio.ini has platform = espressif32.
During the first build process, platformio will download the latest available official espressif32 platform (which currently is 6.11.0 / Arduino 2.0.17)

Now you change the platform setting to

platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip

This will download the latest available pioarduino espressif32 platform, which currently is 55.3.30 / Arduino 3.3.0)

Now you change the platform setting back to

platform = espressif32

The highest installed version will be used (55.3.30 > 6.11.0)

1 Like

This makes sense now, thank you for your patience