I’m trying to learn to control my FS90R servo with ESP32-WROOM-32UE
and PlatformIO. I’ve connected the servo to board ground, board 5v and signal to pin 14.
Here is my config:
[env:esp32]
platform = espressif32@6.5.0
board = esp32dev
framework = arduino
lib_deps =
ESP32Servo
upload_port = /dev/ttyUSB0
monitor_speed = 115200
And here is the code:
#include <ESP32Servo.h>
static const int servoPin = 14;
Servo servo1;
int res = -99;
void setup() {
Serial.begin(115200);
delay(1000);
ESP32PWM::allocateTimer(0);
servo1.setPeriodHertz(50); // Standard 50Hz servo
res = servo1.attach(servoPin, 1000, 2000);
servo1.write(0);
}
void loop() {
Serial.println("attach result");
Serial.println(res);
servo1.writeMicroseconds(1000);
delay(3000);
servo1.writeMicroseconds(2000);
delay(3000);
}
After I upload it to the board run --target upload
I can see next logs and serial output, but the servo doesn’t move at all.
================================== [SUCCESS] Took 6.96 seconds ==================================
[3/3] Starting serial monitor... (Press Ctrl+C to exit)
--- Terminal on /dev/ttyUSB0 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
[ 1016][W][ESP32Servo.cpp:84] attach(): [ESP32Servo] Attempting to Attach servo on pin=14 min=1000 max=2000
[ 1027][W][ESP32PWM.cpp:339] attachPin(): [ESP32PWM] Pin Setup 14 with code 50
[ 1034][W][ESP32Servo.cpp:134] attach(): [ESP32Servo] Success to Attach servo : 14 on PWM 0
attach result
0
On the other hand, the same code runs as expected after I uploaded it via Arduino IDE. On Arduino IDE side I picked ESP32-WROOM-DA
as most similar board.
I see a nice square signal on oscilloscope for arduino based build and a total mess for PlatformIO on pin 14.
Any help appreciated.