@@ -75,8 +75,13 @@ void AnalogIOHardware::SetNativeADCResolution() {
75
75
analogReadResolution (16 );
76
76
_native_adc_resolution = 12 ;
77
77
#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
80
85
#elif defined(ARDUINO_ARCH_RP2040)
81
86
_is_adc_resolution_scaled = true ;
82
87
_native_adc_resolution = 10 ;
@@ -125,7 +130,6 @@ void AnalogIOHardware::CalculateScaleFactor() {
125
130
*/
126
131
/* ************************************************************************/
127
132
uint16_t AnalogIOHardware::GetPinValue (uint8_t pin) {
128
- // Get the pin's value using Arduino API
129
133
uint16_t value = analogRead (pin);
130
134
// Scale the pins value
131
135
if (_is_adc_resolution_scaled) {
@@ -140,13 +144,16 @@ uint16_t AnalogIOHardware::GetPinValue(uint8_t pin) {
140
144
141
145
/* ************************************************************************/
142
146
/* !
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.
147
151
*/
148
152
/* ************************************************************************/
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
152
159
}
0 commit comments