Incorrect Readings from Capacitive Soil Sensor w/ ESP32 Thing Plus

I’m trying to read a capacitive soil sensor using the analog inputs of my ESP32 Thing Plus board. I’m getting 3423/3415/etc. no matter what I do to the sensor. I’ve read the voltage coming off the sensor using a multimeter and it fluctuates as I submerge it in water so I have no idea why the analogRead() doesn’t show any variation.

I’ve also tried switching in a potentiometer and cannot get the value to change at all. When I connect the sensor to a standard Arduino board, it reads correctly. Any help is greatly appreciated. I’ve copied my code below, but it is very basic.

void setup() {
  Serial.begin(9600); // open serial port, set the baud rate as 9600 bps
}

void loop() {
  int val;
  val = analogRead(0); //connect sensor to Analog 0
  Serial.println(val); //print the value to serial port
  delay(1000);
}

Bumbled my way to an answer, I think. Want to keep this up in case anyone else runs into a similar roadblock (and maybe someone can give a better answer than I can). To resolve this issue, I had to do some configuration of the ADC. I know know why, only that I had to.

I pieced it together from this github issue: https://github.com/espressif/arduino-esp32/issues/683

And the adc documentation here: https://docs.espressif.com/projects/esp … s/adc.html

I’m planning to use pretty much all the analog inputs on the board and, from the docs, it looks like I’ll be juggling the wifi connection to make that work.

My new code:

#include <driver/adc.h>

int readSoilSensor(){
  int read_raw;
  adc2_config_channel_atten(ADC2_CHANNEL_9,ADC_ATTEN_DB_11);  //ADC_ATTEN_DB_11 = 0-3,6V
  adc2_get_raw( ADC2_CHANNEL_9, ADC_WIDTH_10Bit, &read_raw );
  return read_raw;
}

void setup() {
  Serial.begin(9600); // open serial port, set the baud rate as 9600 bps
}

void loop() {
  Serial.println(readSoilSensor());
  delay(1000);
}