Skip to content
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

digitalRead() interferes with analogRead() #993

ScruffR opened this issue May 5, 2016 · 2 comments · Fixed by #1006


Copy link

commented May 5, 2016

Based on my understanding of the implementation of analogRead() and confirmed by Brett ( @technobly ) in this post I suggested to a member that it is possible to set a pinMode(analogPin, INPUT_PULLUP) in order to use digitalRead(analogPin) and a subsequent call to analogRead(analogPin) would still work.

But it doesn't!
Setting the pinMode() is OK, but once you use digitalRead() once _after_ calling analogRead() kills any subsequent calls to analogRead().

// tested on Photon with v0.5.0
#define aPIN A0
#define INTERFERE_ONCE  true
#define INTERFERE_MULTI false

void setup()
  pinMode(D7, OUTPUT);
  pinMode(aPIN, INPUT_PULLUP);  // set this once as default state for the pin

void loop()
  int b;
    b = digitalRead(aPIN);
    digitalWrite(D7, b);

  // aPIN should still be set as INPUT_PULLUP
  Serial.println(analogRead(aPIN));  // will be temporarily changed to AN_INPUT
  // and now should be back to INPUT_PULLUP for next time round


Hence I already proposed back in February this


  • Minimum test case added
  • Device, system and user firmware versions stated
  • Particle confirmed

This comment has been minimized.

Copy link
Contributor Author

commented May 18, 2016

No confirmation of this issue yet?

@avtolstoy avtolstoy referenced this issue May 22, 2016
7 of 7 tasks complete

This comment has been minimized.

Copy link

commented May 22, 2016

Issue confirmed and fixed in #1006. DAC pins may also be affected by the issue under certain conditions.

m-mcgowan added a commit that referenced this issue Jun 10, 2016
m-mcgowan added a commit that referenced this issue Jun 10, 2016
digitalRead()/analogRead() interference (#1006)
* Save PinMode in STM32_PIN_MAP.user_property (HAL_GPIO_Save_Pin_Mode/HAL_GPIO_Recall_Pin_Mode)
* adds #993 to changelog

@technobly technobly modified the milestones: 0.6.x, 0.5.3 Aug 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.