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.