Page 1 of 1

ADC calibration

Posted: Sat Sep 16, 2017 7:53 pm
by VisualEcho
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?

Re: ADC calibration

Posted: Wed Oct 04, 2017 1:36 am
by VisualEcho
I did get this figured out, and what I found was to not count on the ESP32's ADC very much.

Re: ADC calibration

Posted: Wed Oct 04, 2017 2:33 pm
by pythoncoder
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.