• 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

Fix required in Smart Home v1.5, Module 11 “ESP32_cam_webserver” project, file “app_httpd.cpp” when using Platform IO

Q&A Forum › Category: ESP32 › Fix required in Smart Home v1.5, Module 11 “ESP32_cam_webserver” project, file “app_httpd.cpp” when using Platform IO
0 Vote Up Vote Down
Bruce Develle asked 6 months ago

A code fix is required when importing an Arduino example into PlatformIO.
I was starting to convert from Arduino IDE to Platform IO on VSCode. I wanted to use the last project that I did as a first example to try out Platform IO. This project was the ESP32 CameraWebServer example discussed in the Smart Home v1.5 ebook in Module 11, and located in the Arduino IDE examples.  Compiling and uploading this example project using the Arduino IDE works fine, but I wanted to do this in Platform IO, so I copied all the source files (CameraWebServer.ino, app_httpd.cpp, camera_index.h, Camera_pins.h, ci.json) from the Arduino IDE to a new project folder. I then went to VS code -> PlatformIO Home -> Import Arduino Project. I also elected NOT to use Arduino libraries when importing, because I want to run VS Code/PlatformIO independent of Arduino IDE.
Before compiling the code I noticed the following error flagged in VS Code:

In the file ‘app_httpd.cpp‘ in the very last lines of the code (lines 1321 to 1327) inside the function ‘setupLedFlash‘ the call to ledcAttach(pin, 5000, 8); is flagged as an error because there is no identifier ‘ledcAttach‘ referenced anywhere (see screenshot https://drive.google.com/file/d/1wgQHlPp_yQ_oZ1B5PgwdzVQ5-fL24EJW/view?usp=sharing ).
Upon compiling, VS Code catches the error and suggests using the function ‘ledcAttachPin‘ ( see screenshot https://drive.google.com/file/d/1_WjzDjcpgdC4GMa_cgc5tKzgJ434-Ewa/view?usp=sharing ).
But the definition of ledcAttachPin is

void ledcAttachPin(uint8_t pin, uint8_t chan)

So I changed the function to ledcAttachPin, but since it is only using two int variables, ‘pin‘ and ‘chan‘ I deleted the ‘5000‘ argument from the function call and recompiled. The compilation was successful after this change.
ledcAttachPin is found in the PlatformIO library ‘esp32-hal-ledc.c‘.
ledcAttach is found in the Arduino ESP32 library ‘esp32-hal-ledc.c’.
It’s definition is:

bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) {

  int free_channel = ~ledc_handle.used_channels & (ledc_handle.used_channels + 1);
  if (free_channel == 0) {
    log_e(“No more LEDC channels available! (maximum is %u channels)”, LEDC_CHANNELS);
    return false;
  }
  uint8_t channel = __builtin_ctz(free_channel);  // Convert the free_channel bit to channel number

  return ledcAttachChannel(pin, freq, resolution, channel);
}

So these two libraries are different between Arduino and PlatformIO, and the functionality of the freq variable must be accounted for.

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 months ago

Hi.
Thanks for sharing.
You’re probably running an older version of the ESP32 core on PlaformIO.
The ledcAttachPin() was supported on version 2 of the ESP32 core, but no longer on version 3.
ledcAttach is only supported on version 3.
 
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.