Servo only works from Arduino IDE (ESP32 Super Mini C3)

Hi everyone,

I’m running into an issue where a very simple servo test sketch works perfectly when uploaded from the Arduino IDE, but the exact same code doesn’t work when built and uploaded with PlatformIO in VS Code.

Here’s the sketch:

#include <ESP32Servo.h>

Servo myServo;

void setup() {
    myServo.attach(7);
}

void loop() {
    myServo.write(106);
}

When I upload this using the Arduino IDE, the servo moves as expected.
However, when I upload it through PlatformIO, the servo does not move at all.

Here’s what I’ve tried in platformio.ini:

;SERVO DOES NOT MOVE
;[env:esp32-c3-devkitm-1]
;platform = espressif32
;board = esp32-c3-devkitm-1
;framework = arduino
;lib_deps = madhephaestus/ESP32Servo@^3.0.8

;SERVO DOES NOT MOVE
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
board_build.mcu = esp32c3
board_build.f_cpu = 160000000L
framework = arduino
lib_deps = 
    madhephaestus/ESP32Servo@^3.0.8
monitor_speed = 115200
build_flags = 
    -D ARDUINO_USB_MODE=1
    -D ARDUINO_USB_CDC_ON_BOOT=1
    -D ARDUINO_ESP32C3_DEV=1
    -D CONFIG_DISABLE_HAL_LOCKS=1
    -D ESP32_C3=1
    -D BOARD_HAS_PSRAM
    -D ARDUINO_FLASH_MODE_QIO=1
    -D ARDUINO_FLASH_FREQUENCY=80
    -D ARDUINO_PARTITION_DEFAULT_4MB=1
upload_speed = 921600

My question is:
What am I missing in the PlatformIO setup that prevents this exact same code from working, even though it runs fine from the Arduino IDE?

Thanks in advance!

Duplicate of How to run servo on ESP32 with PlatformIO

The readme of the library states:

Specifically for the V3.0.0 of Arduino ESP32. All ADC’s have been updated to work correctly with the new release

But using

platform = espressif32

will give you Arduino Framework 2.0.17.

To get the newer Arduino Framework 3.x you have to use the community fork pioarduino of the Espressif32 platform:

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

If you want to pick a specific Arduino Framework version, check this list.

Thanks a lot, I tried a few random versions as the platform but never actually tried the git link :man_facepalming: