Wemos d1 r2 losing sketch after power cycle

I am trying to get a basic button sketch to work on my wemos d1. However, I seem to lose my sketch after every power cycle. It doen’t matter if I connect my wiring to the board, or try to blink the onboard LED with nothing attached.

My button wiring works after I flash the sketch to the wemos, however if I disconnect and connect the usb power I lose the sketch. Also, after flashing a sketch to the board the board disconnects itself from the COM port on my pc.

I am using the arduino environment (1.8.1) to program and flash the board.

I think I have to put my board in a different mode after flashing the sketch to it. It has something to do with this:

| GPIO15 | | GPIO0 | | GPIO2 | | Mode |
| - | - | - | - |
| 0V | | 0V | | 3.3V | | Uart Bootloader |
| 0V | | 3.3V | | 3.3V | | Boot sketch |
| 3.3V | | X | | X | | SDIO mode (not used for Arduino) |

But which mode do I have to put the board in after flashing a sketch to it? And more importantly, how do I do this? I tried connecting GPIO 0 to the 3.3v out pin, however this just switches off the board. One would say this can’t be a shortcircuit, because GPIO0 has a 10k pull up resistor.

My code is as follows:

// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = D5; // the number of the pushbutton pin
const int ledPin = D0; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {

  • // initialize the LED pin as an output:*
  • pinMode(ledPin, OUTPUT);*
  • // initialize the pushbutton pin as an input:*
  • pinMode(buttonPin, INPUT);*
    }
    void loop() {
  • // read the state of the pushbutton value:*
  • buttonState = digitalRead(buttonPin);*
  • // check if the pushbutton is pressed.*
  • // if it is, the buttonState is HIGH:*
  • if (buttonState == HIGH) {*
  • // turn LED on:*
  • digitalWrite(ledPin, HIGH);*
  • } else {*
  • // turn LED off:*
  • digitalWrite(ledPin, LOW);*
  • }*
    }

The wiring diagram is attached. Fritzing doesn’t have a regular D1 as an option, so I used a mini. The idea is the same though. Power is provided through usb.

If this isn’t the right place for questions regarding an ESP8266 boards, please tell me.

When I programmed my wemos I did not change any modes - I'm guessing the IDE took care of that . Have a look at the 8266 programming , on that you have to set the pins correctly - might help you, the Wemos page or its forum might help too

I found this :after some debugging with @jpmens we discovered this was caused by Windows it seems - as soon as I unplug/re-plug the Wemo into my Windows laptop it resets the device back into config mode - if I flash the Wemo, un-plug and plug into a wall wart, it boots up fine. This can be repeated with no issues.

As soon as I plug the Wemo back into my Windows laptop, it is reset and reverts back to config mode.

Very odd, but I don't think this is a Homie issue so I will close this issue.

Sounds like your problem, the cure in this case was an updated ch340 driver : http://www.arduined.eu/ch340-windows-8-driver-download/

Thanks for replying. It seems I already have the newest driver, I also lose my sketch when I connect a battery to the input jack.

I am really starting to think my board is faulty. I'll take a further look into 8266 programming, and maybe post on the wemos forum. But this one is probably faulty, might be the pull up resistor on GPIO0 now that I think about it. Everytime I use that one the board shuts down, never payed much mind to it. But that might be it. Oh well, I will receive an arduino plus wifi shield this week or next week. So then I can continue my project :D

Hey, have you ever figure this out? I have the same issue with my WeMos. Any help will be greatly appreciated.