import machine
import os
import uasyncio as asyncio
from machine import UART
#hardware UART
uart = UART(2, 9600, timeout=0) #TX2(GPIO17) and RX2(GPIO16)
#hardware SPI
sd = machine.SDCard(slot=2) #SPI_MISO = GPIO19, SPI_MOSI = GPIO23,SPI_CLK = GPIO18,SPI_CS = GPIO5
vfs=os.VfsFat(sd)
os.mount(vfs,'/sd')
file = open("/sd/log.txt","a")
async def receiver():
____ sreader = asyncio.StreamReader(uart)
____ while True:
________ print('Waiting on receive')
________ res = await sreader.readline() #wait /n
________ file.write("%s\r\n" % res)
________ file.flush()
________ print('Received', res)
async def main():
____ asyncio.create_task(receiver())
____ while True:
________ await asyncio.sleep(1)
def run():
____ try: asyncio.run(main())
____ except KeyboardInterrupt:
________ print('Interrupted')
____ finally:
________ file.close()
run()