Skip to content

Instantly share code, notes, and snippets.

@InterestingBrainPoops
Created July 25, 2023 04:15
Show Gist options
  • Save InterestingBrainPoops/7e9ffcf12098c8fdd6b212e49a51ba6e to your computer and use it in GitHub Desktop.
Save InterestingBrainPoops/7e9ffcf12098c8fdd6b212e49a51ba6e to your computer and use it in GitHub Desktop.
import machine
import time
# Set up UART1 with the appropriate baud rate and pins.
uart1 = machine.UART(1, baudrate=9600, tx=machine.Pin(4), rx=machine.Pin(5))
def read_char_from_uart(uart):
while not uart.any():
pass
return uart.readline()
def write_char_to_uart(uart, char):
uart.write(char)
uart.flush()
while True:
try:
# Read a character from UART1
received_char = read_char_from_uart(uart1)
print("Received character:", received_char.decode('utf-8'))
# # Modify the received character (e.g., increment it)
# modified_char = chr(ord(received_char) + 1)
#
# print("Xmiting character:", modified_char)
#
# # Write the modified character back to UART1
# write_char_to_uart(uart1, modified_char.encode('utf-8'))
# Wait a bit to avoid flooding the UART
time.sleep_ms(100)
except Exception as e:
print("Error:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment