From 8fbf61ced1f05431cb40ad29a99d8fc2aadff129 Mon Sep 17 00:00:00 2001 From: 7west <33707859+7west@users.noreply.github.com> Date: Tue, 23 Feb 2021 15:31:54 -0500 Subject: [PATCH] A potentially better example for UART on the Pico --- uart/uart.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/uart/uart.py b/uart/uart.py index 87bd2df..c8d9f9c 100644 --- a/uart/uart.py +++ b/uart/uart.py @@ -1,22 +1,13 @@ -from machine import UART, Pin -from time import sleep_us - -class myUART(UART): - def readUntil(self, termination, maxlen=-1, includeTermination=True): - result = '' - while maxlen < 0 or len(result) < maxlen: - if self.any(): - #print("here") - result += chr(self.read(1)[0]) - #print(result) - if result.endswith(termination): - if not includeTermination: - result = result[:-len(termination)] - break - sleep_us(10) - return result - -uart = myUART(0, baudrate=9600, tx=Pin(0), rx=Pin(1), bits=8, parity=None, stop=1) - -uart.write("AT+GMR\r\n") -print(uart.readUntil('OK',maxlen=-1, includeTermination=True)) \ No newline at end of file +from machine import UART, Pin + +uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9), bits=8, parity=None, stop=1) +uart1.write(b'UART on GPIO8&9 at 9600 baud\n\r') + +uart0 = UART(0) +uart0.write(b'UART on GPIO0&1 at 115200 baud\n\r') + +rxData = bytes() +while uart0.any() > 0: + rxData += uart0.read(1) + +print(rxData) \ No newline at end of file