From 1198d5a1b97b644103ff901922eba66da4301f5d Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Wed, 21 Oct 2020 14:40:59 -0400 Subject: [PATCH] Update README.md Add note : - HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE) --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13ad2ff..16b0d14 100644 --- a/README.md +++ b/README.md @@ -157,11 +157,11 @@ This file must be copied into the directory: - `~/.arduino15/packages/arduino/hardware/sam/x.yy.zz/platform.txt` - 4. ***To be able to compile without error and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards***, you have to copy the whole [Arduino SAMD cores 1.8.8](Packages_Patches/arduino/hardware/samd/1.8.8) directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.8). + 4. ***To be able to compile without error and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards***, you have to copy the whole [Arduino SAMD cores 1.8.9](Packages_Patches/arduino/hardware/samd/1.8.9) directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.9). -Supposing the Arduino SAMD version is 1.8.8. These files must be copied into the directory: -- `~/.arduino15/packages/arduino/hardware/samd/1.8.8/platform.txt` -- ***`~/.arduino15/packages/arduino/hardware/samd/1.8.8/cores/arduino/Arduino.h`*** +Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory: +- `~/.arduino15/packages/arduino/hardware/samd/1.8.9/platform.txt` +- ***`~/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino/Arduino.h`*** Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z @@ -230,6 +230,45 @@ To use the old standard cpp way, just --- --- +### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE) + +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. + +#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2 + +#### 2. ESP32 ADCs functions + +- ADC1 controls ADC function for pins **GPIO32-GPIO39** +- ADC2 controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27** + +#### 3.. ESP32 WiFi uses ADC2 for WiFi functions + +Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61) + +> In ADC2, there're two locks used for different cases: +> 1. lock shared with app and Wi-Fi: +> ESP32: +> When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed. +> ESP32S2: +> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock. +> +> 2. lock shared between tasks: +> when several tasks sharing the ADC2, we want to guarantee +> all the requests will be handled. +> Since conversions are short (about 31us), app returns the lock very soon, +> we use a spinlock to stand there waiting to do conversions one by one. +> +> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock. + + +- In order to use ADC2 for other functions, we have to **acquire complicated firmware locks and very difficult to do** +- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE). +- Use ADC1, and pins GPIO32-GPIO39 +- 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). + +--- +--- + ### Examples Also see examples: