Dlloydev / QuickPID

A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.
MIT License
195 stars 50 forks source link

Esp32 and AnalogWrite #1

Closed halmos closed 3 years ago

halmos commented 3 years ago

I'm not able to compile my esp32 project with the QuickPID library because of the use of AnalogWrite in the autotune methods. The Esp32 platform does not support the Arduino's AnalogWrite function. Unfortunately, even tho I don't need the auto-tune capabilities, the call to AnalogWrite breaks the build and so the entire library is unusable. I'm not sure what the best workaround is, but perhaps just a simple #ifndef ESP32 around the offending code blocks could be enough? Otherwise, there is a pollyfill available, tho I haven' tested it.

Dlloydev commented 3 years ago

Thank you for your interest, feedback and suggestions. This shouldn't be too difficult to resolve ... I should be able to take a look at this sometime tomorrow.

halmos commented 3 years ago

Thanks - and thanks for the great library!

On further thought, I wonder if instead of using AnalogWrite, it might not be better to generalize the code a bit to allow for a wider range applications? For example, using a callback function parameter to allow for custom handeling of the PID output during the AutoTune might be more versatile.

In my own project, the PID output is sent to another library that controls a digital variac board. So in this case, directly writing out to a pin wouldn't work.

Thanks again for all the work you've done on this library.

Dlloydev commented 3 years ago

I think I'll order my first esp32 with LoRa. That way I could do some real testing as there's some AnalogWrite compatibility options to try. Also, I may add compatibility with some additional MCUs, but far too busy at the moment.

midcode commented 3 years ago

I have the same problem with an ESP32, would be nice if it would compile at least, right now i don't need the autotune function.

But I really like halmos idea to use callback functions for this, so autotune would work for more use cases. In my current project i can't use analogWrite or analogRead because my input is a temperature sensor which sends binary data and i have to send the output to a controller board via i2c.

Dlloydev commented 3 years ago

@midcode, thanks for your input! I'll definitely investigate adding callback functions to this. This'll be new programming territory for me, but will be an interesting challenge. I can see that having the option to use communication resources instead of analog and digital I/O pins would be beneficial for any compatible MCU.

halmos commented 3 years ago

Would you be open to a pull request on this feature? I may have to develop it in a fork for my own use anyway.

Dlloydev commented 3 years ago

EDITED Yes, that would be great ... a bit rusty on how they work though. Just now received a few ESP-WROOM-32 boards ... can't wait to one up and running! Did some research on various callback methods and PWM/AnalogWrite for ESP32 ... I guess the first step I'll do here is to get everything to compile and work with ESP32 then do an update.

Afterwards, I'll experiment with callback approaches to Autotune and PID io.

Dlloydev commented 3 years ago

New Version of QuickPID released.

Now to research using QuickPID when the transfer of Input and Output data is via communication peripherals.

Dlloydev commented 3 years ago

New version with ESP32-S2 support added. Closing this since AnalogWrite for ESP32 is completed. Will push forward with other development(s) as time permits.