@@ -75,8 +75,13 @@ void AnalogIOHardware::SetNativeADCResolution() {
7575 analogReadResolution (16 );
7676 _native_adc_resolution = 12 ;
7777#elif defined(ARDUINO_ARCH_ESP32)
78- _is_adc_resolution_scaled = true ;
79- _native_adc_resolution = 13 ;
78+ _is_adc_resolution_scaled = false ; // Defined in esp32-arduino BSP
79+ #if defined(ESP32S3)
80+ _native_adc_resolution = 13 ; // The ESP32-S3 ADC uses 13-bit resolution
81+ #else
82+ _native_adc_resolution =
83+ 12 ; // The ESP32, ESP32-S2, ESP32-C3 ADCs uses 12-bit resolution
84+ #endif
8085#elif defined(ARDUINO_ARCH_RP2040)
8186 _is_adc_resolution_scaled = true ;
8287 _native_adc_resolution = 10 ;
@@ -125,7 +130,6 @@ void AnalogIOHardware::CalculateScaleFactor() {
125130*/
126131/* ************************************************************************/
127132uint16_t AnalogIOHardware::GetPinValue (uint8_t pin) {
128- // Get the pin's value using Arduino API
129133 uint16_t value = analogRead (pin);
130134 // Scale the pins value
131135 if (_is_adc_resolution_scaled) {
@@ -140,13 +144,16 @@ uint16_t AnalogIOHardware::GetPinValue(uint8_t pin) {
140144
141145/* ************************************************************************/
142146/* !
143- @brief Calculates the voltage of an analog pin.
144- @param raw_value
145- The pin's raw value .
146- @return The pin's voltage, in Volts .
147+ @brief Gets the voltage of an analog pin.
148+ @param pin
149+ The requested pin .
150+ @return The pin's voltage.
147151*/
148152/* ************************************************************************/
149- float AnalogIOHardware::CalculatePinVoltage (uint16_t raw_value) {
150- float voltage = raw_value * _voltage_scale_factor;
151- return voltage;
153+ float AnalogIOHardware::GetPinVoltage (uint8_t pin) {
154+ #ifdef ARDUINO_ARCH_ESP32
155+ return analogReadMilliVolts (pin) / 1000.0 ;
156+ #else
157+ return getPinValue (pin) * _ref_voltage / 65536 ;
158+ #endif // ARDUINO_ARCH_ESP32
152159}
0 commit comments