• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ledcAttach won’t compile

Q&A Forum › Category: ESP32 › ledcAttach won’t compile
0 Vote Up Vote Down
Wally Harwood asked 3 months ago

I am using platformio 3,4,4
I did the migration from version 2 to version 3 and made appropriate changes. The modified program  compiled and ran fine yesterday. Now there is a problem with ledcAttach .
When doing a build  I now get :
=============================================
Compiling .pio\build\esp32doit-devkit-v1\libb6f\WiFi\WiFiAP.cpp.o
src/main.cpp: In function ‘void setup()’:
src/main.cpp:262:3: error: ‘ledcAttach’ was not declared in this scope
ledcAttach(ledPin1, freq, resolution);
^~~~~~~~~~
src/main.cpp:262:3: note: suggested alternative: ‘ledcAttachPin’
ledcAttach(ledPin1, freq, resolution);
^~~~~~~~~~
ledcAttachPin
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1
===============================
The suggested alternative is exactly what I have used.
Is something else being changed?

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 months ago

Hi.
What does your platformio.ini file look like?
Regards,
Sara

0 Vote Up Vote Down
Wally Harwood answered 3 months ago

 

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200

lib_deps =
    ESP Async WebServer
    arduino-libraries/Arduino_JSON @ 0.1.0
    adafruit/Adafruit BME280 Library @ ^2.1.0
    adafruit/Adafruit Unified Sensor @ ^1.1.4
    QMC5883LCompass.h
    mprograms/QMC5883LCompass@^1.2.3
board_build.filesystem = littlefs

; platform_packages added to enable ledc
;platform_packages=
;  framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.1
;  framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.1/esp32-arduino-libs-3.0.1.zip

++++++++++++++++++++++++++++
Platform packages are residual from  previous method of getting ledc to work with version 2. They are commented out.

0 Vote Up Vote Down
Sara Santos Staff answered 3 months ago

Hi.
Platformio doesn’t support arduino core version 3.
You need to use the old ledc functions supported by core 2.

1. Attach the pin using ledcAttachPin()

ledcAttachPin(ledPin1, channel);

ledPin1 → GPIO pin
channel → LEDC channel (0-15)
 
2. Set up the LEDC PWM channel using ledcSetup()

ledcSetup(channel, freq, resolution);

channel → LEDC channel (same as in ledcAttachPin)
freq → Frequency in Hz
resolution → Bit resolution (1-16 bits)
 
3. Write duty cycle using ledcWrite()

ledcWrite(channel, duty);

ledcWrite(channel, duty);
duty → PWM duty cycle 
 
I hope this helps.

ALTERNATIVELY, you can use the pioarduino fork: https://github.com/pioarduino/platform-espressif32
You can see the usage instructions here: https://github.com/pioarduino/platform-espressif32?tab=readme-ov-file#usage
 
Let me know if you can solve the issue.
 
Regards,
Sara
 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.