EasyManuals Logo

Espressif ESP8266 User Manual

Espressif ESP8266
51 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #21 background imageLoading...
Page #21 background image
D. Input/Output: GPIO pins
Now that we can talk to our microcontroller over the serial line it is time to interact with the
real world. Our ESP8266 is equipped with several so-called General Purpose Input Output or
in short GPIO pins. They can be used for many different applications such as sensing and
generating digital signals of the 3.3 Volt range. This is important if you plan to use an external
component with your ESP8266: hardware designed for older Arduinos often uses the 5V
(CMOS) range. Using such a device without a logic level shifter might destroy your ESP8266.
Using a GPIO pin is quite easy: first you tell the microcontroller if you want to read or write
from the pin. Then you do it. Here is the code for reading:
pinMode(PIN, INPUT);
int state = digitalRead(PIN);
Unless you want to change the mode of a pin you only need to call pinMode() once. Please
note that depending on the pin you can also use INPUT_PULLUP or INPUT_PULLDOWN.
Writing to a pin is not much different:
pinMode(PIN, OUTPUT);
digitalWrite(PIN, HIGH);
//
or
digitalWrite(PIN, LOW);
The second statement will show a HIGH level on PIN which will be 3.3V. The third statement
will set the pin to LOW which is 0V.
What values for PIN can you use? If you are using a generic ESP8266 module (not a NodeMCU)
your pins will be labeled GPIO0, GPIO1, etc. To use pin GPIO0 you would write digitalWrite(0,
HIGH); If you are using a NodeMCU things get a little bit more complicated. The original
creators of the NodeMCU LUA firmware and the development module of the same name had
the idea to give the pins different names. They are called D0, D1, etc. That by itself would not
be confusing yet but they are not using the same digits, e.g. GPIO1 is not equal to D1. Here
is a table to map the pins:
Raw Module Name
NodeMCU &
Wemos Name
Raw Module Name
NodeMCU &
Wemos Name
GPIO0
D3
GPIO9
D11
GPIO1
D10
GPIO10
D12
GPIO2
D4
GPIO11
N/A
GPIO3
D9
GPIO12
D6
GPIO4
D2
GPIO13
D7

Other manuals for Espressif ESP8266

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Espressif ESP8266 and is the answer not in the manual?

Espressif ESP8266 Specifications

General IconGeneral
Digital I/O Pins17
Analog Input Pins1
Wi-Fi802.11 b/g/n
Operating Voltage3.0V - 3.6V
Clock Speed80 MHz / 160 MHz
Operating Temperature-40°C to 125°C
Dimensions24mm x 14mm
ProcessorTensilica L106 32-bit micro controller

Related product manuals