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:30]
Ilias Iliopoulos Added I2C schematic
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 13: Line 13:
 Finally, only GPIO2 pin remains as a pin to be used for general purpose input/​output,​ and even this under specific conditions. 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. 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.+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 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 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.
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 118: Line 118:
 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 124: 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 133: Line 133:
  
 Have fun... ​ Have fun... ​
 +
 +~~DISQUS~~
esp8266/how-to-use-all-esp01-gpio-pins.1570365034.txt.gz ยท Last modified: 2019/10/06 15:30 by Ilias Iliopoulos