Dlloydev / ESP32-ESP32S2-AnalogWrite

ESP32 PWM, Servo, Easing and Tone. Smart GPIO pin management and advanced control features.
MIT License
100 stars 17 forks source link

Need to cycle power after an OTA update #13

Closed nophead closed 3 years ago

nophead commented 3 years ago

For a simple 8 bit 20KHz fan PWM on pin 22 of a DOIT ESP32 DEVKIT V1 :

In setup() I have:

  analogWrite(FAN, 0, 20000, 8); 

In loop()I have:

  fan_pwm =  ... // a function of temperature
  analogWrite(FAN, fan_pwm);

This works as expected but if I do an over the air update the PWM value gets stuck until I cycle the power and then it works again.

Do I need to do something in the OTA code to stop the PWM or reinitialise it?

Dlloydev commented 3 years ago

I haven't used the basic OTA update or web updater yet, but it looks interesting. Therefore, I don't have any suggestions at this time regarding what can be done in the OTA code.

Note that with this library, its not really necessary to configure the PWM pin in setup. It will self-configure the pin with whatever parameters you specify on the first iteration, then only apply anything that changes in subsequent loop iterations. Therefore, you could skip the setup and just use analogWrite(FAN, fan_pwm, 20000, 8); in the loop. Perhaps this would work.

nophead commented 3 years ago

No that still doesn't work. I guess the variables in RAM all get cleared when the program restarts but perhaps the hardware doesn't, so things get out of step.

nophead commented 3 years ago

Passing a value of -1 to detach the pin in ArduinoOTA.onStart() fixes the issue.