从Arduino IDE上传到ESP8266时出错

问题描述 投票:0回答:1

我试图从Arduino IDE将代码上传到esp8266,它给了我这个错误:

   esptool.py v2.8
    Serial port COM6
    Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
      File "C:\Users\arcae_000\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3/tools/upload.py", line 65, in <module>
        esptool.main(cmdline)
      File "C:/Users/arcae_000/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool\esptool.py", line 2890, in main
        esp.connect(args.before)
      File "C:/Users/arcae_000/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool\esptool.py", line 483, in connect
        raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

我在Arduino IDE上安装了esp8266扩展板,并将其设置为'Generic ESP8266 Module'。我尝试更改上传速度,但仍然失败。这是我使用的代码:

#include <ESP8266WiFi.h>

const char* ssid = "SSID";//type your ssid
const char* password = "PASSWORD";//type your password

int ledPin = 2; // GPIO2 of ESP8266
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);


  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // Match the request

  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  } 
  if (request.indexOf("/LED=OFF") != -1){
    digitalWrite(ledPin, LOW);
    value = LOW;
  }

// Set ledPin according to the request
//digitalWrite(ledPin, value);


  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");

  client.print("Led pin is now: ");

  if(value == HIGH) {
    client.print("On");  
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 2 ON<br>");
  client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 2 OFF<br>");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}

(我已经更改了SSID和密码值)我已经搜索了所有可以找到的网站,但仍然无法修复。 esp8266处于闪存模式。另外,我知道esp8266没有损坏。我将不胜感激。

arduino esp8266 arduino-ide arduino-esp8266
1个回答
0
投票

您可以发布上传设置吗?

可能出问题的地方:

  • 您可能有一个NODEMCU模块,请尝试在上传设置中切换到该板。

  • 您是否在插入ESP时确认出现新的COM端口?

  • 您是否选择了正确的COM端口?

这些是我的ESP8266设置,here

如果您实际上有一个NODEMCU,如果上面没有任何作用,请尝试使用所有这些说明来更新固件:https://github.com/nodemcu/nodemcu-firmware

© www.soinside.com 2019 - 2024. All rights reserved.