'ledcSetup' was not declared in this scope

  • ESP32 core 3.x

You may see

error: 'ledcSetup' was not declared in this scope
error: 'ledcAttachPin' was not declared in this scope; did you mean 'ledcAttach'?

Why it happens

  • The code was written for ESP32 core 2.x and you have 3.x, where ledcSetup and ledcAttachPin were removed.

How to fix it

  1. Change ledcSetup(channel, freq, bits); and ledcAttachPin(pin, channel); to one line: ledcAttach(pin, freq, bits);.
  2. Change ledcWrite(channel, value) to ledcWrite(pin, value).
  3. Or install ESP32 core 2.0.17 in the Boards Manager and keep the code as it is.

It worked if: Verify passes and the LED fades.

Seen in a real run (some lines are close variants of it). Produced with Arduino CLI 1.5.1 and ESP32 core 3.1.3. Sources: Arduino ESP32: moving from 2.x to 3.0.

Didn't help? Search another error or ask us.