ADC calibration

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
VisualEcho
Posts: 17
Joined: Mon Jul 04, 2016 7:49 pm
Location: Ann Arbor, Michigan
Contact:

ADC calibration

Post by VisualEcho » Sat Sep 16, 2017 7:53 pm

How do I use the "esp_adc_cal" functions?

It looks like
esp_adc_cal.c ( https://github.com/espressif/esp-idf/bl ... _adc_cal.c )
is in the currently-used ESP-IDF branch, and so I was wondering if
machine_adc.c ( https://github.com/micropython/micropyt ... hine_adc.c )
could have just a few tweaks done to the read() function, similar to the example at
adc1_example_main.c ( https://github.com/espressif/esp-idf/bl ... ple_main.c ).

I think it would be along the lines of

Code: Select all

STATIC mp_obj_t madc_read(mp_obj_t self_in) {
    madc_obj_t *self = self_in;
    esp_adc_cal_characteristics_t characteristics;

    esp_adc_cal_get_characteristics(1100, self->width, self->atten, &characteristics);

    //int val = adc1_get_raw(self->adc1_id);
    int val = adc1_to_voltage(self->adc1_id, &characteristics);
    if (val == -1) mp_raise_ValueError("Parameter Error");
    
    return MP_OBJ_NEW_SMALL_INT(val);
}
MP_DEFINE_CONST_FUN_OBJ_1(madc_read_obj, madc_read);
with the 'width' and 'atten' attributes added to the object structure. If the include and source files are added to the makefile, then I get
"Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception was unhandled." on build/flash/boot.

Okay, so the five-minute edit version didn't work... what am I missing?

User avatar
VisualEcho
Posts: 17
Joined: Mon Jul 04, 2016 7:49 pm
Location: Ann Arbor, Michigan
Contact:

Re: ADC calibration

Post by VisualEcho » Wed Oct 04, 2017 1:36 am

I did get this figured out, and what I found was to not count on the ESP32's ADC very much.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ADC calibration

Post by pythoncoder » Wed Oct 04, 2017 2:33 pm

The DAC's aren't too clever either if my quick measurement is typical. See note at bottom of http://hinch.me.uk/ESP32/ESP32-Devkit-C-pinout.pdf.
Peter Hinch
Index to my micropython libraries.

Post Reply