I am using Arduino to experiment around with creation of a PWM based signal on one ESP32, which I do have up and running. I am outputting .959vDC via ledcAttach/ledcWrite using PIN 12. When I put a multimeter on the output, I do get 0.959v DC. This is a good result and what I want. (eventually board #1 will output a sine wave, but for now a steady output voltage is good enough for testing).
I then took a second identical ESP32. Wrote another small program to read the ACD. I am using the VP pin as the input.
When I put a 1.5v AA battery between GND and VP pin on the board, I get back ~1.56vDC.
When I take the outputs from board #1, outputting 0.959vDC and hook them to the inputs of Board #2 via the same VP input pin, I get readings all over the place, and never close to a rock steady 0.959vDC. Same code, totally different results.
I have tried powering both boards from a single 5vDC power supply in thinking that using two different power sources was problematic. That didn't make a difference.
I have tried a few different ESP32 boards and they all return the same result, so I think I am missing something code-wise.
Board #1 (signal output 0.959vDC = Good. Multimeter gets good reading)
Connect Board #1 to Board #2 via GND/VP input pin, ADC input readings all over the place.
Connect Board #2 to 1.5vDC AA battery, steading readings on the same input pins.
Why is this happening?
Note: I am not using any resistors, since all the voltages are <3.3 volts. Thus R1 and R2 below are zero.
Code: Select all
#define ANALOG_IN_PIN 36 // ESP32 pin GPIO36 (ADC0) connected to voltage sensor "VP" PIN
#define REF_VOLTAGE 3.3
#define ADC_RESOLUTION 4096.0
#define R1 0.0 // resistor values in voltage sensor (in ohms)
#define R2 0.0 // resistor values in voltage sensor (in ohms)
void setup() {
Serial.begin(115200);
// set the ADC attenuation to 11 dB (up to ~3.3V input)
analogSetAttenuation(ADC_11db);
}
void loop() {
// read the analog input
int adc_value = analogRead(ANALOG_IN_PIN);
// determine voltage at adc input
float voltage_adc = ((float)adc_value * REF_VOLTAGE) / ADC_RESOLUTION;
// calculate voltage at the sensor input
float voltage_in = voltage_adc * (R1 + R2) / R2;
// print results to serial monitor to 2 decimal places
Serial.print("adc_value= ");
Serial.print(adc_value, 2);
Serial.print(" Measured V1 = ");
Serial.print(voltage_in, 2);
Serial.print(" v@ADC = ");
Serial.println(voltage_adc, 2);
delay(200);
}