Editing
esp
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==ESP Pins (general)== {| class="wikitable" |- ! Label ! GPIO ! Input ! Output ! Notes |- | D0 | GPIO16 | no interrupt | no PWM<br>or I2C support | <span style="color: white; background: green">HIGH at boot</span><br>used to wake up from deep sleep |- | D1 | GPIO5 | <span style="color: white; background: green">OK</span> | <span style="color: white; background: green">OK</span> | often used as <span style="color: white; background: teal">SCL</span> (I2C) |- | D2 | GPIO4 | <span style="color: white; background: green">OK</span> | <span style="color: white; background: green">OK</span> | often used as <span style="color: white; background: teal">SDA</span> (I2C) |- | D3 | GPIO0 | pulled up | <span style="color: white; background: green">OK</span> | connected to FLASH button,<br>boot fails if pulled LOW |- | D4 | GPIO2 | pulled up | <span style="color: white; background: green">OK</span> | <span style="color: black; background: orange">HIGH at boot</span><br>connected to on-board LED,<br>boot fails if pulled LOW |- | D5 | GPIO14 | <span style="color: white; background: green">OK</span> | <span style="color: white; background: green">OK</span> | <span style="color: white; background: blue">SPI</span> (SCLK) |- | D6 | GPIO12 | <span style="color: white; background: green">OK</span> | <span style="color: white; background: green">OK</span> | <span style="color: white; background: blue">SPI</span> (MISO) |- | D7 | GPIO13 | <span style="color: white; background: green">OK</span> | <span style="color: white; background: green">OK</span> | <span style="color: white; background: blue">SPI</span> (MOSI) |- | D8 | GPIO15 | pulled to GND | <span style="color: black; background: yellow">OK</span> | <span style="color: white; background: blue">SPI</span> (CS)<br>Boot fails if pulled HIGH |- | RX | GPIO3 | <span style="color: black; background: yellow">OK</span> | <span style="color: white; background: red">RX pin</span> | <span style="background: orange">HIGH at boot</span> |- | TX | GPIO1 | <span style="color: white; background: red">TX pin</span> | <span style="color: black; background: yellow">OK</span> | <span style="background: orange">HIGH at boot</span><br>debug output at boot,<br>boot fails if pulled LOW |- | A0 | ADC0 | Analog Input | <span style="color: white; background: red">X pin</span> | |} GPIO6 to GPIO11 are not recommended to use.<br> GPIO4 and GPIO5 are the most safe to use GPIOs if you want to operate relays.<br> You can read [http://rabbithole.wwwdotorg.org/2017/03/28/esp8266-gpio.html this article] that investigates the state and behavior of each GPIO on boot.<br> [[Wemos_D1_Mini#Pins:|Wemos D1 Mini pinout]]<br> {{template:toponly}} ===Analog Input=== The ESP8266 only supports analog reading in ADC0 and it is usually marked on the silkscreen as A0. The maximum input voltage of the ADC0 pin is 0 to 1V if you’re using the ESP8266 bare chip. If you’re using a development board like the ESP8266 12-E NodeMCU kit, the voltage input range is 0 to 3.3V because these boards contain an internal voltage divider. You can learn how to use analog reading with the ESP8266 with this guide:<br> [https://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/ ESP8266 ADC – Read Analog Values with Arduino IDE, MicroPython and Lua] {{template:toponly}} ===On-board LED=== LED_BUILTIN<br> Most of the ESP8266 development boards have a built-in LED. This LED is usually connected to GPIO2 (D4 on the Wemos D1 Mini).<br> [[File:ESP8266-NodeMCU-kit-12-E-on-board-LED.jpg|200px]]<br clear=all> {{template:toponly}} ===RST Pin=== When the RST pin is pulled LOW, the ESP8266 resets. This is the same as pressing the on-board RESET button.<br> [[File:ESP8266-NodeMCU-kit-12-E-RESET-ENABLE-button.jpg|200px]]<br clear=all> {{template:toponly}} ===GPIO0=== When GPIO0 is pulled LOW, it sets the ESP8266 into bootloader mode. This is the same as pressing the on-board FLASH/BOOT button.<br> [[File:ESP8266-NodeMCU-kit-12-E-FLASH-BOOT-button-1.jpg|200px]]<br clear=all> {{template:toponly}} ===I2C=== The ESP8266 doesn’t have hardware I2C pins, but it can be implemented in software. So you can use any GPIOs as I2C. Usually, the following GPIOs are used as I2C pins: GPIO5: SCL GPIO4: SDA {{template:toponly}} ===SPI=== The pins used as SPI in the ESP8266 are: GPIO12: MISO GPIO13: MOSI GPIO14: SCLK GPIO15: CS {{template:toponly}} ===PWM Pins=== ESP8266 allows software PWM in all I/O pins: GPIO0 to GPIO16. PWM signals on ESP8266 have 10-bit resolution. {{template:toponly}} ===Interrupts=== ====Pins==== The ESP8266 supports interrupts in any GPIO, except GPIO16 (D0).<br> ====setup()==== Attach the interrupt pin to the handler in setup: attachInterrupt(START_PIN, startButtonHandler, RISING); ====ISR tips==== The ESP expects handlers to be stored in the IRAM space, or you will get an error and reboot: ISR not in IRAM! Just add a compiler directive and your interrupt handler will work just fine. <nowiki>volatile bool interruptReceived= false; IRAM_ATTR void handleInterrupt() { interruptReceived = true; }</nowiki> ;Example <nowiki>IRAM_ATTR void limitSwitchHandler() { { static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); // If interrupts come faster than 200ms, assume it's a bounce and ignore if (interrupt_time - last_interrupt_time > 200) motorState = !motorState; //Limit switch is closed, stop the motor } last_interrupt_time = interrupt_time; }</nowiki> ====Debounce ISR==== <nowiki>void my_interrupt_handler() { static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); // If interrupts come faster than 200ms, assume it's a bounce and ignore if (interrupt_time - last_interrupt_time > 200) { ... do your thing } last_interrupt_time = interrupt_time; }</nowiki> {{template:top}}
Summary:
Please note that all contributions to Notebook may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Notebook:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Home Page
C++ Reference
ESP Hardware
ESPHome
Home Assistant
Network Stuff
Tools
What links here
Related changes
Special pages
Page information