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

Commit ac52ad5

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

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The catch is your function is now part of an **ISR (Interrupt Service Routine)**
5353

5454
## Prerequisite
5555

56-
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
56+
1. [`Arduino IDE 1.8.13+`](https://www.arduino.cc/en/Main/Software)
5757
2. [`ESP32 core 1.0.4+`](https://github.com/espressif/arduino-esp32/releases) for ESP32 boards
5858

5959
---
@@ -81,6 +81,46 @@ Another way to install is to:
8181
3. Install **ESP32_ISR_Servo** library by using [Library Manager](https://docs.platformio.org/en/latest/librarymanager/). Search for ESP32_ISR_Servo in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
8282
4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
8383

84+
---
85+
---
86+
87+
### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
88+
89+
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.
90+
91+
#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2
92+
93+
#### 2. ESP32 ADCs functions
94+
95+
- ADC1 controls ADC function for pins **GPIO32-GPIO39**
96+
- ADC2 controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27**
97+
98+
#### 3.. ESP32 WiFi uses ADC2 for WiFi functions
99+
100+
Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61)
101+
102+
> In ADC2, there're two locks used for different cases:
103+
> 1. lock shared with app and Wi-Fi:
104+
> ESP32:
105+
> When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.
106+
> ESP32S2:
107+
> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
108+
>
109+
> 2. lock shared between tasks:
110+
> when several tasks sharing the ADC2, we want to guarantee
111+
> all the requests will be handled.
112+
> Since conversions are short (about 31us), app returns the lock very soon,
113+
> we use a spinlock to stand there waiting to do conversions one by one.
114+
>
115+
> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
116+
117+
118+
- In order to use ADC2 for other functions, we have to **acquire complicated firmware locks and very difficult to do**
119+
- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
120+
- Use ADC1, and pins GPIO32-GPIO39
121+
- 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).
122+
123+
---
84124
---
85125

86126
## More useful Information

0 commit comments

Comments
 (0)