Skip to content

Commit 873ab46

Browse files
author
Alasdair Allan
committed
Added UART example #19 (comment)
1 parent f62ca72 commit 873ab46

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

uart/uart.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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))

0 commit comments

Comments
 (0)