V. flashing an ESP8266¶
preparing the ArduinoIDE¶
At the ESP8266 github page are some information, how to prepare the ArduinoIDE to be able to flash chips from the ESP8266 family.
To do so just open the Preferences
and add the Additional Boards Manager URL : https://arduino.esp8266.com/stable/package_esp8266com_index.json
In the Boards Manager search for the ESP8266
and click install
After installing, there are a lot of different ESP8266 board variants available.
I use a NodeMCU 1.0 (ESP-12E Module
, so I choose this one.
wiring up¶
Similar to my echo hello-world board, I used a LED and a button.
The LED
is connected to D6
and GND
and the push button
is connected to D3
and GND
programming¶
The program code is also similar to the echo hello-world board. I adapted the code to the ESP8266 and changed the led and the buttonpin.
int buttonPin = D3; // the number of the pushbutton pin
int ledPin = D6; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
int lastState = 0; // is the LED on or off
void setup() {
Serial.begin(9600);
Serial.println("Hello, world");
Serial.println("start sensing");
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == LOW && lastState == 0) {
// turn LED on:
digitalWrite(ledPin, HIGH);
lastState = 1;
Serial.println("LED ON");
// delay(100);
} else if (buttonState == LOW && lastState == 1){
// turn LED off:
digitalWrite(ledPin, LOW);
lastState = 0;
Serial.println("LED OFF");
// delay(100);
}
delay(250);
}
Because of the hardware serial, the <SoftwareSerial.h>
library is not needed here.
This is the ArduinoIDE output after uploading the sketch
Testing¶
works