arduino / arduino/ArduinoCore-mbed

`analogRead()` does not reset pin properly after previous `pinMode()`

Open
#829 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
411
Forks
225
PR merge metrics
No merged PRs in 30d

Description

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

Sample sketch:
```c
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 https://github.com/arduino/ArduinoCore-mbed/issues/328 and https://github.com/arduino/ArduinoCore-renesas/issues/58

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided sketch on a Giga R1 with Arduino MBed OS v4.0.10 and compare the readings before and after pinMode(A0, INPUT). Trace the pinMode() and analogRead() entry points for the board, then verify that the second reading remains close to the first and that the Adafruit_TouchScreen use case can switch pin modes correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.