Wemos D1 Mini stalled: Failed to connect to ESP8266: Timed out waiting for packet header

Hi there. I bought some Wemos D1 Mini from a supplier a few weeks ago. They worked fine at the beginning and one day to the other they simply stopped working. I got a refund from the supplier and got 2 new different Wemos D1 mini that also worked for a few days and suddenly they stopped working too.
When I say they stopped working I mean I couldn't upload data and the following error eventually appeared "Failed to connect to ESP8266: Timed out waiting for packet header". I gave up and change my supplier, and got a new Wemos D1 and it also crashed (with the same behaviour as the last 4 boards) just 2 uploads after I opened it.
I think I've tried everything: Pulling down D4, Pulling up/down D3, Pulling Up/Down D0. I've changed and rechanged every setting in the Arduino IDE Tools. I've reinstalled the CH340 driver, added the json link to Preferences Tab, installed a buch of differerent ESP8266 versions from ESP8266 Community in the Boards Manager. Some things have worked just once or with and specific board and then stopped, like pulling DOWN D3 worked like 3 uploads with one of the first 2 boards i got and never worked again.
I know it's not a hardware error because sometimes, just SOMETIMES (like once a day if i spend at least 4 hours trying to get them working) they do upload and execute the code right until i try to upload again or unplug de USB cable.

I know it's not my computer because I've try two different PCs and it's not the USB cable because I use 2 different Micro USB cables of different brands and they both work smoothly with the ESP32 DEVKIT V1 I have.

Currently, the last board I got works partially (meaning it can print on the Serial Monitor but i think the pins are not working correctly) when I connect the 3.3V to de D4.

Finally, if anyone of you has a similar problem, you might try this weird thing i noticed: if you try to run the code that is already on the board while it's acting out, and you change the Serial Monitor Baud rate to specifically 74880 baud. It prints really weird text like "epc1=0x4017f8fc, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000". I've tried using the all kinds of text it prints to debug using old forums but nothing works.
To this point I'd try to guess something, but I'm pretty sure I've tried everything. It seems to me like the stalling it's random hence impossible to predict. But anyway, I thought I might ask here to see what happens.

Thanks for reading and good luck

See if this thread solves your problem:

Hi there! Thank you @docdoc for taking the time. I saw this response a few days ago, and just tried it again and it still doesn't work. I'm not quite sure whether "Reset board in flash mode" means just pressing the Reset button while the Wemos is plugged in or when my computer is trying to upload code into it. But either way I just tried both and they do not make a difference.

Post here the first code you load into the ESP8266.

If this happened on 4 different boards it looks like either a faulty batch (I'd try to get one from another seller) or something with your project and/or hardware.

I have now some questions:
First of all, have you ever tried to upload your code making sure you don't have anything connected to the board?
What are the connections of your project (a diagram could help us a bit)?
And are you sure you haven't damaged the board (e.g. with bad voltages/currents)?
And if you still have the code you uploaded last (the one that worked fine at first) can you post it here, as @ruilviana correctly asked?

Hey guys. Yep. I actually have nothing connected to the board while I’m doing trials. And as i have 5 boards, 1 of them from a different seller than the other 4, I figured I have to be doing something wrong.
Currently all boards have a blank sketch and upload continues to fail.
The last board a i got, the one from the different seller crashed (failed to upload) immediately after i wired and run the Full Example for a Neo 6M GPS


#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
/*
   This sample code demonstrates the normal use of a TinyGPSPlus (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = D1, TXPin = D2;
static const uint32_t GPSBaud = 9600;

// The TinyGPSPlus object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(9600);
  ss.begin(GPSBaud);

  Serial.println(F("FullExample.ino"));
  Serial.println(F("An extensive example of many interesting TinyGPSPlus features"));
  Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP  Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("           (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printFloat(gps.hdop.hdop(), gps.hdop.isValid(), 6, 1);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);

  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

The wiring was standard and hence I’m out for the week i cannot provide a schematic, but is something like:
WEMOS | GPS
3.3V to VCC
G to GND
D1 to TX
D2 to RX

The GPS ran fine and worked smoothly until I tried to upload a new version of the code that also used ESP-NOW. That code was never actually uploaded so then on, the board got a blank sketch (as mentioned, they SOMETIMES work idk why, so i managed to upload a blank sketch) and no wiring.

It’s worth mentioning that not all boards have crashed after being connected to the GPS. Another one of them was connected to a SX1278 LoRa module and crashed the same way, so im pretty skeptical about the GPS AND the LoRa being the reason.
Anyway, you guys let me know what you think.

Thank you!

Oh! I forgot to mention:

A basic ESP-NOW sketch was also tried before the GPS sketch and also worked smoothly.
The upload i did after the GPS sketch (the one that failed) was while the WEMOS was all wired to the GPS. I understand that might have crashed that specific upload but I don’t know if that can permanently damage the board and prevent further uploads.

Answering the questions about if I might have damage the board with bad voltages or current…I thought about that and I have 3 justifications for why I think thats not the case.

  1. I powered all 5 boards with the Micro USB port
  2. It’s hard to believe i managed to burn all 5 boards!
  3. The boards SOMETIMES do work with specific wiring (D4 Pull Up for example) or just do so randomly (i think, i haven’t found a pattern yet). Those specific wirings work for a specific board and usually doesn’t last more than 4 uploads (maybe depending on the last sketch uploaded? It’s hard to tell right now, but i think they should work just fine no matter the last sketch uploaded)

I see nothing special in both your code and description, so I'm sorry I have no idea at the moment.

That's normal, that's a specific speed for ESP bootloader output info.
But does it come out also on "defective" boards? I'm curious, could you copy/paste here the full Serial Monitor output when you boot a D1?

Ok, I'm just trying to help you, but as I have never encountered such issue (I already used a bunch of D1 Mini around...), could you copy/paste here both the output (the full printouts over serial with 74880 baud when you turn D1 on, and the one when trying to upload something)?
One more thing, what IDE version are you using, what OS, and what is the boards manager URLs you have set on Preferences?

Don't think so.