ESP8266 Support WIKI

User Tools

Site Tools


esp8266_gpio_pin_allocations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
esp8266_gpio_pin_allocations [2015/07/06 21:28]
tytower [UART pins]
esp8266_gpio_pin_allocations [2017/11/10 02:18] (current)
ekriirke [Pin Functions]
Line 1: Line 1:
-===== Basic Wiring functions =====+====== Basic Wiring functions ​======
  
 pinMode(), digitalRead(),​ digitalWrite(),​ analogWrite() work as usual. pinMode(), digitalRead(),​ digitalWrite(),​ analogWrite() work as usual.
Line 10: Line 10:
 from reversed voltages with diodes. from reversed voltages with diodes.
  
-GPIO0-GPIO15 can be INPUT, OUTPUT, ​INPUT_PULLUP,​ and INPUT_PULLDOWN.\\  +At startup, pins are configured as INPUT.\\ 
-GPIO16 can be INPUT, OUTPUT or INPUT_PULLDOWN. It is also XPD for deepSleep() (Perhaps ​via a small capacitor.)+GPIO0-GPIO15 can be INPUT, OUTPUT, ​or INPUT%%_%%PULLUP.\\  
 +GPIO16 can be INPUT, OUTPUTor INPUT%%_%%PULLDOWN_16. It is also XPD for deepSleep() (perhaps ​via a small capacitor.)\\ 
 +Note that GPIO6-GPIO11 are typically used to interface with the flash memory ICs on most esp8266 modules, so these pins should not generally be used.
  
 +analogRead(A0) reads the value of the ADC channel connected to the TOUT pin.
 +
 +===== Analog ADC =====
  
-analogRead(A0) reads the value of the ADC channel connected to the TOUT pin .\\  
  
-Analog ADC 
 ESP8266EX also integrates a generic purpose 10-bit analog ADC. The ADC range is from 0V to ESP8266EX also integrates a generic purpose 10-bit analog ADC. The ADC range is from 0V to
 1.0V. It is typically used to measure the voltages from the sensor or battery status. The ADC 1.0V. It is typically used to measure the voltages from the sensor or battery status. The ADC
-cannot be used when the chip is transmitting. Otherwise the voltage may be inaccurate.(From Expressif datasheet CH 8.5)+cannot be used when the chip is transmitting. Otherwise the voltage may be inaccurate. (From Expressif datasheet CH 8.5)
    
 {{:​essp8266_adc.png|}}\\ ​ {{:​essp8266_adc.png|}}\\ ​
  
-===Interupts=== +==== Interrupts ​==== 
-Pin interrupts are supported through attachInterrupt(),​ detachInterrupt() functions. Interrupts may be attached to any GPIO pinexcept GPIO16. Standard Arduino interrupt types are supported: CHANGE, RISING, FALLING.+ 
 +Pin interrupts are supported through attachInterrupt(),​ detachInterrupt() functions. Interrupts may be attached to any GPIO pin except GPIO16, but since GPIO6-GPIO11 are typically used to interface with the flash memory ICs on most esp8266 modules, applying interrupts to these pins are likely to cause problems. Standard Arduino interrupt types are supported: CHANGE, RISING, FALLING.
    
 ==== PWM ==== ==== PWM ====
  
-analogWrite(pin,​ value) enables software PWM on the given pin. PWM may be used on pins 0 to 15. Call analogWrite(pin,​ 0) to disable PWM on the pin. value may be in range from 0 to 1023. +analogWrite(pin,​ value) enables software PWM on the given pin. PWM may be used on pins 0 to 15. Call analogWrite(pin,​ 0) to disable PWM on the pin. Value may be in range from 0 to 1023. 
-0 to 255 is normal on an arduino ​board as its an 8bit ADC  but ESP8266 ​is 10 bit so 1023 is full duty cycle.+0 to 255 is normal on an Arduino ​boardas it'​s ​an 8 bit register, ​ but ESP8266 ​uses software PWM so 1023 is full duty cycle.
  
 ===== Pin Functions ===== ===== Pin Functions =====
