Skip to content

ESP32-C6: analogRead() returns wrong ADC values while analogReadMilliVolts() returns right mV values #11324

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

Open
1 task done
mercur4148 opened this issue Apr 29, 2025 · 0 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@mercur4148
Copy link

mercur4148 commented Apr 29, 2025

Board

ESP32-C6 Zero

Device Description

Waveshare's ESP32-C6 Zero

Hardware Configuration

GPIO3 is pulled-up via 10k to 3v3

Version

v3.2.0

IDE Name

Arduino IDE 1.8.13

Operating System

Windows 10

Flash frequency

80 MHz

PSRAM enabled

yes

Upload speed

921600

Description

I have a board with GPIO3 pulled up to 3v3 via 10k resistor. I've tried the same experiment with GPIO0. The bug is still the same: when performing analogRead(GPIO_number), I expect to get maximum ADC reading (4095 by default or 2047 if analogReadResolution(11); was called) and something close to 3300 mV when analogReadMilliVolts() is called. But I keep receiving ADC values of 3360 (1680 in 11-bit mode) but with right millivolts of around 3300.

Another thing that I've noticed is that pinMode(GPIO_number, INPUT_PULLUP) does nothing.

Have tried 2 different boards, both ESP cores of 3.1.13 and 3.2.0, and different PCs. The bug is still the same.

I've left commented out ADC settings in setup() so you can reproduce the problem and see it at different resolutions.

Sketch

const uint8_t ANALOG_PIN = 3;

void setup()
{
  Serial.begin(115200);
  pinMode(ANALOG_PIN, INPUT);

  // analogReadResolution(12);
  // analogSetAttenuation(ADC_11db);
}

void loop()
{
  int sensorValue = analogRead(ANALOG_PIN);
  int millivolts = analogReadMilliVolts(ANALOG_PIN);
  Serial.println("-------------");
  Serial.print("ADC value: ");
  Serial.print(sensorValue);
  Serial.print(" in millivolts: ");
  Serial.print(millivolts);
  Serial.println();
  delay(10);
}

Debug Message

Chip Info:
------------------------------------------
  Model             : ESP32-C6
  Package           : 1
  Revision          : 0.01
  Cores             : 1
  CPU Frequency     : 80 MHz
  XTAL Frequency    : 40 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Apr 29 2025 18:53:54
  Compile Host OS   : windows
  ESP-IDF Version   : v5.4.1-1-g2f7dcd862a-dirty
  Arduino Version   : 3.2.0
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32C6_DEV
  Arduino Variant   : esp32c6
  Arduino FQBN      : esp32:esp32:esp32c6:JTAGAdapter=default,CDCOnBoot=cdc,PartitionScheme=default,CPUFreq=80,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=verbose,EraseFlash=none,ZigbeeMode=default
============ Before Setup End ============
[101155][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 12 already has type USB_DM (38) with bus 0x4080ee20
[101157][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 13 already has type USB_DP (39) with bus 0x4080ee20
[101158][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x42000590
[101159][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 3 successfully set to type GPIO (1) with bus 0x4
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   470576 B ( 459.5 KB)
  Free Bytes        :   436432 B ( 426.2 KB)
  Allocated Bytes   :    27608 B (  27.0 KB)
  Minimum Free Bytes:   431532 B ( 421.4 KB)
  Largest Free Block:   401396 B ( 392.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     3 : GPIO
    12 : USB_DM
    13 : USB_DP
    16 : UART_TX[0]
    17 : UART_RX[0]
============ After Setup End =============
[101191][D][esp32-hal-adc.c:272] __analogRead(): Calling __analogInit! pin = 3
[101192][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type ADC_ONESHOT (7) successfully set to 0x420000ba
[101193][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 3 successfully set to type ADC_ONESHOT (7) with bus 0x4
[101195][D][esp32-hal-adc.c:305] __analogReadMilliVolts(): Creating cali handle for ADC_0
-------------
ADC value: 3360 in millivolts: 3318
-------------
ADC value: 3360 in millivolts: 3318
-------------
ADC value: 3361 in millivolts: 3317

Other Steps to Reproduce

Works perfectly on ESP32-C3 SuperMini.

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@mercur4148 mercur4148 added the Status: Awaiting triage Issue is waiting for triage label Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

1 participant