Skip to content

analogReadMilliVolts returns the wrong value in esp32-s2 #6436

Closed
@yangminglong

Description

@yangminglong

Board

none

Device Description

esp32-s2

Hardware Configuration

none

Version

latest master

IDE Name

none

Operating System

none

Flash frequency

none

PSRAM enabled

no

Upload speed

none

Description

[esp32-s2-adc api-reference:]
(https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/adc.html)

Attenuation Measurable input voltage range
ADC_ATTEN_DB_0 0 mV ~ 750 mV
ADC_ATTEN_DB_2_5 0 mV ~ 1050 mV
ADC_ATTEN_DB_6 0 mV ~ 1300 mV
ADC_ATTEN_DB_11 0 mV ~ 2500 mV

arduino-esp32-master code at line 251:

    uint16_t adc_reading = __analogRead(pin);
    uint16_t max_reading = 8191;
    uint16_t max_mv = 1100;
    switch(__analogAttenuation){
        case 3: max_mv = 3900; break;
        case 2: max_mv = 2200; break;
        case 1: max_mv = 1500; break;
        default: break;
    }
    return (adc_reading * max_mv) / max_reading;

#4941
#4386

Sketch

none

Debug Message

none

Other Steps to Reproduce

none

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

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions