Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
tonyldo
Posts: 5
Joined: Wed Jun 20, 2018 5:04 pm
Location: Brazil

Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by tonyldo » Wed Jun 20, 2018 5:25 pm

how can i write this code with micropython?

Code: Select all

void Setup() {
   Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY);
   pinMode(2, OUTPUT);
   pinMode(0, OUTPUT);
   pinMode(3, INPUT_PULLUP);
...
I will use on this circuit:

https://www.forward.com.au/pfod/ESP8266 ... UTPUTS.jpg
Last edited by tonyldo on Thu Jun 21, 2018 3:28 pm, edited 1 time in total.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by kevinkk525 » Wed Jun 20, 2018 7:53 pm

You might want to have a look at the documentation: https://docs.micropython.org/en/latest/ ... /pins.html
What board are you trying to use?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
tonyldo
Posts: 5
Joined: Wed Jun 20, 2018 5:04 pm
Location: Brazil

Re: Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by tonyldo » Thu Jun 21, 2018 12:29 am

kevinkk525 wrote: You might want to have a look at the documentation: https://docs.micropython.org/en/latest/ ... /pins.html
What board are you trying to use?
The documentation doesn't talk about the use of RX pin (gpio 3, esp01 module) as ordinary input pin and anything about disable the input serial comunication with something like this statement:

Code: Select all

Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); 
Enviado de meu XT1580 usando o Tapatalk
Last edited by tonyldo on Thu Jun 21, 2018 3:27 pm, edited 1 time in total.

User avatar
tonyldo
Posts: 5
Joined: Wed Jun 20, 2018 5:04 pm
Location: Brazil

Re: Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by tonyldo » Thu Jun 21, 2018 3:26 pm

I'll test this in boot.py:

Code: Select all

import uos, machine

TX_PIN = 1
uos.dupterm(none, 1)
uos.dupterm(machine.UART(0, 115200, pins=(TX_PIN, None)), 1)
and in main.py:

Code: Select all

import  machine

RX_PIN = 3
pin = machine.Pin(RX_PIN , machine.Pin.IN, machine.Pin.PULL_UP)

newb
Posts: 43
Joined: Wed Jan 10, 2018 8:19 pm
Location: Bulgaria

Re: Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by newb » Sat Jul 28, 2018 4:17 pm

[quote=tonyldo post_id=28282 time=1529594788 user_id=4089]
I'll test this in boot.py:

[CODE]
import uos, machine

TX_PIN = 1
uos.dupterm(none, 1)
uos.dupterm(machine.UART(0, 115200, pins=(TX_PIN, None)), 1)
[/CODE]

and in main.py:

[CODE]
import machine

RX_PIN = 3
pin = machine.Pin(RX_PIN , machine.Pin.IN, machine.Pin.PULL_UP)
[/CODE]
[/quote]

Have you managed to solve this? I'm in the same situation - I'd like to use RX (pin 3) for button input, but it it doesn't work.

newb
Posts: 43
Joined: Wed Jan 10, 2018 8:19 pm
Location: Bulgaria

Re: Using the GPIO0 /GPIO2 for OUTPUT and RX for INPUT

Post by newb » Sat Jul 28, 2018 7:28 pm

Looks like I solved it myself.
Just needed to disable the UART:

https://github.com/micropython/micropyt ... 303fec6ed3


import machine
import uos
uart = machine.UART(0, 115200)
uos.dupterm(uart, 0)

And RX works as normal input pin :)

Post Reply