Line 36: Line 40:
  
  ​SPECIAL maps to:  ​SPECIAL maps to:
-  * 0. CLK_OUT+  * 0. CLK%%_%%OUT
   * 1. TX0   * 1. TX0
   * 2. TX1   * 2. TX1
   * 3. RX0   * 3. RX0
-  * 4. CLK_XTAL +  * 4. CLK%%_%%XTAL 
-  * 5. CLK_RTC +  * 5. CLK%%_%%RTC 
-  * 12. SPI_MISO +  * 12. SPI%%_%%MISO 
-  * 13. SPI_MOSI +  * 13. SPI%%_%%MOSI 
-  * 14. SPI_CLK +  * 14. SPI%%_%%CLK 
-  * 15. SPI_SS+  * 15. SPI%%_%%SS
  
-You can activate any "​FUNCTION_"​ with pinMode(pin,​ FUNCTION_1)for example\\ ​+You can activate any "​FUNCTION_"​ with pinMode(pin,​ FUNCTION_1) for example
 + 
 +Note: Func number 1-5 in Expressif table corresponds to FUNCTION 0-4 in SDK\\ 
 +http://​bbs.espressif.com/​download/​file.php?​id=442
  
 {{:​pin_functions.png|}} {{:​pin_functions.png|}}
  
- ESP8266 has three modes of operation: SDIO mode, UART mode and FLASH mode. These are obtained by pulling three pins either high or low at bootupGPIO15 ​ GPIO0  GPIO2  according to this table +ESP8266 has three modes of operation: SDIO mode, UART mode and FLASH mode. These are obtained by pulling three pins either high or low at bootupGPIO15GPIO0GPIO2  according to this table
-0 Low1 High  x floating+ 
 +0 Low\\ 
 +1 High\\ 
 +x floating
  
 ^  MODE            ^GPIO15 ​            ​^GPIO0 ​          ​^GPIO2 ​ | ^  MODE            ^GPIO15 ​            ​^GPIO0 ​          ​^GPIO2 ​ |
-^SDIO            | 1                 | x              | x       | +^SDIO  ​(BootSDCard) ​         ​| 1                 | x              | x       | 
-^UART            | 0                 | 0              | x or 1  | +^UART  ​(UploadCode) ​         ​| 0                 | 0              | x or 1  | 
-^FLASH (DEFAULT) | 0                 | 1              | x or 1  | Running Mode  ​\\ +^FLASH (NormalRunning) | 0                 | 1              | x or 1  |   ​\\ 
  
-__Note__ ​:-  GPIO2 It is considered safer to pull it high with a resitor ​on boot rather than leave it floating to avoid possible chip damage if pin is pulled high by your program but I use it as a general IO pin .\\  +__Notes__ ​:-  GPIO2 It is considered safer to pull it high with a resistor ​on boot rather than leave it floating to avoid possible chip damage if pin is pulled high by your program but also see [[http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524|http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524]].  ​GPIO1 (UART TX) also has an effect on boot  if pulled low; it will not boot in this case.
    
-FLASH mode is when running the program. Take GPIO0 high or float  or it will stall on first reset,​intentional or not\\  +FLASH mode is when running the program. Take GPIO0 high or float  or it will stall on first reset, intentional or not.
- +
-UART mode is how the code is uploaded to the chip and GPIO0 must be low on boot to enter this mode .\\  +
- +
-SDIO mode is where the chip boots from an SD card. I dont think this is available to us yet \\     +
-   +
  
 +UART mode is how the code is uploaded to the chip and GPIO0 and GPIO15 must be low on boot to enter this mode.
  
 +SDIO mode is where the chip boots from an SD card. I don't think this is available to us yet.
  
 ===== UART pins ===== ===== UART pins =====
