-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
analogWrite is not compliant with standard Arduino API #2895
Comments
Use the defined PWMRANGE. You could then go along and calibrate it accordingly: https://www.arduino.cc/en/Tutorial/Calibration ( I once thought it was my mosfets not working as good on 3.3V since it did work with an Arduino. |
@igrr is this something that we want to do? I really don't like defaulting to 8bits and having to change to 10bits with a function call, it would break who know what out there, but the request has a point about compatibility with Arduino. |
Maybe put this under "major breaking changes for new major release" category (i.e. if/when we bump the version to 3.0). I agree that this should be made Arduino compatible, at some point. |
@devyte It currently is breaking stuff all over the place. Several libraries don't work out of the box with esp8266 due to this (internally they use analog write). |
@Makuna can you mention some of these libraries? As in, it would probably take ~15min per library to send a PR to take PWMRANGE into account. That would be a reasonable short term solution, I think. |
@Makuna will you be providing the requested info? |
The library issues came up in a maker class I was teaching where students applied specifics from their projects. We discovered the issues with several, but I don't have the links to them sorry. They were not Esp8266 libraries, they were for standard Arduino projects sort of thing that we were porting to esp8266. I just want to make sure its clear, the PWMRANGE is not an Arduino standard, and currently the AnalogWrite work is not Arduino compliant as it sits. If its not a priority to fix, then at least leave this issue open so others can get a good search hit as how they can work around it. |
It is confusing for an Arduino user that expects
On chipKIT we default to 8 bit and give |
Matching standard Arduino cores, make the default analogWrite() take values from 0...255. Users can always use the analogWriteRange() call to change to a different setup. Fixes esp8266#2895
Matching standard Arduino cores, make the default analogWrite() take values from 0...255. Users can always use the analogWriteRange() call to change to a different setup. Add a `analogWriteResolution` which takes a number of bits and sets the range from 0...(1<<bits)-1, part of the standard Arduino API. Remove the PWMRANGE define. It's non-standard and not generally valid (i.e. it's fixed at 1024 of 256, but the real range varies depending on what you last set). Also add note about the change and how to fix pre 3.0 applications. Fixes #2895
The standard Arduino API
analogWrite()
takes a value from 0-254. The Esp Arduino version defaults to a 10 bit value. This makes code incompatible between all other Hardware and leads to confusion on the part of users.analogWrite()
should be modified to default to 8bit and the standardanalogWriteResolution()
should be implemented to set the resolution to 10bit (and/or what ever else it can support).The text was updated successfully, but these errors were encountered: