So I've powered the remainder of the circuit with a separate 3.3 volt regulator.
Anyone interested in the cad model can download it here:
I've used it in my other projects before and it has worked out well.
I was able to power the reguator with the Vin pin of the ESP32.
I've measured the Vout and it's ~3.27 volts.
Thanks to 6v6gt for helping complete the original code.
I've modified the program in the post here to print only one variable (the azimuth variable):
TEMT6000 smoothing values on ESP32 ADC for ESP-Now
I figured I would get correct readings but something is off.
When I light up the right half of the circuit I get a serial readout with values.
When I light up the left half of the circuit the serial readout is zero.
Here is the code. Free and open source. CC BY 4.0:
//Free and open source. CC BY 4.0
#include <driver/adc.h>
// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 64;
const int numSensors = 1;
uint32_t readings[numSensors][numReadings]; //multi-dimensional readings from analog input
uint32_t total[numSensors] = {0}; // the running total
uint32_t readIndex = 0; // the index of the current reading
uint32_t average = 0; // the average
uint16_t EspNowAverage = 0; // 0-255 value average
// delay to process smoothing readings
uint16_t numReadingsInterval = 1;
uint32_t lastEventAtMs = 0 ;
void setup() {
Serial.begin(115200);
// initialize all the readings to 0:
for (uint16_t thisReading = 0; thisReading < numReadings; thisReading++) {
for ( int j = 0; j < numSensors; j++) readings[j][thisReading] = 0;
}
}
void loop() {
//Voltage divider analog in pins
// https://dl.espressif.com/doc/esp-idf/latest/api-reference/peripherals/adc.html
// set up A:D channels
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_11); //Pin34
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_11); //Pin35
// millis() -->Returns the number of milliseconds passed since the Arduino board began running the current program.
// This number will overflow (go back to zero), after approximately 50 days.
// timing resets to 0 when millis() - lastEventAtMS becomes greater than or equal to numReadingsInterval
// then loop proceeds with remaining functions
if ( millis() - lastEventAtMs >= numReadingsInterval ) {
lastEventAtMs = millis();
// Read the sensor
uint16_t Azimuth = adc1_get_raw(ADC1_CHANNEL_6);
uint16_t Elevation = adc1_get_raw(ADC1_CHANNEL_7);
uint16_t inputPin[ numSensors ] = {Azimuth};
uint16_t ai;
for (ai = 0; ai < numSensors ; ai++) {
// subtract the last reading:
total[ ai ] = total[ ai ] - readings[ai][readIndex];
// read from the sensor:
readings[ai][readIndex] = inputPin[ai];
// add the reading to the total:
total[ai] = total[ai] + readings[ai][readIndex];
// calculate the average:
average = total[ai] / numReadings;
// reduce results to 0-255
EspNowAverage = average/16;
Serial.print( "EspNowAverage sensor: ");
Serial.print( ai );
Serial.print( " " );
Serial.println(EspNowAverage); //
}
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}
}
}
Here is the serial readout (right side with light, voltage readout of 2.2 volts,
half of 3.3 volts is 1.65 volts --> a difference of .55 volts from the midpoint --> .55volts/3.3 volts equals .167 --> .167 * 255 (0-255 adc range) = ~42.5
the left half was covered up with a finger.):
EspNowAverage sensor:
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
EspNowAverage sensor: 0 42
Now when I cover the right half and light up the left half, the serial read out is 0 and the voltage readout is ~.01 volts.
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
EspNowAverage sensor: 0 0
I don't get it. My circuit setup seems correct and matches the photoresistor setup I had, except now I'm using phototransistors. I take multimeter readings at the ground of the ESP32, and at V location (right sensor) and for the left sensor (S location, or signal out).