Line 86: Line 93:
 </​code>​ </​code>​
  
-original ​func: +Original ​func:\\ 
-U0TXD=>​pin:​U0TXD +U0TXD=>​pin:​U0TXD\\ 
-U0RXD=>​pin:​U0RXD +U0RXD=>​pin:​U0RXD\\ 
-U0CTS=>​pin:​MTCK +U0CTS=>​pin:​MTCK\\ 
-U0RTS=>​pin:​MTDO+U0RTS=>​pin:​MTDO\\
  
-after pin swap: +After pin swap:\\ 
-U0TXD=>​pin:​MTDO  +U0TXD=>​pin:​MTDO\\ 
-U0RXD=>​pin:​MTCK +U0RXD=>​pin:​MTCK\\ 
-U0CTS=>​pin:​U0RXD+U0CTS=>​pin:​U0RXD\\
 U0RTS=>​pin:​U0TXD U0RTS=>​pin:​U0TXD
  
Line 101: Line 108:
  
  
-kolban asserts:"​ The device writes to UART1 by itself in certain circumstances.+kolban asserts: "The device writes to UART1 by itself in certain circumstances.
 First, when you flash the device, the data received is apparently also written to the TX pin of UART1 (GPIO2). First, when you flash the device, the data received is apparently also written to the TX pin of UART1 (GPIO2).
-Second, the "debug" ​code in the device writes its output to UART1." ​\\  ​If anyone has a reference for this please post it on the thread [[http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524|http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524]]+Second, the 'debug' ​code in the device writes its output to UART1."​ 
 + 
 +If anyone has a reference for this please post it on the thread [[http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524|http://​www.esp8266.com/​viewtopic.php?​f=6&​t=3862&​p=22524#​p22524]] 
 ===== LED Pin ===== ===== LED Pin =====
-GPIO1 which is also TX is wired to the blue LED on many devices. ​ Note that the LED is active low (conected ​to Vcc and sinks through the chip to ground) so setting a logical value of 0 will light it up.  Since GPIO1 is also the TX pin, you won't be able to blink the LED and perform Serial communications at thew same time unless you switch TX/RX pins.+ 
 +GPIO1which is also TXis wired to the blue LED on many devices. ​ Note that the LED is active low (connected ​to Vcc and sinks through the chip to ground) so setting a logical value of 0 will light it up.  Since GPIO1 is also the TX pin, you won't be able to blink the LED and perform Serial communications at the same time unless you switch TX/RX pins.   
 +Note that if this pin is pulled LOW on power up, the ESP will not boot. (The normal LED is from Vcc to IO1, an LED from GND to IO1 is enough to prevent boot)
  
 ===== Maximum Current ===== ===== Maximum Current =====
-When using a GPIO as output (i.e. to drive something such as an LED) it is important to note that the maximum output current is 12mA. (I<​sub>​MAX</​sub>​=12mA per Expressif ​datasheet) + 
- If you try and output more current than that, you run the risk of damaging the device. ​ Since many LEDs are able to draw 20mA you should adjust your current limiting resistor to be 12mA or less.  Using [[https://​en.wikipedia.org/​wiki/​Ohm'​s_law|Ohms law]] - R=V/I so 3.3V at 12mA = 275Ω min so use 330Ω or higher.+When using a GPIO as output (i.e. to drive something such as an LED) it is important to note that the maximum output current is 12mA. (I<​sub>​MAX</​sub>​=12mA per Espressif ​datasheet) 
 + If you try and output more current than that, you run the risk of damaging the device. ​ Since many LEDs are able to draw 20mA you should adjust your current limiting resistor to be 12mA or less.  Using https://​en.wikipedia.org/​wiki/​LED_circuit ​- R=(Vout-Vled)/I so (3.3V-1.8Vred) ​at 12mA = 125Ω min for a red LED.
esp8266_gpio_pin_allocations.1436218119.txt.gz · Last modified: 2015/07/06 21:28 by tytower