ESP32servo library gives compiling errors with board nano ESP32

Hi all,
I'm trying to read a servo input using library ESP32servo. Up to now, it has been done with the ESP32 WEMOS LOLIN32 board using this library but now i'm trying to use the nano ESP32 received a week ago to test if it's compatible and it doesn't compile showing errors.

A minimal example code to reproduce this error can be taken opening a blank new sketch from Arduino Editor and including only the library at the beginning "#include <ESP32Servo.h>"...

  • If ESP32 board WEMOS LOLIN32 is selected , no errors are given when compiled.

  • If Arduino nano ESP32 is selected, selection, following message is given:
    "...ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given
    void tone(int pin,unsigned int frequency);"

Could be a error but my asumption is that the libraries should be reviewed for this new Arduino board nano ESP32.

Has anyone had the same problem? how is it solved?

Thanks in advance.

Hi @GALILEO

Yes, it was previously reported here:

Instructions are provided here:


Please let me know if you have any questions or problems while following those instructions.

Hi @ptillisch,

I saw that problem, before writing this post, and it doesn't solve anything related with described problem.

1- As explained, with an empty sketch (no code inside setup() and Loop()), if the inclusion of the ESPservo.h header is the only thing done, the problem arises by itself after compile.
2- Let me tell you that yesterday I also did the suggested solution by replacing the "#define tone(..." in the "io_pin_remap.h" and in this case, it gives other problems related to analogWrite and more. You can try it yourself.

I must say that the problem with this library is only when using the Arduino nano ESP32 board. With ESP32 WEMOS LOLIN32 I have no problems.

Thanks for your comment.

Hello @GALILEO and thanks for spotting this.
The Nano ESP32 board is fairly new and contains new code related to pin naming (the digitalPinToGPIONumber stuff), and not every library has been updated to support it. In particular, this ESP32Servo 0.13.0 library suffers from very similar errors than the ones @ptillisch referenced.
The issue is more complex here, however, as the library provides its own re-implementation of some core Arduino functions. In this case, the library will need to be slightly adapted.

To fix this you should:

  • apply the tone() fix in my previous post
  • locate your own copy of the ESP32Servo library source (found in your sketchbook libraries/ESP32Servo/src folder)
  • edit the 4 files analogWrite (.cpp and .h) and ESP32Tone (.cpp and .h) replacing all mentions of analogWrite, tone, and noTone with (analogWrite), (tone), and (noTone).

For example, the line

void analogWrite( uint8_t APin, uint16_t AValue );

has to be changed to

void (analogWrite)( uint8_t APin, uint16_t AValue );

There should be 1 match in each analogWrite file and 3 matches in each ESP32Tone file.

I will submit this to the library authors for review and inclusion in a future version of the library.

Hi @lburelli,
:clap: :+1:
The proposal solves the problem of the basic example explained (only by including the ESP32servo library header in an empty sketch). Once this problem is solved I will continue with the migration of my application code to see if everything works on this new board.

Thank you very much for your help.

1 Like

Thanks, but it seems I was a little bit optimistic. The above only fixed the compile-time issues, but I see from source and examples that it is more difficult to properly implement the pin-naming fix due to how the library reuses Arduino function names for its own implementation.

Sorry, I don't think this library is currently compatible with the Nano ESP32.We will discuss how to best support this situation in upcoming releases.

I hope it gets solved as quickly as possible because it's the only way, at least for me, that I have when using the ESP32 board type, to be able to read a PWM servo input and get the period in microseconds similar to when libraries of "Servo.h" or "ServoInput.h" are used for AVR or other board types.

I hope soon good news, greetings and thanks for your support.

1 Like

Is there any news about it to solve the problem?
Regards to Forum.

Hi @GALILEO. Have you tried it again with the latest version of the "Arduino ESP32 Boards" platform? The library is working fine for me now so I think it is fixed.

Please give it a try and then let us know if you still have problems.

Hi @ptillisch,
Following your recomendation, in Board Manager I upgraded "Arduino ESP Boards" type to latest version at this moment (2.0.13).
After a compile, lot of errors remains present regarding to analogWrite, Tone and noTone (pin remap file and expansion macros).

After that, also the ESP32Servo library was upgraded too latest version (1.1.0) and after compiling,... "voila", no errors has been collected.

The compilation of the basic file explained at the beginning to be able to reproduce the error, and after that, with my project too has been OK.

Note: Maybe that only the upgrade of the library corrects the past problems but, anyway, it's OK.

Many thanks for your support and help!

I didn't investigate the actual source of the now functional state of the library before making my previous reply, but I see now that you are correct.

The fix was introduced by this commit:

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