{
  "id": "matthias-bs/MicroPython-ADC_Cal",
  "name": "MicroPython-ADC_Cal",
  "prettyName": "MicroPython-ADC_Cal",
  "description": "MicroPython ESP32 library for calibrated on-chip ADC conversion ",
  "version": "",
  "author": "matthias-bs",
  "license": "MIT",
  "tags": [
    "esp32",
    "micropython",
    "micropython-esp32"
  ],
  "status": "VALID",
  "official": false,
  "source": "https://github.com/matthias-bs/MicroPython-ADC_Cal",
  "updatedAt": "2026-02-13T07:00:21.819Z",
  "page": "https://checkmim.com/packages/matthias-bs+MicroPython-ADC_Cal",
  "createdAt": "2025-05-27T04:29:35.198Z",
  "submittedBy": "oliverr",
  "install": {
    "mpremote": "mpremote mip install github:matthias-bs/MicroPython-ADC_Cal",
    "mip": "import mip; mip.install(\"github:matthias-bs/MicroPython-ADC_Cal\")"
  },
  "readme": "[![formatting: lint](https://github.com/matthias-bs/MicroPython-ADC_Cal/actions/workflows/code-formatting.yml/badge.svg)](https://github.com/matthias-bs/MicroPython-ADC_Cal/actions/workflows/ci.yml)\n[![GitHub release](https://img.shields.io/github/release/matthias-bs/MicroPython-ADC_Cal?maxAge=3600)](https://github.com/matthias-bs/MicroPython-ADC_Cal/releases)\n\n# MicroPython-ADC_Cal\n**MicroPython ESP32 library for calibrated on-chip ADC conversion**\n\n***Please refer to ESP32 documentation for maximum ADC input voltage ratings!!!***\n\nThe [Espressif IDF API Reference](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html) describes the limitations of the ESP32's built-in analog-to-digital converter - and provides a (partial) solution in terms of providing a method for improving its accuracy by using a chip specific calibration value (or two calibration values, respectively) stored in the efuse. It also provides useful information regarding *noise mitigation* and the *suggested range* of input voltages in each mode.\n\nThis [ADC calibration scheme](https://github.com/espressif/esp-idf/blob/master/components/esp_adc_cal/esp_adc_cal_esp32.c) is (in parts) provided by the ADC1Cal class.\n\nThe following restriction applies:\n* Only V_ref calibration mode is supported<br>(This is due to the fact that the author does not have a proper ESP32 device to test two point calibration mode.)\n\n`ADC1Cal` extends MicroPython's ESP32 `machine.ADC` class. Please refer to the [MicroPython ESP32 ADC documentation](https://docs.micropython.org/en/latest/esp32/quickref.html#adc-analog-to-digital-conversion) for methods and attributes inherited from the `ADC` class.\n\n    Attributes:\n        name (string):      instance name (for debugging)\n        vref (int):         ADC reference voltage in mV (from efuse calibration data or supplied by programmer)\n\n    Methods:\n        @property\n        voltage()\n            Get voltage measurement [mV]\n\n            Returns:\n                float: voltage [mV]\n        \n        __str__()\n            Dump object info as a string\n            \n            Returns:\n                string: \"Name: <n>  width: <w>, attenuation: <a>, raw value: <raw>, value: <voltage>\"\n\n**Usage example:**\n\n        from machine import Pin\n        import adc1_cal\n        \n        ADC_PIN   = 35                # ADC input pin no.\n        DIV       = 1                 # div = V_measured / V_input; here: no input divider\n        AVERAGING = 10                # no. of samples for averaging (default: 10)\n        \n        # vref = None -> V_ref calibration value is read from efuse\n        ubatt = ADC1Cal(Pin(ADC_PIN, Pin.IN), DIV, None, AVERAGING, \"ADC1 Calibrated\")\n        \n        # set ADC result width\n        ubatt.width(ADC.WIDTH_10BIT)\n    \n        # set attenuation\n        ubatt.atten(ADC.ATTN_6DB)\n    \n        print('ADC Vref: {:4}mV'.format(ubatt.vref))\n    \n        print('Voltage:  {:4.1f}mV'.format(ubatt.voltage))\n\n        \n"
}