There’s only one analog input pin, labeled ADC. To read the ADC pin, make a function call
to analogRead(A0). Remember that this pin has a weird maximum voltage of 1V – you’ll get a
10-bit value (0-1023) proportional to a voltage between 0 and 1V.
Yielding
This is one of the most critical differences between the ESP8266 and a more classical
Arduino microcontroller. The ESP8266 runs a lot of utility functions in the background –
keeping WiFi connected, managing the TCP/IP stack, and performing other duties. Blocking
these functions from running can cause the ESP8266 to crash and reset itself. To avoid these
mysterious resets, avoid long, blocking loops in your sketch.
If you have a long loop in your sketch, you can add a delay([milliseconds]) call within, to allow
the critical background functions to execute. The ESP8266’s delay() funciton, while of course
delaying for a set number of milliseconds, also makes a quick call to the background
functions.
The amazing creators of the ESP8266 Arduino libraries also implemented a yield() function,
which calls on the background functions to allow them to do their thing. As an example, if your
sketch is waiting for someone to press a button attached to pin 12, creating a loop like this will
keep the ESP8266 from crashing:
COPY CODE
pinMode(12, INPUT_PULLUP); // Set pin 12 as an input w/ pull-upwhile (digitalRead(12) == HIGH) // While pin
12 is HIGH (not activated)
yield(); // Do (almost) nothing -- yield to allow ESP8266 background functions
Serial.println("Button is pressed!"); // Print button pressed message.
ESP8266WiFi Class
This is the ESP8266, so the WiFi class will probably be included in just about every sketch
there is. If you’ve used the Arduino WiFi library before, the ESP8266 WiFi library will be very
similar, there’s just a few key differences:
• To include the ESP8266 WiFi library call #include <ESP8266WiFi.h> not <WiFi.h>.
• To connect to a network, like the normal WiFi library, call WiFi.begin(NetworkSSID,
NetworkPassword). You can also set the ESP8266 up as a WiFi access point by
calling WiFi.softAP(AP_SSID, AP_Password).
• To set the ESP8266’s mode, which can be access point (AP), station (STA), or combo
(the ESP8266 can do both at the same time!), call WiFi.setMode([mode]) with
either WIFI_AP, WIFI_STA, or WIFI_STA_AP as the parameter.
The examples earlier in this tutorial should have demonstrated all of these differences.
Libraries Available/Not Available and the Differences
A lot of the core Arduino libraries have been re-written to work for the ESP8266, including: