Skip to content

(( analogRead() )) Strange fluctuations of values when using multiple analogRead() #7820

@ic1414

Description

@ic1414

Board

ESP32 Dev Module

Device Description

ESP32 Dev Module and four potential meters.

Hardware Configuration

Potential meters connect to GPIO 36, 39, 34, 35

Version

v1.0.6

IDE Name

Arduino IDE

Operating System

Windows10

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

921600

Description

Example 1

The value of j2x follows the variation of j1y, but the value of j2x is expected to be a constant. The red one is j1y, and the green one is j2x.
serialPlotter

#define j1x 36
#define j1y 39
#define j2x 34
#define j2y 35

void setup() {
  Serial.begin(250000);
  pinMode(j1x, INPUT);
  pinMode(j1y, INPUT);
  pinMode(j2x, INPUT);
  pinMode(j2y, INPUT);
}


void loop() {
  int vals[4];
  vals[0] = analogRead(j1x);
  vals[1] = analogRead(j1y);
  vals[2] = analogRead(j2x);
  vals[3] = analogRead(j2y);

  for (int i = 0; i < 4; i++) {
    Serial.print(vals[i]);
    Serial.print("   ");
  }
  Serial.println();

  delay(2);
}

Example 2

When swapping the sequence of analogRead(), the problem becomes j2x following the variation of j2y. The yellow one is j2y, and the green one is j2x.and the
图片

  vals[2] = analogRead(j2x);
  vals[0] = analogRead(j1x);
  vals[1] = analogRead(j1y);
  vals[3] = analogRead(j2y);

Sketch

#define j1x 36
#define j1y 39
#define j2x 34
#define j2y 35

void setup() {
  Serial.begin(250000);
  pinMode(j1x, INPUT);
  pinMode(j1y, INPUT);
  pinMode(j2x, INPUT);
  pinMode(j2y, INPUT);
}

void loop() {
  int vals[4];
  vals[0] = analogRead(j1x);
  vals[1] = analogRead(j1y);
  vals[2] = analogRead(j2x);
  vals[3] = analogRead(j2y);

  for (int i = 0; i < 4; i++) {
    Serial.print(vals[i]);
    Serial.print("   ");
  }
  Serial.println();

  delay(2);
}

Debug Message

.

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

Labels

Status: Needs investigationWe need to do some research before taking next steps on this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions