How to use UART

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
MikaelNissen
Posts: 4
Joined: Sat Apr 23, 2016 1:19 am

How to use UART

Post by MikaelNissen » Tue Apr 26, 2016 8:35 pm

Hi

I have a little bet hard time to figur out if UART is implementerede in the firmware....

What I'm trying to do is reading from UART and send the data via socket to a server...

I'm tryin to init the UART port via REPL without luck;

Code: Select all

from machine import UART 
uart = UART(1, 115200)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: extra positional arguments given
Thanks!

wendlers
Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: How to use UART

Post by wendlers » Wed Apr 27, 2016 9:50 am

Hi,

first: I have not tried UART myself on the ESP. That being said, from the MP code I could tell the following:

The "UART" constructor only takes a single argument, the UART ID. All the settings then should be done by calling the "init" method I think. The "init" allows a set of "kwargs", but to my understanding, only "timeout" and "timeout_char" are allowed at the moment. Baudrate I think is fix (https://github.com/micropython/micropyt ... phal.c#L51)

So just using:

Code: Select all

from machine import UART
uart = UART(1)
Might give you a UART object working at 115200 ....

MikaelNissen
Posts: 4
Joined: Sat Apr 23, 2016 1:19 am

Re: How to use UART

Post by MikaelNissen » Wed Apr 27, 2016 3:18 pm

Thanks for the info

I get an error if I use UART(1):

Code: Select all

from machine import UART
uart = UART(1)
test = uart.readline()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: UART(1) can't read
But it is working on UART0:

Code: Select all

from machine import UART

uart = UART(0)

wendlers
Posts: 47
Joined: Wed Mar 16, 2016 10:07 pm

Re: How to use UART

Post by wendlers » Wed Apr 27, 2016 7:59 pm

Hi,

yes, seams like UART(1) is only for writing (the exception you see is thrown from the UART code when you call "read" for UART with ID 1). Writing so far works for me. I think using UART 0 is not an option I think since it is the one the REPL uses.

Also it seams that my board (NodeMCU) has no HW pin for RX on UART ID 1:

Image

aleskeyfedorovich
Posts: 28
Joined: Mon Aug 27, 2018 4:43 pm

Re: How to use UART

Post by aleskeyfedorovich » Wed Aug 29, 2018 8:35 am

Anyone that tested it?
If I understood the reply, it is mandatory to use D0 for reading/writing from/to devices communicating through uart?
thank you

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

Re: How to use UART

Post by kevinkk525 » Wed Aug 29, 2018 5:26 pm

I used UART one for TX in one application and it works fine.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

aleskeyfedorovich
Posts: 28
Joined: Mon Aug 27, 2018 4:43 pm

Re: How to use UART

Post by aleskeyfedorovich » Mon Sep 03, 2018 10:43 am

Which pin do you mean?
In the above schema I can't see any pin named "UART1".
I have an ESP-12e (actually a nodeMCU lolin)
I'm a beginner.
Thank you

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

Re: How to use UART

Post by kevinkk525 » Mon Sep 03, 2018 3:30 pm

I think it was pin D4. It was a work project and I don't have the files at the moment.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply