I am working on project that requires measuring the voltage of six different inputs simultanously. For the development I'm using the DevKitC with ESP WROOM 32.
http://akizukidenshi.com/download/ds/es ... eet_en.pdf
As a newcomer to ESP32, I am using the adc example.
Here is the code I used:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "esp_system.h"
#include "esp_adc_cal.h"
#define V_REF 1100
#define ADC1_TEST_CHANNEL (ADC1_CHANNEL_7)
//#define V_REF_TO_GPIO //Remove comment on define to route v_ref to GPIO
void app_main(void)
{
#ifndef V_REF_TO_GPIO
//Init ADC and Characteristics
esp_adc_cal_characteristics_t characteristics;
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_0db);
esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_0db, ADC_WIDTH_12Bit, &characteristics);
uint32_t voltage;
while(1){
voltage = adc1_to_voltage(ADC1_TEST_CHANNEL, &characteristics);
printf("%d mV\n",voltage);
vTaskDelay(pdMS_TO_TICKS(1000));
}
#else
//Get v_ref
esp_err_t status;
status = adc2_vref_to_gpio(GPIO_NUM_25);
if (status == ESP_OK){
printf("v_ref routed to GPIO\n");
}else{
printf("failed to route v_ref\n");
}
fflush(stdout);
#endif
}
123 mV
124 mV
124 mV
122 mV
120 mV
121 mV
121 mV
124 mV
128 mV
139 mV
146 mV
155 mV
172 mV
172 mV
187 mV
195 mV
195 mV
189 mV
188 mV
190 mV
185 mV
195 mV
202 mV
198 mV
199 mV
Then with a jumper cable attached (with no power source!)
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
54 mV
81 mV
193 mV
338 mV
617 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
1018 mV
It seems that the voltage is going up and down over and over again. I am completely clueless why this is happening. It could be that I'm missing something obvious in the config for example, but I have not been able to figure out what is wrong.
I would really appreciate all the help and information on the topic.