-
Notifications
You must be signed in to change notification settings - Fork 235
Simple serial terminal example to run on Pico #69
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
Open
brianddk
wants to merge
2
commits into
raspberrypi:master
Choose a base branch
from
brianddk:pico_terminal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Pico serial terminal | ||
|
||
A simple example to allow a Pico to act as a serial terminal into another Raspberry Pi computer. | ||
Usefull for setting up a Pi when network setup fails for some reason. | ||
Should work for Windows, Linux, or Mac host machines. | ||
|
||
1. Add `enable_uart=1` to the Raspberry Pi computer `config.txt` and boot it. | ||
2. Connect pins `pico:{1,2,3}` to `pi:{10,8,6}` | ||
3. Connect to Pico using [Thonny][thonny] | ||
4. From Thonny, run `terminal.py` on Pico, then power up the Pi | ||
|
||
[thonny]: https://thonny.org/ | ||
|
||
You should now have a serial terminal to your Raspberry Pi computer through your Pico. | ||
|
||
### Erratta / Bugs | ||
|
||
* Input is only taken a whole line at a time after the EOL character. | ||
* Line input is ALWAYS echoed back to the terminal as a new line, even passwords | ||
* Control characters are dropped so no curses tools (like `raspi-config`) work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env micropython | ||
from _thread import start_new_thread | ||
from machine import UART, Pin | ||
|
||
UART0 = 0 # uart0 is the FIRST uart | ||
TX=0 # Default Pin number for TX on Pico uart0 | ||
RX=1 # Default Pin number for RX on Pico uart0 | ||
VS=2 # comment reminder: DONT FORGET to connect the common Ground (VSS) | ||
|
||
uart = UART(UART0, 115200, parity=None, bits=8, stop=1, tx=Pin(TX, Pin.OUT), rx=Pin(RX, Pin.IN)) | ||
|
||
# Type a line (plus enter) in REPL to transmit down UART | ||
def TX(): | ||
while True: | ||
line = input() + "\n" | ||
uart.write(line.encode()) | ||
|
||
# Busy thread to relay EVERY character arriving from uart | ||
def RX(): | ||
while True: | ||
recv = uart.read() | ||
if(recv): | ||
try: | ||
print(recv.decode(), end='') | ||
except UnicodeError: | ||
# Caught a control char in buffer, eject it and move along | ||
fix = [x for x in recv if x <= 127] | ||
print(bytes(fix).decode(), end='') | ||
|
||
# Run busy thread on second processor | ||
start_new_thread(RX, tuple([])) | ||
# Run input wait on this (BSP) processor | ||
TX() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.