You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 5, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,6 +77,45 @@ The best and easiest way is to use `Arduino Library Manager`. Search for `Blynk_
77
77
---
78
78
---
79
79
80
+
### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
81
+
82
+
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.
83
+
84
+
#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2
85
+
86
+
#### 2. ESP32 ADCs functions
87
+
88
+
- ADC1 controls ADC function for pins **GPIO32-GPIO39**
89
+
- ADC2 controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27**
90
+
91
+
#### 3.. ESP32 WiFi uses ADC2 for WiFi functions
92
+
93
+
Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61)
94
+
95
+
> In ADC2, there're two locks used for different cases:
96
+
> 1. lock shared with app and Wi-Fi:
97
+
> ESP32:
98
+
> When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.
99
+
> ESP32S2:
100
+
> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
101
+
>
102
+
> 2. lock shared between tasks:
103
+
> when several tasks sharing the ADC2, we want to guarantee
104
+
> all the requests will be handled.
105
+
> Since conversions are short (about 31us), app returns the lock very soon,
106
+
> we use a spinlock to stand there waiting to do conversions one by one.
107
+
>
108
+
> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
109
+
110
+
111
+
- In order to use ADC2 for other functions, we have to **acquire complicated firmware locks and very difficult to do**
112
+
- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
113
+
- Use ADC1, and pins GPIO32-GPIO39
114
+
- 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).
115
+
116
+
---
117
+
---
118
+
80
119
### How to migrate from [BlynkESP32_BT_WF library](https://github.com/khoih-prog/BlynkESP32_BT_WF)
0 commit comments