UART issue

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
technodict
Posts: 5
Joined: Wed Nov 30, 2016 8:19 am

UART issue

Post by technodict » Wed Nov 30, 2016 8:27 am

Hello ,
I am trying to run the following code on the ESP8266 Node MCU board. I have put this code in main.py. The input is being taken from a laptop running Cutecom as a terminal program. The issue is uart.read() doesn’t wait to receive any data from serial (Rx). The Rx and Tx pins are connected to corresponding Tx and Rx of a serial to USB converter.

from machine import UART
uart = UART(0, 9600, timeout=0)
uart.init(9600, bits=8, parity=None, stop=1)
text = uart.read(12)
while True:
if text == b' RECEIVEDTEXT':
uart.write("sucess")
else:
uart.write("failed")
break
Last edited by technodict on Thu Dec 01, 2016 5:16 am, edited 1 time in total.

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: UART issue

Post by platforma » Wed Nov 30, 2016 10:02 am

technodict wrote:The Rx and Tx pins are connected to corresponding Rx and Tx of a serial to USB converter.
Those need to be crossed, i.e:

Code: Select all

Board -> |Rx - Tx| <- Usb2Serial
         |Tx - Rx|
You might already have them that way, just though I'll double check!

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

Re: UART issue

Post by dhylands » Wed Nov 30, 2016 5:11 pm

And also make sure you connect GND from the 8266 to GND on the usb-to-serial converter.

technodict
Posts: 5
Joined: Wed Nov 30, 2016 8:19 am

Re: UART issue

Post by technodict » Thu Dec 01, 2016 5:11 am

Yes the Pins are Rx-Tx Tx-Rx and yes grounds are connected !

Neil
Posts: 15
Joined: Tue Jul 14, 2015 8:51 pm

Re: UART issue

Post by Neil » Thu Dec 01, 2016 8:25 am

I think the problem is that the UART.read is not a blocking read and will read the buffer UPTO but not neccessary the exact number of bytes specified. Therefore something like this may work.

Code: Select all

from machine import UART
uart = UART(0, 9600, timeout=0)
uart.init(9600, bits=8, parity=None, stop=1)
text=''
while len(text)<12:
	text += uart.read(1)
if text == b' RECEIVEDTEXT':
	uart.write("sucess")
else:
	uart.write("failed")
note this code is untested and just from the top of my head.

abhi98
Posts: 1
Joined: Sun Jul 12, 2020 12:25 pm

Re: UART issue

Post by abhi98 » Sun Jul 12, 2020 12:37 pm

Code: Select all

from machine import UART
uart = UART(1, 9600)                         
uart.init(9600, bits=8, parity=None, stop=1) 
uart.write("hello")
using this code Node mcu and using serial monitor see whats happening as i plugged the serial monitor repl stops working ?
can anyone please help me ?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: UART issue

Post by jimmo » Mon Jul 13, 2020 2:31 am

abhi98 wrote:
Sun Jul 12, 2020 12:37 pm
using this code Node mcu and using serial monitor see whats happening as i plugged the serial monitor repl stops working ?
can anyone please help me ?
Is your serial monitor also running at 9600 baud?

This is a limitation of the ESP8266 -- there is only one UART, so it will be shared with the REPL.

Post Reply