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
UART issue
-
- Posts: 5
- Joined: Wed Nov 30, 2016 8:19 am
UART issue
Last edited by technodict on Thu Dec 01, 2016 5:16 am, edited 1 time in total.
Re: UART issue
Those need to be crossed, i.e:technodict wrote:The Rx and Tx pins are connected to corresponding Rx and Tx of a serial to USB converter.
Code: Select all
Board -> |Rx - Tx| <- Usb2Serial
|Tx - Rx|
Re: UART issue
And also make sure you connect GND from the 8266 to GND on the usb-to-serial converter.
-
- Posts: 5
- Joined: Wed Nov 30, 2016 8:19 am
Re: UART issue
Yes the Pins are Rx-Tx Tx-Rx and yes grounds are connected !
Re: UART issue
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.
note this code is untested and just from the top of my head.
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")
Re: UART issue
Code: Select all
from machine import UART
uart = UART(1, 9600)
uart.init(9600, bits=8, parity=None, stop=1)
uart.write("hello")
can anyone please help me ?
Re: UART issue
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.