Introduction: ESP8266-01 Building Blocks: Unleash 2 Bonus GPIO Pins

This instructable is part of my series on introducing people to the ESP8266-01 WiFi transceiver. The goal of this series is to act as a basic code repository for easy reuse, as well as to provide some foundational building blocks for people new to the ESP. The "building blocks" series will contain just the basic code needed to complete the object of the instructable, with a (hopefully) thorough explanation of what's going on and why.

In this project, we're going to take a closer look at the pins available on an ESP-01. A common reason people ditch the ESP-01 and go to something more robust (like the ESP-12) is the number of pins available for data inputs/outputs. The ESP-12 has 11 digital GPIOs, and one analog. The ESP-01 has 2 digital GPIOs. And no analog pins (unless you have some fine soldering skills, which we'll look at another time).

Both ESPs are pretty cheap, but the 01 is still cheaper than the 12. And most of my projects just don't need that many GPIOs, so the ESP-01 is usually my go-to. Once in a while though, you just need some extra input or output. So, let's level up and unlock some bonus features!

Step 1: Gather Your Parts

To upload your code, you'll need a setup like I laid out here.

For this project you just need a few items on top of what's in the upload board:

Step 2: The Code

Upload the following code to the ESP:

int actPin = 0;

void setup() {

pinMode(3, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);

  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
}

void loop() {

  digitalWrite(actPin, LOW);
  
  if (actPin == 3) {
    actPin = 0;
  } else {
    actPin ++;
  }
  digitalWrite(actPin, HIGH);

  delay(2000);

}

Step 3: Set Up Your Board

You can add the new components into the upload board, or wire up a new one and just swap your ESP over to it after you've uploaded the code.

Since this is a very basic example, reusing the same board may be easiest. All we are doing is setting up 4 different LEDs in series with a 220 ohm resistor connected to ground - LED cathode to resistor.

Then we are connecting the anode of each LED to the following ESP pins:

GPIO0, TX, GPIO2, and RX

Order doesn't really matter too much, but of course it looks better if they are lined up in sequence to how the code will fire them.

Last step is to pull UP GPIO0 and GPIO2 with a 10k ohm resistor. If you are reusing the upload board, don't connect the wires to these two pins until AFTER you loaded the code and repowered the unit with the Flash switch turned off. You won't be able to flash the ESP if these wires are connected when pulled high.

Step 4: Explanation

The code is a very basic blink example of the 4 pins. It rotates through each LED turning it on, then off, then going to the next. Here's what's important:

We've unlocked our secret bonus GPIOs that hide behind their secret identities of TX and RX. We do this by defining them as output with the pinMode() function. Alternatively, we could have specified them as input as well.

TX becomes GPIO1, and RX becomes GPIO3.

Wow, two free extra pins. What's the catch?

The catch is: you can get serial transmissions, or you can get data in or out, but you can't have both. No debugging messages if you have a complicated project using all four pins could possibly be a deal breaker. But on the flip side, if you are building an IoT device that you are actually going to deploy, odds are you don't need any serial communication once you are outside of testing. So take your two extra pins and run!

Last notes: TX will always send a little chatter when the ESP boots up. You may get some arbitrary data to or from your sensor or device connected to the TX pin, but it's only briefly when it boots up, so is easy to handle/account for. The last point is that TX is tied to the onboard blue LED. So you will see that flash on or off depending on what you send or receive off of GPIO1.

I hope this Instructable has helped you to maximize your uses for your ESP-01 projects!

Comments

About This Instructable

494views

13favorites

Bio: IoT - Internet of Things. Iota - small thing. Thingamajig - An object whose name can't be recalled. Iotamajig - A little unnamed internet connected gizmo! More »
More by iotamajig:Detect Household Power With Low Voltage Circuit - Arduino AC Voltage DetectorArduino IDE: How to Store and Retrieve Data From a File.Enable DeepSleep on an ESP8266-01
Add instructable to: