ESP32_New_ISR_Servo Library

I am working on a project to control landing gear for a drone. It has basically two positions raised and lowered. It requires a 1ms PWM pulse at 250Hz to lower, if up, and 2ms to lower, if raised. The cycle is 4ms.

At any rate, I was going to use the ESP32_New_ISR_Servo since several people have used it, but I getting errors when attempting to get the example, ESP32_New_ISR_MultiServos, to compile. Is there a different library that works for this scenario or is there a fix?

In file included from /home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.h:49,
                 from /tmp/.arduinoIDE-unsaved2024812-9018-uj8gbi.lqph/ESP32_New_ISR_MultiServos/ESP32_New_ISR_MultiServos.ino:81:
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.hpp:72:4: warning: #warning Using ESP32-based board [-Wcpp]
   72 |   #warning Using ESP32-based board
      |    ^~~~~~~
In file included from /home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_FastTimerInterrupt.h:85,
                 from /home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.hpp:108:
/home/whitemo/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.1-b6b4727c58/esp32/include/driver/deprecated/driver/timer.h:16:2: warning: #warning "legacy timer group driver is deprecated, please migrate to driver/gptimer.h" [-Wcpp]
   16 | #warning "legacy timer group driver is deprecated, please migrate to driver/gptimer.h"
      |  ^~~~~~~
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_FastTimerInterrupt.h:269:5: warning: missing initializer for member 'timer_config_t::clk_src' [-Wmissing-field-initializers]
  269 |     };
      |     ^
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_FastTimerInterrupt.h: In member function 'bool ESP32FastTimerInterrupt::setFrequency(const float&, esp32_timer_callback)':
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_FastTimerInterrupt.h:329:23: error: 'TIMER_BASE_CLK' was not declared in this scope
  329 |         _frequency  = TIMER_BASE_CLK / TIMER_DIVIDER;   //1000000;
      |                       ^~~~~~~~~~~~~~
In file included from /home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.h:50:
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h: At global scope:
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h:68:54: warning: ignoring attribute 'section (".iram1.2")' because it conflicts with previous 'section (".iram1.0")' [-Wattributes]
   68 | bool IRAM_ATTR ESP32_ISR_Servo_Handler(void * timerNo)
      |                                                      ^
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.hpp:142:23: note: previous declaration here
  142 | extern bool IRAM_ATTR ESP32_ISR_Servo_Handler(void * timerNo);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h:80:37: warning: ignoring attribute 'section (".iram1.3")' because it conflicts with previous 'section (".iram1.1")' [-Wattributes]
   80 | void IRAM_ATTR ESP32_ISR_Servo::run()
      |                                     ^
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo.hpp:169:20: note: previous declaration here
  169 |     void IRAM_ATTR run();
      |                    ^~~
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h: In member function 'void ESP32_ISR_Servo::run()':
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h:105:7: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
  105 |   if (timerCount++ >= REFRESH_INTERVAL / TIMER_INTERVAL_MICRO)
      |       ^~~~~~~~~~
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h: In member function 'int8_t ESP32_ISR_Servo::setupServo(const uint8_t&, const uint16_t&, const uint16_t&)':
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h:163:3: warning: '++' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
  163 |   numServos++;
      |   ^~~~~~~~~
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h: In member function 'void ESP32_ISR_Servo::deleteServo(const uint8_t&)':
/home/whitemo/Arduino/libraries/ESP32_New_ISR_Servo/src/ESP32_New_ISR_Servo_Impl.h:302:5: warning: '--' expression of 'volatile'-qualified type is deprecated [-Wvolatile]
  302 |     numServos--;
      |     ^~~~~~~~~

exit status 1

Compilation error: exit status 1

Does the library properties say it can be used with ab esp32? Is this a possible V3 issue (see migration doc)

I just looked and it is no longer being maintained. If it isn't broke yet, it soon will be. Find a more current library. I don;t understand why you even need it.

Thanks for the info. What would you recommend?

Just write a fuction that has the timing you mentioned for raise and lower. Maybe look at the ledc library for inspiration, but also low level servo code should work.

I tried that, but it didn't work. It may be a clocking issue, which is why was looking into using a servo library.

void landingGear::up() {
  if (_position == _LDG_DOWN) {
    if (ledcWrite(_pin, _U_PWM_DC)) {  //generates PWM of 50% duty cycle
      //Serial.print("\tGear Up");
      _position = _LDG_UP;
      delay(10);
    }
  }
}

Uh oh... Be afraid!!! Just for fun I had ChatGPT create code for the landing gear. Based on "Create arduino code for an ESP32 microcontroller to control pwm 250Hz landing gear with input from flight controller" Below is what it created.

// Include necessary libraries
#include <ESP32Servo.h> // To control the PWM output on the ESP32

// Define pins
const int flightControllerPin = 15; // Input from the flight controller
const int landingGearPin = 16;      // Output to landing gear

// Variables to store values
int flightControllerSignal = 0;
int dutyCycle = 0;
Servo landingGearServo;

// Setup function
void setup() {
  // Begin serial communication for debugging
  Serial.begin(115200);
  
  // Attach the PWM output pin to the servo object
  landingGearServo.attach(landingGearPin, 1000, 2000); // Servo PWM min and max values (1ms to 2ms pulse)
  
  // Configure the flight controller pin as input
  pinMode(flightControllerPin, INPUT);
}

void loop() {
  // Read the PWM signal from the flight controller (assuming it's between 1000-2000us pulse width)
  flightControllerSignal = pulseIn(flightControllerPin, HIGH);

  // Map the input signal to a PWM duty cycle for the landing gear
  // Assuming 1000-2000us from the flight controller corresponds to 0-100% duty cycle
  if (flightControllerSignal > 1000 && flightControllerSignal < 2000) {
    dutyCycle = map(flightControllerSignal, 1000, 2000, 0, 180);  // Mapping to servo position

    // Set the servo to the corresponding position (0-180 degrees)
    landingGearServo.write(dutyCycle);
  }
  
  // Debugging output
  Serial.print("Flight controller signal: ");
  Serial.print(flightControllerSignal);
  Serial.print(" | Landing gear position: ");
  Serial.println(dutyCycle);

  delay(20); // Short delay for stable reading
}

You don't even need to map() the flightControllerSignal value : Servo.write() considers values beyond 180 as microseconds pulse durations instead of angle values.

I haven't dug into the actual code. I was just amazed that AI could write anything vaguely useful based on a brief description. You are probably correct. AI was attempting to adjust the output for 250Hz instead of 50Hz.

Do you have a link to the landing gear you're using ? I'm surprised it requires a 250Hz output since everything else is standard servo signal...

The landing gear is from a Yuneec Typhoon H480 drone. I'm attempting to modify it to use a PixHawk FC.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.