ESP32模拟引脚4值连接WIFI后刷新失败

时间:2019-04-04 12:40:49

标签: esp32

我不明白为什么WIFI智能配置完成后,无法刷新连接10kohm电阻的光敏电阻的ESP32引脚4模拟值,始终保持最大4095。

另一方面,如果未将WIFI智能配置相关的编码添加到源代码中,则如下所示,将从引脚4输入的模拟值刷新

int sensorPin = 4;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 1000;  // variable to store the value coming from the sensor
#include <WiFi.h>

void setup() {
  // declare the ledPin as an OUTPUT:
  Serial.begin(115200);


 WiFi.mode(WIFI_AP_STA);
  WiFi.beginSmartConfig();
  Serial.println("Waiting for Smart Config");

  while (!WiFi.smartConfigDone()) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("Smart Config Done");
  //*Wait for WiFi to connect to AP
  Serial.println("waiting for WiFi");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi Connected");
  Serial.print("IP Address ");
  Serial.println(WiFi.localIP());


}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.println(sensorValue);

  delay(sensorValue);

}

日志

0:40:35.846 -> 
20:40:35.846 -> rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
20:40:35.846 -> configsip: 0, SPIWP:0xee
20:40:35.846 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
20:40:35.846 -> mode:DIO, clock div:1
20:40:35.846 -> load:0x3fff0018,len:4
20:40:35.846 -> load:0x3fff001c,len:1100
20:40:35.846 -> load:0x40078000,len:10088
20:40:35.846 -> load:0x40080400,len:6380
20:40:35.846 -> entry 0x400806a4
20:40:36.215 -> Waiting for Smart Config
20:40:36.719 -> ..............................................................................
20:41:15.217 -> Smart Config Done
20:41:15.217 -> waiting for WiFi
20:41:15.724 -> ..WiFi Connected
20:41:16.233 -> IP Address 192.168.1.7
20:41:16.233 -> 4095
20:41:20.333 -> 4095
20:41:24.427 -> 4095

没有刷新WIFI日志

20:43:16.964 -> 3115
20:43:20.077 -> 3121
20:43:23.196 -> 3122
20:43:26.298 -> 2971
20:43:29.272 -> 1886
20:43:31.159 -> 3109

1 个答案:

答案 0 :(得分:0)

只需要将sensorPin更改为GPIO 36或39或ADC1上运行的任何引脚即可作为模拟监听输入来解决WIFI上拉问题