# simplePicoRfV10.py tlfong01 2021oct28hkt1150 # # Pico GP Pin Assignment # GP0 = UART0 TxD = FS1000S # GP1 = UART0 RxD = MX05V # Setup # 1. To loop back, short TxD pin to RxD pin # 2. To test Xmit/Recv, connect GP0 pin to FS1000S (Note 1), GP1 pin to MX05V # Note 1 # Warning: Pico 3V3 Gp0 pin direct connecting to 5V FS1000S data pin, might cause "latching up", and fry Pico (5% chance). # Note 2 # Suggestions # 1. Use HCT125 or HC03 to shift 3V3 logical level to 5V. # 2. Use 12V to power FS1000S to increae xmit power and therefore longer effective distance # References # 1. MicroPython Class UART – duplex serial communication bus # https://docs.micropython.org/en/latest/library/machine.UART.html # 2. General information about the RP2xxx port # https://docs.micropython.org/en/latest/rp2/general.html from machine import UART, Pin import utime uart0 = UART(0, baudrate = 1200, tx=Pin(0), rx=Pin(1)) def testUartLoopBackV01(): print('Begin testUartLoopBackV01(), ...') testMsg = 'Hello World' print(' writeTestMsg =', testMsg) uart0.write(testMsg) # write 5 bytes utime.sleep(0.5) bytesRead = uart0.read(20) # read up to 5 bytes print(' bytes read =', bytesRead) print('End testUartLoopBackV01().') return def testUartLoopBackV02(): print('Begin testUartLoopBackV02(), ...') #testMsg = 'Hello World' testBytes = b'\0x5b\0xb5' print(' bytes written =', testBytes) uart0.write(testBytes) utime.sleep(0.5) bytesRead = uart0.read(20) # print(' bytes read =', bytesRead) print(' Begin repeat printing bytes =', testBytes) for count in range(100000): uart0.write(testBytes) utime.sleep(0.01) print(' End repeat printing bytes =', testBytes) print('End testUartLoopBackV02().') return def testPicoFs1000aV06(): print('Begin Pico TxD (GP0) driving FS1000A, ...') testBytes = b'\0x55\0x55' for count in range(100000): uart0.write(testBytes) utime.sleep(0.01) print('End Pico TxD (GP0) driving FS1000A.') return def testPicoDirectDriveFs1000sV07(): print('Begin Pico TxD (GP0) direct drive FS1000S, ...') testBytes = b'\0x55\0x55\0x55\0x55\0x55\0x55\0x55\0x55' for count in range(100000): uart0.write(testBytes) utime.sleep(0.01) print('End Pico GP0 direct drive FS1000S.') return def testFs1000aMx05vV08(): print('Begin testFs1000aMx05vV08(), ...') testBytes = b'\0x55\0x55\0x55\0x55\0x55\0x55\0x55\0x55' uart0.write(testBytes) # flush output uart0.read() # flush Input print(' bytes written to GP0 (UART0 TxD), connected to FS1000S =', testBytes) uart0.write(testBytes) utime.sleep(0.5) bytesRead = uart0.read(8) print(' bytes read from GP1 (UART0 RxD), connected to MX05V =', bytesRead) print('End testFs1000sMx05vV05().') return def testXmitRecvV09(): print('Begin testXmitRecvV09(), ...') uart0.write(b'\0x00\0xff\0x00\0xff\0x00\0xff\0x00\0xff') # flush output utime.sleep(0.5) uart0.read() # flush Input testBytes = b'\0x5b\0xb5\0x5b\0xb5\0x5b\0xb5\0x5b\0xb5' print(' bytes written =', testBytes) uart0.write(testBytes) utime.sleep(0.5) bytesRead = uart0.read(32) print(' bytes read =', bytesRead) print('End testXmitRecvV09().') return # *** Main *** #testUartLoopBackV01() # GP0, GP1 loopback 'Hello World" #testUartLoopBackV02() # GP0, GP1 loopback'\x00x5b\x00xb5', also repeat send testXmitRecvV09() # .END ''' *** Sample output *** >>> %Run -c $EDITOR_CONTENT Begin testXmitRecvV09(), ... bytes written = b'\x00x5b\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5' bytes read = b'\x00\x00`\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5\x1f' End testXmitRecvV09(). Begin testXmitRecvV09(), ... bytes written = b'\x00x5b\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5\x00x5b\x00xb5' bytes read = b'\x00\x10\x01\xe1\x89\xd5\x01\xe1\xd5\x89\x01\xe1\x89\xd5\x01\xe1\xd5\x89\x01\xe1\x89\xd5\x01\xe1\xd5\x89\x01\xe1\x89\xd5\xff\x07' End testXmitRecvV09(). '''