10

When programming an ESP-01 with Arduino IDE, how can I make the Tx and Rx into a generic I/O pins reliably? I think there's a command to swap the Tx and Tx with other pins. I tried serial.swap() but it didn't work. So how to get done with Arduino IDE or is it even possible?. I am using an ESP-01, which means there will be four GPIO pins once this question in answered.

I want to achieve same as in the video, How to add more GPIOs to ESP8266 (ESP-01), but without soldering wire.

Greenonline
  • 3,152
  • 7
  • 36
  • 48
vzxc
  • 101
  • 1
  • 1
  • 4

5 Answers5

20

Add this to your code at the beginning of set void setup():

//********** CHANGE PIN FUNCTION  TO GPIO **********
//GPIO 1 (TX) swap the pin to a GPIO.
pinMode(1, FUNCTION_3); 
//GPIO 3 (RX) swap the pin to a GPIO.
pinMode(3, FUNCTION_3); 
//**************************************************

You will no longer be able to use the Serial Monitor as TX will now be a GPIO pin and not transmit Serial data. You can still Flash your device as when you boot the device in flash mode it converts GPIO1 and GPIO3 back to TX/RX. Once you reboot into regular running mode GPIO1 and GPIO3 will go back to being GPIO pins.

To change GPIO1 and GPIO3 back to being TX/RX for regular Serial Monitor use add this to your code at the beginning of set void setup():

//********** CHANGE PIN FUNCTION  TO TX/RX **********
//GPIO 1 (TX) swap the pin to a TX.
pinMode(1, FUNCTION_0); 
//GPIO 3 (RX) swap the pin to a RX.
pinMode(3, FUNCTION_0); 
//***************************************************

If I understand the ESP-01 correctly the pins CANNOT be both TX/RX and GPIO pins at the same time.

MaxChinni
  • 103
  • 3
Isaias Munguia
  • 231
  • 3
  • 5
5

Tx = GPIO 1

Rx = GPIO 3

Should work but be careful cause if they burn, you won't be able to program or even talk to the ESP anymore.

Dat Ha
  • 2,943
  • 6
  • 24
  • 46
3

To work TX RX as GPIO Serial.begin() must be deleted from code.

Dima
  • 31
  • 1
1

Maybe a little late but it might helps someone else.

ESP-01 GPIO pins (1&3)

Ernst
  • 19
  • 1
1

One thing I noticed is that if you're trying to use the Tx/Rx pins for the main serial comm (1 & 3) as a GPIO then you must not use any Serial commands in your code, such as Serial.begin.

I was having my GPIO digital reads randomly read high (they had their mode set as INPUT_PULLUP) while I had a source pulling them low (I verified that input was indeed pulled low while the ESP8266 digitalRead was reading high)

Removing all Serial commands (begin, print and println) fixed that for me.

maddios
  • 11
  • 1