Skip to content

analogRead() does not reset pin properly after previous pinMode() #829

Open
@dhalbert

Description

@dhalbert

BSP: Arduino MBed OS Giga boards v4.0.10
Board: Giga R1
Arduino IDE: 2.2.1

Sample sketch:

void setup() {
  Serial.begin(9600);
  while (!Serial) { }

  // Attach A0 to 3.3V through a 220K or other high-value resistor,
  // so it's not stronger than the driven output.

  delay(100);
  Serial.println(analogRead(A0));

  pinMode(A0, INPUT);

  delay(100);
  Serial.println(analogRead(A0));

  Serial.println("Done");
}

void loop() {
}

On my test setup, this prints:

744
92
Done

I would expect it to print 744 or close to that twice.
Once the pin is used in the pinMode(), it appears to be pulled low.

By comparison, the same sketch on an Arduino Uno prints (with the 220K resistor connected to 5V):

1023
1023
Done

The use case is a resistive touch screen driver (https://github.com/adafruit/Adafruit_TouchScreen) which flips pins back and forth between digital input/output and analog input modes to read X/Y resistance values.

This is reminiscent of (though order is different) to #328 and arduino/ArduinoCore-renesas#58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions