reconfigure UART on the ESP8266

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
Hasenradball
Posts: 12
Joined: Tue May 21, 2019 12:52 pm
Location: Germany
Contact:

reconfigure UART on the ESP8266

Post by Hasenradball » Wed Jul 03, 2019 7:00 am

Hi guys,

does anyone know that or can give a hint?
I want to use the DS3231 and the DHT22 on the ESP8266-01, there I have the following Pins available:

Pin 0
Pin 1 (UART - TX)
Pin 2
Pin 3 (UART - RX)

Normally for measuring the temperature and maybe control the chip I need one Pin for the DHT22 signal, and two Pins for the I2C and if possible one Pin for the UART - TX functionality.
Can you answer if it is possible:

to use the Pins 1 and 3 for I2C functionality
only to make the TX functionality Pin available on Pin 2 for example
and use the DHT on Pin 0

If possible can you say how to set up the Pin config fot the UART?

PS: using this Adapter: http://esp8266-01-adapter.de/

Thank you
Frank

Christian Walther
Posts: 52
Joined: Fri Aug 19, 2016 11:55 am

Re: reconfigure UART on the ESP8266

Post by Christian Walther » Wed Jul 03, 2019 11:06 am

I can’t test it right now, but from memory:
  • You cannot reconfigure the pins of UART 0 because they are hardwired, however what you want to do should be possible using UART 1, which transmits on GPIO2 (and cannot receive). To switch the terminal output to a different UART, use uos.dupterm().
  • I2C and DHT should work on all pins because they are implemented in software.
  • Make sure you can still pull up and down pins 0 and 2 as required for booting.

User avatar
Hasenradball
Posts: 12
Joined: Tue May 21, 2019 12:52 pm
Location: Germany
Contact:

Re: reconfigure UART on the ESP8266

Post by Hasenradball » Fri Jul 05, 2019 2:46 pm

Hi thank you for your post,

but as I know in Arduino you can disable the Serial and so use for example all 4 GPIO pins on the ESP8266-01 for reading sensors.
So I thought this should also be able with micropython.
Isn't it?

Christian Walther
Posts: 52
Joined: Fri Aug 19, 2016 11:55 am

Re: reconfigure UART on the ESP8266

Post by Christian Walther » Fri Jul 05, 2019 5:13 pm

I probably misunderstood what you meant by “reconfigure”. What I’m saying is that you cannot use other pins than 1 and 3 for UART 0. However, you should indeed be able to use pins 1 and 3 for other purposes than UART 0.

(If there is anything else to discuss, let’s continue in the other topic you opened in the proper forum.)

User avatar
dhylands
Posts: 3202
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: reconfigure UART on the ESP8266

Post by dhylands » Fri Jul 05, 2019 6:06 pm

Not necessarily.

The ESP8266's that have an onboard USB-to-serial adapter on them have the TX line from the USB-to-serial converter hard wired to the RX pin on UART0, so if you try to use that physical pin for a different purpose then you'll have 2 sources trying to drive the pin, and you won't get what you expect.

Of course, if you're using a module with no USB-to-serial converter then you're free to use the pin for something else.

Now some boards, like the NodeMCU board
https://circuits4you.com/wp-content/upl ... iagram.png
may have inline resistors (470 ohms in the schematic above) which means that you would be able to use the RX line for a low-impedance source (something which has a significantly lower impedance than 470 ohms). When no data is being received then the 470 ohm resistor will act like a 470 ohm pullup (since the UART idle state is high), but when data comes into, then it will oscillate back and forth between acting like a pullup and pulldown.

Christian Walther
Posts: 52
Joined: Fri Aug 19, 2016 11:55 am

Re: reconfigure UART on the ESP8266

Post by Christian Walther » Fri Jul 05, 2019 6:39 pm

Good point (and that was also the reason why I still haven’t tested it). I was specifically referring to the OP’s ESP-01 module, which does not include a USB-to-serial converter.

Post Reply