Skip to content

Update analogWrite doc #705

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

Merged
merged 1 commit into from
Aug 28, 2020
Merged

Update analogWrite doc #705

merged 1 commit into from
Aug 28, 2020

Conversation

stefankaters
Copy link
Contributor

You need to call pinMode() before calling analogWrite();

You need to call pinMode() before calling analogWrite();
@stefankaters stefankaters changed the title Update mistake Update analogWrite doc Sep 22, 2019
@smellai smellai requested a review from per1234 September 23, 2019 07:41
@kengdahl
Copy link
Member

If nobody objects I will merge this.

@kengdahl kengdahl merged commit 8c3300d into arduino:master Aug 28, 2020
@per1234
Copy link
Collaborator

per1234 commented Aug 28, 2020

@katerss1 @kengdahl which board did you find this was necessary for?

I know that, for Arduino AVR Boards, the previous documentation was correct:
https://github.com/arduino/ArduinoCore-avr/blob/1.8.3/cores/arduino/wiring_analog.c#L108-L111

	// writing with them.  Also, make sure the pin is in output mode
	// for consistenty with Wiring, which doesn't require a pinMode
	// call for the analog output pins.
	pinMode(pin, OUTPUT);

I haven't looked at other official boards platforms though.

@kengdahl
Copy link
Member

kengdahl commented Sep 8, 2020

@per1234
Without the pinMode(); it is not working properly on the MKR boards, i.e. SAMD architecture. So there is an inconsistency between our boards.

@kengdahl
Copy link
Member

kengdahl commented Sep 8, 2020

@per1234 did some research and:
Is it necessary to call pinMode(pin, OUTPUT) when using analogWrite()?

  • ARC32 (Arduino 101): no
  • AVR (Uno): no
  • Mbed (Nano 33 BLE): no
  • Mbed (Portenta H7 (M7 core)): no
  • Mbed (Portenta H7 (M4 core)): no
  • megaAVR (Nano Every): no
  • SAM (Due): no
  • SAMD (MKR WiFi 1010): no

The test sketch:

void setup() {
  analogWrite(3, 125);
}
void loop() {}

So all the official Arduino boards platforms behave consistently in regards to not needing to set the pin mode to OUTPUT when using analogWrite() and the documentation is fine as it is now in this regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants