Skip to content

Commit

Permalink
Added UART example #19 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallan committed Feb 23, 2021
1 parent f62ca72 commit 873ab46
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions uart/uart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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))

0 comments on commit 873ab46

Please sign in to comment.