diff --git a/uart/README.adoc b/uart/README.adoc new file mode 100644 index 0000000..34d2f0f --- /dev/null +++ b/uart/README.adoc @@ -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 <> 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. \ No newline at end of file diff --git a/uart/pico_uart_example.png b/uart/pico_uart_example.png new file mode 100644 index 0000000..cb42734 Binary files /dev/null and b/uart/pico_uart_example.png differ diff --git a/uart/uart.py b/uart/uart.py index c8d9f9c..25bc037 100644 --- a/uart/uart.py +++ b/uart/uart.py @@ -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) \ No newline at end of file + rxData += uart0.read() + +print(rxData.decode('utf-8')) \ No newline at end of file