Page 1 of 1

ESP32 bad ADC1 readings

Posted: Tue Feb 16, 2021 6:28 pm
by DwDckQo
Hello guys, i have esp32 dev kit and I need to read voltage from 4-20mA transducer. I made simple circuit with rail-to-rail op amp.
Schematic: https://drive.google.com/file/d/15zgiig ... sp=sharing

So, my measure voltage range is from 0.6V to 3.0V. When I connect transducer and then I want read voltage by ADC (gpio35) I get 3.3V (4095) where should be less, actually about 2.9V. I measured the output to adc with multimeter and it shows exactly 2.9V (measured between adc pin and esp32 gnd), but ADC read 4095 = 3.3V...

I also tried another channel of adc1 (6,7), and then i also try replace "analogRead" function with "adc1_get_raw", but still same issue. It looks like adc is saturated.. OR ? Did anyone have a similar problem? Thank you for all the advices ;)

SETUP:
  1.   adc1_config_width(ADC_WIDTH_12Bit);
  2.   adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_MAX); //GPIO 34
  3.   adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_MAX); //GPIO 35
My code:
  1. float readAdcVoltage(tsadcSamples *trans, int16_t lsbOffset, uint16_t adcRozsahLow, uint16_t adcRozsahHigh, float inVoltLow, float inVoltHigh){
  2.  
  3.     //Null
  4.     trans->buffer = 0;
  5.     trans->avgSample = 0;
  6.  
  7.     //OverSample
  8.     for(int i = 0; i < ADC_BUFFERSIZE; i++)
  9.     {
  10.         trans->buffer += analogRead(trans->adcPin);
  11.     }
  12.  
  13.     trans->avgSample = (trans->buffer >> 2);
  14.    
  15.     trans->internalVolt = (trans->avgSample * ADC_VREF) / (ADC_BIT);
  16.     trans->externalVolt = (trans->internalVolt * 3.0303030303);
  17.     trans->value = mapf(trans->avgSample, adcRozsahLow, adcRozsahHigh, inVoltLow, inVoltHigh); //BAR
  18.  
  19.     return trans->internalVolt;
  20.  
  21. }