ESP32C6 ADC not working properly

rafael.04694
Posts: 1
Joined: Wed Apr 05, 2023 7:25 pm

ESP32C6 ADC not working properly

Postby rafael.04694 » Wed Apr 05, 2023 11:02 pm

Sorry in advance in case this post is repeated.

I'm trying to read voltages using the ESP ADC, but something weird happens.

I'm using the one shot example from ESP-IDF.

When the pin with the used channel is connected to 3.3V it returns a raw reading of 4081, giving me a V = 4081 * 3V3 / 4095 = 2.28 V which is pretty good. However, when I connect the pin to GND, the raw value is 2144, which gives me something like 1.7V.

I'm using the new C6, and I know its calibration is still not available, but shouldn't the method I'm using work? Considering it works for 3V3?

(The code is the one bellow, with an addition of a printf that prints the voltage using the formula above).

Code: https://github.com/espressif/esp-idf/bl ... ead_main.c

Sprite
Espressif staff
Espressif staff
Posts: 10593
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32C6 ADC not working properly

Postby Sprite » Fri Apr 07, 2023 12:48 am

Wondering if it is because you're witching between two channels all the time. Does it still does that if you only measure one channel?

aenapple
Posts: 1
Joined: Mon Aug 28, 2023 4:37 pm

Re: ESP32C6 ADC not working properly

Postby aenapple » Mon Aug 28, 2023 4:40 pm

I have the same issue - higher bit from 12-bits ADC value always is '1'.

rkit2134
Posts: 6
Joined: Mon Sep 14, 2020 5:54 am

Re: ESP32C6 ADC not working properly

Postby rkit2134 » Wed Aug 30, 2023 9:39 am

I have the same problem. Adc always reads exactly 4081.

lhns_esp
Posts: 1
Joined: Tue Feb 27, 2024 11:53 pm

Re: ESP32C6 ADC not working properly

Postby lhns_esp » Tue Feb 27, 2024 11:58 pm

Hello! I am experiencing the same issue.
If I connect the pin to GND I get the following ADC output: 0b0000100001110001
If I connect it to 3.3V I get: 0b0000111111110001
Is this a hardware bug?

phemmer
Posts: 1
Joined: Mon Mar 04, 2024 1:17 pm

Re: ESP32C6 ADC not working properly

Postby phemmer » Wed Mar 06, 2024 12:44 am

I'm getting the same thing on 2x ESP32-C6-DevKitM-1, and also on a ESP32-H2-DevKitM-1. To get the same thing on H2 and C6, I'm dubious of a hardware bug.

For me I'm working in rust. And this is my first time working with ESP32 units, so I'm inclined to think I'm doing something wrong. However I've basically got the same code as in the example on https://docs.rs/esp32c6-hal/latest/esp3 ... index.html. So I can't see how it would be a software issue either. Unless there's some prerequisites that I've missed.

Also, to note, I do get a signal. When the input voltage changes, so does the value read. But it's nowhere near what it's supposed to be. When pulled to ground, I get ~2144 (bounces around a bit), and when floating it goes to 4081. When I have an input voltage of 0.307v and 0dB attenuation, I should read a value of about 1571, but instead get 3297.

bjozwicki
Posts: 1
Joined: Fri Jun 09, 2023 10:45 am

Re: ESP32C6 ADC not working properly

Postby bjozwicki » Fri May 24, 2024 10:56 am

Same problem here one year later, any update on that? Surprisingly I have tested oneshot read from Arduino and it worked fine...

yeohwaisiang
Posts: 2
Joined: Fri Jun 07, 2024 1:34 pm

Re: ESP32C6 ADC not working properly

Postby yeohwaisiang » Fri Jun 07, 2024 1:42 pm

still no one can resolved the ADC-4081 issue?
where are their engineers?

ewozniak
Posts: 2
Joined: Wed Feb 26, 2025 6:59 am

Re: ESP32C6 ADC not working properly

Postby ewozniak » Wed Feb 26, 2025 7:13 am

Based on my tests in C and Rust, the problem occurs in Rust esp-hal.

If code in C language has DEFAULT_VREF set to 1100 problem should not occur.

Code: Select all

#include <Arduino.h>
#include "driver/adc.h"

#define DEFAULT_VREF    1100
#define ADC_PIN A4

// Define the ADC channel and attenuation
#define ADC_CHANNEL ADC1_CHANNEL_4 // important check your pin channel, for ESP32-C6 DevkitC I have a pin 4
#define ADC_ATTEN ADC_ATTEN_DB_11

int ADC_VALUE = 0;
double voltage_value = 0.0; 

void setup() {
  Serial.begin(9600);
  pinMode(ADC_PIN, INPUT); // set the analog reference to 3.3V
  // Initialize the ADC configuration
  adc1_config_width(ADC_WIDTH_BIT_12);
  adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN);
}

void loop() {
  do_adc();
  delay(500);
}

void do_adc() {
  sensor_reading();
  Serial.print("ADC value: ");
  Serial.println(ADC_VALUE);
  Serial.print("ADC voltage: ");
  Serial.println(voltage_value);
}


float sensor_reading() {
  ADC_VALUE = adc1_get_raw(ADC_CHANNEL);
  voltage_value = (ADC_VALUE * 3.3 );
  return voltage_value;
}

This gives me

ewozniak
Posts: 2
Joined: Wed Feb 26, 2025 6:59 am

Re: ESP32C6 ADC not working properly

Postby ewozniak » Thu Mar 06, 2025 7:15 am

Last day I did some changes in my Rust code and it worked almost perfectly

Code: Select all

#[main]
fn main() -> ! {
    let mut adc1_config = AdcConfig::new();
    let pin = adc1_config.enable_pin_with_cal::<GpioPin<4>, AdcCalBasic<ADC1>>(hw_390_pin, Attenuation::_11dB);
    let adc1 = Adc::new(peripherals.ADC1, adc1_config);
    loop {
        let out: i32 = block!(adc.read_oneshot(&mut pin)).unwrap() as i32;
        info!("read: {:?}", out);
        delay.delay_millis(500);
    }
}
Important part is adc1_config.enable_pin_with_cal::<GpioPin<4>, AdcCalBasic<ADC1>>(hw_390_pin, Attenuation::_11dB);, if you do not define AdcCalScheme output may give you always 4081. There are 3 possible implementations of the AdcCalScheme
  • 1. AdcCalBasic
    2. AdcCalCurve
    3. AdcCalLine
For some reasone I don't undenstand when you enable a pin calibration schema will be () which does nothing.

Code: Select all

pub struct AdcPin<PIN, ADCI, CS = ()> {
    /// The underlying GPIO pin
    pub pin: PIN,
    /// Calibration scheme used for the configured ADC pin
    #[cfg_attr(esp32, allow(unused))]
    pub cal_scheme: CS,
    _phantom: PhantomData<ADCI>,
}

Who is online

Users browsing this forum: PetalBot and 4 guests