khoih-prog / ESP_WiFiManager

This is an ESP32 / ESP8266 WiFi Connection Manager with fallback web configuration portal. Use this library for configuring ESP32 (including ESP32-S2 and ESP32-C3), ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson
MIT License
371 stars 97 forks source link

ADC2 problems with LAN activated #83

Closed sergionaf closed 2 years ago

sergionaf commented 2 years ago

When using the ADC2 port 39 with a sinusoidal signal many errors in the mesure occur if the LAN is activated.

Steps to Reproduce

Using this code, the graph of signal in Serial Plotter is displayed like a charm

void setup() {
Serial.begin(115200);
pinMode(39,INPUT);
}
void loop() {
Serial.println(analogRead(39));
delay(51);
}

Expected behavior

sem eth io39

With a simple code to activate the LAN

#include <ETH.h> // quote to use ETH

#define ETH_ADDR        1
#define ETH_POWER_PIN   16//-1 //16 // Do not use it, it can cause conflict during the software reset.
#define ETH_POWER_PIN_ALTERNATIVE 16 //17
#define ETH_MDC_PIN    23
#define ETH_MDIO_PIN   18
#define ETH_TYPE       ETH_PHY_LAN8720
#define ETH_CLK_MODE    ETH_CLOCK_GPIO0_IN 

// ******************************** INICIALIZA ETH ********************************
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case SYSTEM_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default:
      break;
  }
} // ********************************  FIM INICIALIZA ETH ********************************

// ******* setup ******

void setup() {

  Serial.begin(115200);

  pinMode(39,INPUT);

  // ******* Setup ETH *******
  pinMode(ETH_POWER_PIN_ALTERNATIVE, OUTPUT);
  digitalWrite(ETH_POWER_PIN_ALTERNATIVE, HIGH);
  //WiFi.onEvent(WiFiEvent);
  ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE); // Enable ETH
  //ETH.config(local_ip, gateway, subnet, dns1, dns2); // Static IP, leave without this line to get IP via DHCP
  //  while(!((uint32_t)ETH.localIP())){}; // Waiting for IP (leave this line group to get IP via DHCP)
  // ******* Fim Setup ETH *******

  //Serial.println(ETH.localIP());

}

void loop() {
Serial.println(analogRead(39));
delay(51);
}

Actual behavior

The curve on graph has several parts with noise

com eth io39

Information

Please ensure to specify the following:

khoih-prog commented 2 years ago

Hi @sergionaf

This has nothing to do with this library. Please post next time on the correct place, such as ESP32 core to save us some time.

Possible some hints for you at HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE) as ETH and WiFi share code.