The ESP8266 is by far my favorite Arduino board, the fact you can get $3 board with built in WiFi still blows my mind!
I've worked with them a lot for the last 18 months or so, and in this instructable I'm going to share 5 quirks I've come across to working with them.
Lets get to it!
Step 1: Check Out the Video
I made a two minute video covering everything in this instructable, check it out!
Step 2: Quirk 1: Phantom WiFi
If you do not specify any WiFi configuration in your sketch, your ESP8266 will still try connect using the last WiFi configurations.
To test this out:
- Write a sketch that has WiFi configurations and lights an LED when its connected. Flash it to the board and test
- Now comment out all WiFi configurations, but leave in the part where it will light up the LED when connected. Flash it to the board, the LED will still light up
Not configuring the WiFi in your sketch is actually a good bit faster (this is shown in real time in the video) so if you are trying to connect to the WiFi as quick as possible it might be worth trying out.
If you don't want to use WiFi in your sketch you can set WiFi.mode(WIFI_OFF); to turn off the WiFi
Step 3: Quirk 2: Analog Write Intensity
AnalogWrite is the method you use when you want to set the PWM value of a pin on an Arduino, and it doesn't work quite the same on an ESP8266. If you research AnalogWrite for Arduino online you will get the max value you can use is 255.
If you write a sketch where you DigitalWrite one pin HIGH and AnalogWrite another pin 255, you can see in the second picture that on the ESP8266 the Analog written LED is significantly dimmer, while with the Nano the two LEDs are the same
This is because the max value for AnalogWrite with the ESP8266 is 1023
Step 4: Quirk 3: AnalogWrite Persistance
If you write a blink sketch where you digitalWrite LOW and AnalogWrite a value, you would expect the LED to blink. And it does on normal Arduinos but not on the ESP8266. There is a bug with the current released version of the ESP8266 Arduino core, if you AnalogWrite to a pin, you need to AnalogWrite(PIN, 0); before you can DigitalWrite again
This is fixed in the Release Candidate of the ESP8266 core.
Step 5: Quirk 4: Pin Identity Crisis
One thing that can be confusing about working with ESP8266 is the pin numbers is that some boards have them labeled differently.
In the pictures I write a blink sketch using pin 5 but when I have an LED plugged into D5 the led does not work, but when I plug it into D1 it works ok.
The reason why is that NodeMCU and Wemos boards have a custom pin label compared to the generic ESP8266 boards.
The easiest way to get around this is to use the name of the pin that appears on your board (as per the last picture)
Step 6: Quirk 5: Boot Mode Pins
The ESP8266 has some pins that if configured on startup can be used to enable different boot modes, these pins are:
0 (D3), 2 (D4) and 15 (D8)
If you have devices connected to these pins and your ESP8266 is not booting up, you may be accidentally enabling a boot mode
Step 7: Conclusion
These were some of the quirks I came across while using the ESP8266, hopefully you find some of the useful!
If you have any quirks that you would like to share please let us know in the comments!