UART example update and README

First attempt
This commit is contained in:
7west 2021-02-24 21:39:50 -05:00 committed by GitHub
parent 8fbf61ced1
commit f0f802ef85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

25
uart/README.adoc Normal file
View File

@ -0,0 +1,25 @@
= Using UART on the Raspberry Pi Pico
:xrefstyle: short
Send data from the UART1 port to the UART0 port.
== Other code to try
[source.python]
uart0 = UART(0) #opens a UART connection at the default baudrate of 115,200
uart0.readline() #reads until the CR (\r) and NL (\n) characters then returns the line
== Wiring information
See <<uart-wiring-diagram>> for wiring instructions.
[[uart-wiring-diagram]]
[pdfwidth=75%]
.Wiring two of the Pico's ports together
image::pico_uart_example.png[]
== List of Files
A list of files with descriptions of their function;
uart.py:: The example code.

BIN
uart/pico_uart_example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View File

@ -1,13 +1,15 @@
from machine import UART, Pin
import time
uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9), bits=8, parity=None, stop=1)
uart1.write(b'UART on GPIO8&9 at 9600 baud\n\r')
uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9))
uart0 = UART(0)
uart0.write(b'UART on GPIO0&1 at 115200 baud\n\r')
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
txData = b'hello world\n\r'
uart1.write(txData)
time.sleep(1)
rxData = bytes()
while uart0.any() > 0:
rxData += uart0.read(1)
print(rxData)
rxData += uart0.read()
print(rxData.decode('utf-8'))