Skip to content

Commit 8fbf61c

Browse files
authored
A potentially better example for UART on the Pico
1 parent 1b39602 commit 8fbf61c

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

uart/uart.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
from machine import UART, Pin
2-
from time import sleep_us
3-
4-
class myUART(UART):
5-
def readUntil(self, termination, maxlen=-1, includeTermination=True):
6-
result = ''
7-
while maxlen < 0 or len(result) < maxlen:
8-
if self.any():
9-
#print("here")
10-
result += chr(self.read(1)[0])
11-
#print(result)
12-
if result.endswith(termination):
13-
if not includeTermination:
14-
result = result[:-len(termination)]
15-
break
16-
sleep_us(10)
17-
return result
18-
19-
uart = myUART(0, baudrate=9600, tx=Pin(0), rx=Pin(1), bits=8, parity=None, stop=1)
20-
21-
uart.write("AT+GMR\r\n")
22-
print(uart.readUntil('OK',maxlen=-1, includeTermination=True))
1+
from machine import UART, Pin
2+
3+
uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9), bits=8, parity=None, stop=1)
4+
uart1.write(b'UART on GPIO8&9 at 9600 baud\n\r')
5+
6+
uart0 = UART(0)
7+
uart0.write(b'UART on GPIO0&1 at 115200 baud\n\r')
8+
9+
rxData = bytes()
10+
while uart0.any() > 0:
11+
rxData += uart0.read(1)
12+
13+
print(rxData)

0 commit comments

Comments
 (0)