ADC1 on Adafruit Feather HUZZAH-ESP32 doesn't work with esp-idf
Posted: Thu May 24, 2018 12:43 pm
Hello,
I do not know if this is the right place for my request. Maybe it would be better to place it at Adafruit?
Yesterday I started with the "ADC" part of my DIY project: I use an Adafruit Feather HUZZAH-ESP32 (ESP32-WROOM) with esp-idf and need some ADC channels. I'd prefer to use ADC1 for my goal, because ADC2 is used by WiFi also.
I wrote a simple code for testing the ADC code at all with the esp-idf (with v3.0-rc1 and with v3.0).
Because the output displayed different values with open inputs, I connected alternately the input pins with GND.
Running this code displays that the unit ADC2 only works.
Since I have two modules of the feather, I tried the code with both modules: with the same result, the unit ADC1 doesn't work.
Is it a known issue/failure?
Thanks in advance,
Michael
I do not know if this is the right place for my request. Maybe it would be better to place it at Adafruit?
Yesterday I started with the "ADC" part of my DIY project: I use an Adafruit Feather HUZZAH-ESP32 (ESP32-WROOM) with esp-idf and need some ADC channels. I'd prefer to use ADC1 for my goal, because ADC2 is used by WiFi also.
I wrote a simple code for testing the ADC code at all with the esp-idf (with v3.0-rc1 and with v3.0).
Code: Select all
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/adc.h"
#include "freertos/FreeRTOS.h"
#include "esp_system.h"
typedef struct
{
int channel;
char name[8];
} adc_channel;
adc_channel adc1[] =
{
{ ADC1_CHANNEL_0, "A1_0" }, // IO36/A4
{ ADC1_CHANNEL_3, "A1_3" }, // IO39/A3
{ ADC1_CHANNEL_4, "A1_4" }, // IO32/A7
{ ADC1_CHANNEL_5, "A1_5" }, // IO33/A9
{ ADC1_CHANNEL_6, "A1_6" }, // IO34/A2
{ ADC1_CHANNEL_MAX, "" }
};
adc_channel adc2[] =
{
{ ADC2_CHANNEL_0, "A2_0" }, // IO4/A5
{ ADC2_CHANNEL_3, "A2_3" }, // IO15/A8
{ ADC2_CHANNEL_4, "A2_4" }, // IO13/A12
{ ADC2_CHANNEL_5, "A2_5" }, // IO12/A11
{ ADC2_CHANNEL_6, "A2_6" }, // IO14/A6
{ ADC2_CHANNEL_7, "A2_7" }, // IO27/A10
{ ADC2_CHANNEL_8, "A2_8" }, // A1/DAC1
{ ADC2_CHANNEL_9, "A2_9" }, // A0/DAC2
{ ADC2_CHANNEL_MAX, "" }
};
void app_main(void)
{
int adc_value, ch;
gpio_num_t gpio;
adc_power_on();
adc_set_data_inv(ADC_UNIT_1, false);
adc_set_data_width(ADC_UNIT_1, ADC_WIDTH_BIT_12);
for (ch = 0; adc1[ch].channel != ADC1_CHANNEL_MAX; ch++)
{
if (adc1_pad_get_io_num(adc1[ch].channel, &gpio) == ESP_OK)
gpio_set_direction(gpio, GPIO_MODE_INPUT);
adc1_config_channel_atten(adc1[ch].channel, ADC_ATTEN_DB_0);
}
adc_set_data_inv(ADC_UNIT_2, false);
for (ch = 0; adc2[ch].channel != ADC2_CHANNEL_MAX; ch++)
{
if (adc2_pad_get_io_num(adc2[ch].channel, &gpio) == ESP_OK)
gpio_set_direction(gpio, GPIO_MODE_INPUT);
adc2_config_channel_atten(adc2[ch].channel, ADC_ATTEN_DB_0);
}
while (true)
{
for (ch = 0; adc1[ch].channel != ADC1_CHANNEL_MAX; ch++)
{
adc_value = adc1_get_raw(adc1[ch].channel);
printf("%s : %4d\n", adc1[ch].name, adc_value);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
for (ch = 0; adc2[ch].channel != ADC2_CHANNEL_MAX; ch++)
{
adc2_get_raw(adc2[ch].channel, ADC_WIDTH_BIT_12, &adc_value);
printf("%s : %4d\n", adc2[ch].name, adc_value);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Running this code displays that the unit ADC2 only works.
Since I have two modules of the feather, I tried the code with both modules: with the same result, the unit ADC1 doesn't work.
Is it a known issue/failure?
Thanks in advance,
Michael