# How to switch pin between GPIO and UART?

**URL:** <https://forum.amebaiot.com/t/how-to-switch-pin-between-gpio-and-uart/3665>\
**Category:** Peripherals\
**Tags:** rtl872xd\
**Created:** [January 2, 2025, 3:43am UTC](https://forum.amebaiot.com/t/how-to-switch-pin-between-gpio-and-uart/3665 "2025-01-02T03:43:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@Joe](https://forum.amebaiot.com/u/Joe)\
**Post date:** [January 2, 2025, 3:43am UTC](https://forum.amebaiot.com/t/how-to-switch-pin-between-gpio-and-uart/3665/1 "2025-01-02T03:43:03Z")

</div>

Is there a way to switch pin PB1 between GPIO and UART? Once used for UART, GPIO will not work anymore:

```auto
#include <SoftwareSerial.h>

#define TXpin PB1 
#define RXpin PB2
SoftwareSerial mySerial(RXpin, TXpin);

void blink() {
    for(int i = 0; i < 10; i++) {
        digitalWrite(TXpin, HIGH);
        delay(500);
        digitalWrite(TXpin, LOW);
        delay(500);
    }
}

void setup() {
    pinMode(TXpin, OUTPUT);
    blink(); // This works!
    mySerial.begin(250000, 8, PARITY_NONE, 2);
    mySerial.println("Hello world");
    mySerial.end();
    pinMode(TXpin, OUTPUT);
    blink(); // No output anymore!
}

```
