Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UART Terminal #12

Open
urish opened this issue Aug 3, 2024 · 1 comment
Open

UART Terminal #12

urish opened this issue Aug 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@urish
Copy link
Member

urish commented Aug 3, 2024

Sketch of a code to implement a UART terminal using the RP2040 hardware UART peripheral. The terminal is connected to the user project pins ui_in[3] (12) and uo_out[4], and is running at 115200 baud rate.

import uselect
import sys
from machine import UART, Pin

uart1 = UART(0, baudrate=115200, tx=Pin(12), rx=Pin(13))
poll = uselect.poll()
poll.register(sys.stdin, uselect.POLLIN)

while True:
	if poll.poll(0):
		_ = uart1.write(sys.stdin.buffer.read(1))
	uart_data = uart1.read()
	if uart_data:
		_ = sys.stdout.write(uart_data)

Currently, the terminal does not forward the Ctrl+C character to the UART port. Instead, it stops running. You can change this behavior by calling micropython.kbd_intr(0).

Also, it'd be more efficient to poll() for both stdin and uart1, if possible.

@urish urish added the enhancement New feature or request label Aug 3, 2024
@urish
Copy link
Member Author

urish commented Dec 24, 2024

Update for SDK v2.0.0 / TT06 DB:

import uselect
import sys
from machine import UART

uart = UART(0, baudrate=115200, tx=tt.pins.ui_in3.raw_pin, rx=tt.pins.uo_out4.raw_pin)
poll = uselect.poll()
poll.register(sys.stdin, uselect.POLLIN)

while True:
	if poll.poll(0):
		_ = uart.write(sys.stdin.buffer.read(1))
	uart_data = uart.read()
	if uart_data:
		_ = sys.stdout.write(uart_data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant