-
Notifications
You must be signed in to change notification settings - Fork 7.6k
analogWrite() not implemented #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
will be when the driver is ready |
Just found some examples! The led stuff worked for me. |
Will you provide an Arduino-compatible |
Is there any news about this? It's labed as 'to be implemented' but what is the priority of this? It would really helpful to have this function so it can be compatible with some libs that use it. |
Just tried to move some code over from a ESP8266 to my shiny new ESP32 and had the same issue with analogWrite not being implemented. Will this be fixed any time soon? |
any update? Just hit this problem as well |
There are work arounds using ledC. I uploaded a example into the GitHub repo: You attached a pin to ledc, set it up, then you can call commands with ledc to update the output. |
Over two years, and no fix? Seriously? |
@Sod-Almighty different hardware. a direct equivalent implementation is impossible. There are other methods to achieve the same functionality, but they are not exactly compatible. You have to adjust your code to use either SigmaDelta or LEDC. Both work but they are not drop in. You as the programmer have to decide how to handle the differences. Chuck. |
As posted see my example. If you are programming for both say both a ESP8266 and a ESP32 you can use some if then statements to determine which to use. For example a RGB LED strip control program I have attaches the pin to use in the setup:
Then when I need to write to the output:
Although I will disagree with @stickbreaker - nothing is impossible. There has to be a way to add a wrapper for analogWrite that just does the LedC stuff for you but it doesn't look like that's going to happen. |
@vseven so, I do not see how the following Arduino Uno commands To directly translate from TCCR2B = (TCCR2B & 0b11111000) | 6; I have only used analog Write for one motor controller; a brushed 8 Amp gear motor. I had to adjust the PWM freq way down before the motor could operate. So I reconfigured the base PWM to 122hz with this TCCR2B value. This allowed me to use I believe that making a partial translation would be more of a hindrance than benefit. I know that the ESP32 is different, so to successfully set a PWM freq to 122hz I must Learn how to configure the ESP32 to achieve this goal. Chuck. |
Although I made the ledC example sketch for the ESP32 it was more of a learning thing then anything. I've never programmed a Uno controller, I've never actually used the analogWrite command for that matter. I've only used the ESP32 and then I modified my code to also support ESP8266 chips (using analogWrite) so I don't know the detailed ins and outs. I just know that for a ESP32 you have to add in the ledC PWM "channel" and tie it to your output. You can then modify the channel for your frequency and resolution. Like I said I'm just using it for relatively simple analog RGB LED control and my code works for both the ESP32 and 8266 without having to modify anything. Check out the sketch above. It might help (or not). |
@vseven Like you have experienced, the ESP32 hardware is not equivalent to the AtMega328p. So to effectively use it you have to Learn the differences and exploit them. Your example is a good reference of how to achieve a similar result. My harping that the programmer must discover/learn the ESP32 hardware to maximize his effectiveness is my hardware background showing through. Thank you for your assistance. I have not needed Chuck. |
I have just had an issue with the LiquidCrystal which wouldn't compile because it was missing the I added to Might be a quick fix for anyone wanting to use existing arduino code on their esp32 Note: This was using PlatformIO. In the arduino IDE it just worked without any special defines |
Wow, it looks like this is the oldest opened issue on espressif/arduino-esp32. |
it's a very important function ,is there anyone can rerewrite the lib? |
Hi @me-no-dev I have create a small library that provide the classic analogWrite for ESP32, please test it and give me your feedback Repository https://github.com/ERROPiX/ESP32_AnalogWrite |
Bump. |
Something to consider is making the hpoint value more accessible as this can be used to provide PWM phase shift control. Might come in handy for discrete RGB LED color mixing, and generating unique signal patterns, quadtrature signals, etc. I realize that multiple channels are not synchronized (that's a job for MCPWM) but at lower frequencies a few µs here or there becomes less important depending on the application. |
analogWrite PR Link: #5861 |
Hello all contributors of this request, AnalogWrite was already implemented based on LedC with PR #5861. This implementation has some limitation so we created a new issue #6544 and add it to our Roadmap. If you are interested you can follow newly created issue and I'm closing this one. Thanks for your patience and help. |
Thank you very much! This is actually all i've needed. At least some basic functionality. Because i only use arduino API for some simple things and preliminary hardware tests. For anything serious i prefer to use espressif API directly anyway.... |
@Harvie We are glad that this basic functionality works for you. If you are interested, feel free to comment newly created issue for full implementation. |
does analogWrite() now finally truly work like the Arduino API implementation both
ref.: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/ |
thanks, but then I don't see what has been implemented actually and what not, tbh... |
I would say that this issue should not be closed until users can at least run the included Fade.ino sketch that comes with the IDE. |
Hola. I have updated Arduino IDE from 1.8.xx to 2.0.0 and analogWrite on ESP32 dont not work anymore. before was.. :x |
The IDE does not control those features. Which core version did you install? |
ignore any localized idf
by chance I found this Arduino lib: will it work with all ESP32 repo versions? has anyone checked it? |
@dsyleixa have you tried the thing merged 3 years ago? https://github.com/espressif/arduino-esp32/pull/5861/files |
I do not know that - where is the example code? |
No description provided.
The text was updated successfully, but these errors were encountered: