Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit bc6ee7e

Browse files
authored
Update README.md
Add note : - HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
1 parent 78f9e85 commit bc6ee7e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,45 @@ To re-use the new h-only way, just
128128
---
129129
---
130130

131+
### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
132+
133+
Please have a look at [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to have more detailed description and solution of the issue.
134+
135+
#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2
136+
137+
#### 2. ESP32 ADCs functions
138+
139+
- ADC1 controls ADC function for pins **GPIO32-GPIO39**
140+
- ADC2 controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27**
141+
142+
#### 3.. ESP32 WiFi uses ADC2 for WiFi functions
143+
144+
Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61)
145+
146+
> In ADC2, there're two locks used for different cases:
147+
> 1. lock shared with app and Wi-Fi:
148+
> ESP32:
149+
> When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.
150+
> ESP32S2:
151+
> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
152+
>
153+
> 2. lock shared between tasks:
154+
> when several tasks sharing the ADC2, we want to guarantee
155+
> all the requests will be handled.
156+
> Since conversions are short (about 31us), app returns the lock very soon,
157+
> we use a spinlock to stand there waiting to do conversions one by one.
158+
>
159+
> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
160+
161+
162+
- In order to use ADC2 for other functions, we have to **acquire complicated firmware locks and very difficult to do**
163+
- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
164+
- Use ADC1, and pins GPIO32-GPIO39
165+
- If somehow it's a must to use those pins serviced by ADC2 (**GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27**), use the **fix mentioned at the end** of [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to work with ESP32 WiFi/BlueTooth (BT/BLE).
166+
167+
---
168+
---
169+
131170
## How It Works
132171

133172
- The [Async_ConfigOnSwitch](examples/Async_ConfigOnSwitch) example shows how it works and should be used as the basis for a sketch that uses this library.

0 commit comments

Comments
 (0)