iotappstory / ESP-Library

Software Distribution and Management Over the Air
GNU Lesser General Public License v2.1
124 stars 35 forks source link

pwm not working at GPIO14 (ESP23-WROOM-32D) #182

Closed SteffenBis closed 3 years ago

SteffenBis commented 3 years ago

I am not sure if this is really an issue with iotappstory, however I have some problems getting the pwm functionality to work on GPIO14. While trying to reproduce the issue with a smaller sketch I noticed that the problem does not occur at GPIO02 (built in LED of FireBeetle-Board V4.0 that I use). Using the attached sketch the problem occurs only at GPIO14 and with "INCLUDE_OTA_UPDATE" set to "true". There is still a timer interrupt inside the sketch - for some reason I could not get rid of it without stopping the code from working (I dont know why, but maybe this is part of the issue?). In this example I used the jled-library for convenience (as I do in the original sketch). However it does not seem that the issue is linked to the jled-library. I do not use the default partition, but "min_spiffs.csv", since I ran out of flash memory with my bigger sketch.

main.txt platformio.txt

Onno-Dirkzwager commented 3 years ago

@SteffenBis thank you for this information Ill have a look.

SteffenBis commented 3 years ago

I modified the code and got rid of the jled-library and using ledcWrite instead - this works now. So I guess it is some compatibility issue between jled and iotappstory that somehow does not affect GPIO02 but GPIO14. Modified code:

define TEST_LED 14

define INCLUDE_OTA_UPDATE true

define COMPDATE DATE TIME

define MODEBUTTON 5

include

if INCLUDE_OTA_UPDATE

include

IOTAppStory IAS(COMPDATE, MODEBUTTON);

endif

hw_timer_t * timer = NULL; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

void IRAM_ATTR onTime() { portENTER_CRITICAL_ISR(&timerMux); // set some flags portEXIT_CRITICAL_ISR(&timerMux); }

byte dutycycle;

void setup() { // for some reason the code does not run without this timer attatched (dont really understand - maybe linked to the issue?) timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTime, true); Serial.begin(115200); Serial.println("Start"); ledcSetup(0, 5000, 8); ledcAttachPin(TEST_LED, 0); }

void loop() { ledcWrite(0, dutycycle); dutycycle++; delay(5); }

Onno-Dirkzwager commented 3 years ago

@SteffenBis thank you for putting in the extra effort to find out where it goes wrong. I'll still check if there is anything we can do..... and leave this issue open as a reminder.

1JonaB1 commented 3 years ago

@SteffenBis The reason is that you cant use pin 14 PWM and WiFi at the same time (I had the same problem some time ago). Here is a thread about this issue https://github.com/espressif/arduino-esp32/issues/102 .

SteffenBis commented 3 years ago

@1JonaB1 interesting, thank you for pointing me to that thread. Over there somebody describes that ADC2 (the one for pin 14) is also unavailable if BLE is active. In my case PWM on pin 14 worked fine whith BLE running until I included the WiFi functionality. But as it seems it may be just a bad idea to use pin 14 with a fancy breathing LED while WiFi is active.

Onno-Dirkzwager commented 3 years ago

Thankyou @1JonaB1 for sharing this information. @SteffenBis I think we can close this issue now?