User Tools

Site Tools


esp8266:how-to-use-all-esp01-gpio-pins

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:how-to-use-all-esp01-gpio-pins [2019/10/06 15:16]
Ilias Iliopoulos Added schematics
esp8266:how-to-use-all-esp01-gpio-pins [2024/02/02 21:49] (current)
Ilias Iliopoulos
Line 1: Line 1:
-====== How to use all ESP-01 GPIO pins ======+====== How to use "all" ​ESP-01 GPIO pins ======
  
 ===== Introduction ===== ===== Introduction =====
Line 9: Line 9:
   - RXD and TXD are used for interfacing purposes, ​   - RXD and TXD are used for interfacing purposes, ​
   - the Reset (RST) and Enable (CH_PD) pins cannot be used for any other purpose, ​   - the Reset (RST) and Enable (CH_PD) pins cannot be used for any other purpose, ​
-  - GPIO0 is used during flashing the operating software, ​+  - GPIO0 and GPIO2 are used during flashing the operating software, ​
  
-Finally, only GPIO2 pin seem to remain ​as a pin to be used for general purpose input/​output. In practice, even GPIO2 has some peculiarities that make it hard to use.+Finally, only GPIO2 pin remains ​as a pin to be used for general purpose input/​output, ​and even this under specific conditions.
  
-There are of course several ways to bypass the problem. The easiest by far is to dump ESP-01 and use one of the several modules, such as the ESP-07 or ESP-12, or one of the development platforms such as NodeMCU, ​WeeMos ​D1 etc. But, engineers are notorious for trying to squeeze every drop of juice, especially when our project requires only minimal resources.+There are of course several ways to bypass the problem. The easiest by far is to dump ESP-01 and use one of the several modules, such as the ESP-07 or ESP-12, or one of the development platforms such as NodeMCU, ​WeMos D1 etc. which provide a larger number of GPIO pins. But, engineers are notorious for trying to squeeze every drop of juice, especially when our project requires only minimal resources, or when we have several spare ESP-01 modules in our lab bins.
  
-In this article, I will show you how to use all the available pins of ESP-01, in a couple of use cases. The article ​is intentionally small, because its purpose is only to present ​"​how"​ it is done and not the details of "​why"​ it is done like this. Please consult the official documentation. Unfortunately,​ the popularity of the ESP8266 has made most of us learn the system ​mostly through articles and experimentation,​ rather than studying the lengthy documentation,​ and therefore, it is not my intention to present information that is not 100% correct.+In this article, I will show you how to use all the available pins of ESP-01, in a couple of use cases. The article ​present ​only "​how"​ it is done and not the details of "​why"​ it is done like this. Please consult the official documentation ​to find additional information. Unfortunately,​ the popularity of the ESP8266 has made most of us learn the ESP-8266 platform ​mostly through articles and experimentation,​ rather than studying the lengthy documentation,​ and therefore, it is not my intention to present information that is not 100% correct.
  
 In addition, bear in mind that __there is no such thing as a free lunch__. There are dangers in the process. Make sure that you have read and fully understand the [[esp8266:​how-to-use-all-esp01-gpio-pins#​WARNING|WARNING]] section below. **You have been warned!!!** In addition, bear in mind that __there is no such thing as a free lunch__. There are dangers in the process. Make sure that you have read and fully understand the [[esp8266:​how-to-use-all-esp01-gpio-pins#​WARNING|WARNING]] section below. **You have been warned!!!**
Line 54: Line 54:
 The solution is to implement a **negative logic** in our code. This means that HIGH voltage on the pin will signify an **"​Off"​** state, whereas a LOW voltage will be the **"​On"​** state. The circuit to implement this method employs a PNP transistor, followed by an NPN transistor. In this example circuit, a relay is driven by GPIO0. When we want to activate the relay, we write LOW to pin 0: The solution is to implement a **negative logic** in our code. This means that HIGH voltage on the pin will signify an **"​Off"​** state, whereas a LOW voltage will be the **"​On"​** state. The circuit to implement this method employs a PNP transistor, followed by an NPN transistor. In this example circuit, a relay is driven by GPIO0. When we want to activate the relay, we write LOW to pin 0:
  
-<​code>​+<​code ​c++>
 digitalWrite(0,​ LOW); digitalWrite(0,​ LOW);
 </​code>​ </​code>​
Line 60: Line 60:
 And when we want to de-activate the relay, we write HIGH. And when we want to de-activate the relay, we write HIGH.
  
-<​code>​+<​code ​c++>
 digitalWrite(0,​ HIGH); digitalWrite(0,​ HIGH);
 </​code>​ </​code>​
Line 66: Line 66:
 Because I try to write code that can be re-used in several projects, I introduce a constant such as **gpioLogic** and the code goes like: Because I try to write code that can be re-used in several projects, I introduce a constant such as **gpioLogic** and the code goes like:
  
-<​code>​+<​code ​c++>
 /* /*
   Set true for a positive logic or false for a negative logic   Set true for a positive logic or false for a negative logic
Line 113: Line 113:
  
 See the circuit below. The series resistors provide some safety from short-circuiting a pin in case both sides operate as outputs, before our code takes over. See the circuit below. The series resistors provide some safety from short-circuiting a pin in case both sides operate as outputs, before our code takes over.
 +
 +{{ :​esp8266:​esp01_txrx.png |}}
  
 In terms of software, in order to force pins TXD/GPIO1 and RXD/GPIO3 to operate as I2C pins functioning as SDA and SCL respectively,​ we must set in our code: In terms of software, in order to force pins TXD/GPIO1 and RXD/GPIO3 to operate as I2C pins functioning as SDA and SCL respectively,​ we must set in our code:
  
-<​code>​+<​code ​c++>
 Wire.begin(1,​ 3) Wire.begin(1,​ 3)
 </​code>​ </​code>​
Line 122: Line 124:
 The syntax is: The syntax is:
    
-<​code>​+<​code ​c++>
 Wire.begin(sda_pin,​ scl_pin). Wire.begin(sda_pin,​ scl_pin).
 </​code>​ </​code>​
Line 128: Line 130:
 ===== Conclusion ===== ===== Conclusion =====
  
-I have presented ways to exploit an ESP-01 as much as possible and utilize all four pins, instead of just one (GPIO2). The above methods can mostly be utilized in hobby projects, due to dangers of frying the pins. For more serious or commercial projects, it will be better to select another more appropriate ​module. ​+I have presented ways to exploit an ESP-01 as much as possible and utilize all four available GPIO pins. The above methods can mostly be utilized in hobby projects, due to dangers of frying the pins. For more serious or commercial projects, it will be better to select another more suitable ​module. ​
  
 Have fun... ​ Have fun... ​
 +
 +~~DISQUS~~
esp8266/how-to-use-all-esp01-gpio-pins.1570364214.txt.gz ยท Last modified: 2019/10/06 15:16 by Ilias Iliopoulos