Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Analog Voltage on esp32 to use analogReadMilliVolts #620

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/components/analogIO/Wippersnapper_AnalogIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ void Wippersnapper_AnalogIO::setADCResolution(int resolution) {
analogReadResolution(16);
_nativeResolution = 12;
#elif defined(ARDUINO_ARCH_ESP32)
scaleAnalogRead = true;
_nativeResolution = 13;
scaleAnalogRead = true; // probably should be false, handled in bsp
#if defined(ESP32S3)
_nativeResolution = 13; // S3 ADC is 13-bit, others are 12-bit
#else
_nativeResolution = 12;
#endif
#elif defined(ARDUINO_ARCH_RP2040)
scaleAnalogRead = true;
_nativeResolution = 10;
#else
scaleAnalogRead = true;
_nativeResolution = 10;
#endif

_adcResolution = resolution;
}

Expand Down Expand Up @@ -232,8 +235,12 @@ uint16_t Wippersnapper_AnalogIO::getPinValue(int pin) {
*/
/**********************************************************/
float Wippersnapper_AnalogIO::getPinValueVolts(int pin) {
#ifdef ARDUINO_ARCH_ESP32
return analogReadMilliVolts(pin) / 1000.0;
#else
uint16_t rawValue = getPinValue(pin);
return rawValue * getAref() / 65536;
#endif
}

/******************************************************************/
Expand Down Expand Up @@ -380,7 +387,7 @@ void Wippersnapper_AnalogIO::update() {
// Perform voltage conversion if we need to
if (_analog_input_pins[i].readMode ==
wippersnapper_pin_v1_ConfigurePinRequest_AnalogReadMode_ANALOG_READ_MODE_PIN_VOLTAGE) {
pinValVolts = pinValRaw * getAref() / 65536;
pinValVolts = getPinValueVolts(_analog_input_pins[i].pinName);
}

// Publish pin event to IO
Expand Down
Loading