You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
analogWrite is not compliant with standard Arduino API #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 standard analogWriteResolution() should be implemented to set the resolution to 10bit (and/or what ever else it can support).
(
I somewhat agree that it's not 100% compliant, or should be documented better.
I once thought it was my mosfets not working as good on 3.3V since it did work with an Arduino.
But I had to scale the PWM to work with the ESP8266's range and now it works like a treat.
)
@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.
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 analogWrite() to be 8 bit.
Here is one example where they are confused that analogWrite(pin, 255); doesn't act the same as digitalWrite(pin, HIGH);.
On chipKIT we default to 8 bit and give analogWriteResolution() to change it to higher resolutions. We also provide the (non-standard, though very useful) analogWriteFrequency() function to change the fundamental frequency of the PWM - great for motor driving at 25kHz.
Activity
mAPBhlJ commentedon Jan 24, 2017
#295
Use the defined PWMRANGE.
You could then go along and calibrate it accordingly: https://www.arduino.cc/en/Tutorial/Calibration
(
I somewhat agree that it's not 100% compliant, or should be documented better.
I once thought it was my mosfets not working as good on 3.3V since it did work with an Arduino.
But I had to scale the PWM to work with the ESP8266's range and now it works like a treat.
)
devyte commentedon Sep 9, 2017
@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.
igrr commentedon Sep 9, 2017
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.
Makuna commentedon Sep 9, 2017
@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).
igrr commentedon Sep 10, 2017
@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.
devyte commentedon Oct 4, 2017
@Makuna will you be providing the requested info?
Makuna commentedon Oct 4, 2017
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.
majenkotech commentedon Nov 11, 2018
It is confusing for an Arduino user that expects
analogWrite()to be 8 bit.analogWrite(pin, 255);doesn't act the same asdigitalWrite(pin, HIGH);.On chipKIT we default to 8 bit and give
analogWriteResolution()to change it to higher resolutions. We also provide the (non-standard, though very useful)analogWriteFrequency()function to change the fundamental frequency of the PWM - great for motor driving at 25kHz.BREAKING - analogWriteRange 8-bit default
BREAKING - analogWriteRange 8-bit default (#7456)