Skip to content

digitalRead gets stuck on 0 once analogRead is called on the pin #10927

Closed
@thegoodhen

Description

@thegoodhen

Board

ESP32-S3 custom board

Device Description

I bumped into this issue with my custom ESP32S3 board. The board was not detecting a button press after I mistakingly left analogRead in the loop.

Hardware Configuration

A button to pin 3, but can be replicated by having a pullup from 3 to vcc.

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

N/A

PSRAM enabled

yes

Upload speed

921600

Description

Once analogRead is called on a pin, subsequent calls to digitalWrite return zero, even if the pin is pulled high.

Sketch

void setup() {
  // put your setup code here, to run once:
  pinMode(3, INPUT);
  Serial.begin(115200);
  // gpio pulled high
  Serial.println(analogRead(3));
  delay(100);
}

void loop() {

  Serial.println(digitalRead(3));
  delay(100);
}

Debug Message

Printing zeros, despite being pulled high.

15:13:35.602 -> 0
15:13:35.699 -> 0
15:13:35.796 -> 0
15:13:35.893 -> 0
15:13:35.989 -> 0
15:13:36.086 -> 0
15:13:36.182 -> 0
15:13:36.279 -> 0
15:13:36.376 -> 0

When I interleave analogRead and digitalRead printouts (sanity check):

:15:22.993 -> 4095
15:15:23.090 -> 0
15:15:23.185 -> 4095
15:15:23.314 -> 0
15:15:23.410 -> 4095
15:15:23.507 -> 0
15:15:23.605 -> 4095

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions