Skip to content

Instantly share code, notes, and snippets.

@suru-dissanaike
Created January 26, 2019 19:03
Show Gist options
  • Save suru-dissanaike/0d2259e8b538acaa667039d78d6648d6 to your computer and use it in GitHub Desktop.
Save suru-dissanaike/0d2259e8b538acaa667039d78d6648d6 to your computer and use it in GitHub Desktop.
Custom configuration of the ADC
#include <stdio.h>
#include "esp32/esp32_adc.h"
#include "esp_adc_cal.h"
#include "mgos.h"
#include "mgos_adc.h"
#include "mgos_system.h"
#include "mjs.h"
/* Custom configuration of the ADC */
int pc_adc_configuration(void)
{
static int s_vref = 1100;
// Using PIN32
/*
{.pin = 36, .ch = ADC1_CHANNEL_0},
{.pin = 37, .ch = ADC1_CHANNEL_1},
{.pin = 38, .ch = ADC1_CHANNEL_2},
{.pin = 39, .ch = ADC1_CHANNEL_3},
{.pin = 32, .ch = ADC1_CHANNEL_4},
{.pin = 33, .ch = ADC1_CHANNEL_5},
{.pin = 34, .ch = ADC1_CHANNEL_6},
{.pin = 35, .ch = ADC1_CHANNEL_7},
*/
if (adc1_config_width(ADC_WIDTH_12Bit) != ESP_OK || adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_6db) != ESP_OK)
{
LOG(LL_INFO, ("fail ADC config"));
return -1;
}
esp_adc_cal_characteristics_t *adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_6db, ADC_WIDTH_12Bit, s_vref, adc_chars);
return 0;
}
enum mgos_app_init_result mgos_app_init(void)
{
LOG(LL_INFO, ("----------- Ver 0.01 ------------"));
return MGOS_APP_INIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment