# Libraries
from machine import UART, Pin
import _thread
import time
# Define UART pins and baud rate
UART0_TX_PIN = 0 # UART0 TX on GP0
UART0_RX_PIN = 1 # UART0 RX on GP1
UART1_TX_PIN = 4 # UART1 TX on GP4
UART1_RX_PIN = 5 # UART1 RX on GP5
BAUD_RATE = 9600
# Initialize UART0 (core 0)
uart0 = UART(0, baudrate=BAUD_RATE, tx=Pin(UART0_TX_PIN), rx=Pin(UART0_RX_PIN))
# Function for core 1 to receive and print messages
def uart1_receive():
# Initialize UART1 (core 1)
uart1 = UART(1, baudrate=BAUD_RATE, tx=Pin(UART1_TX_PIN), rx=Pin(UART1_RX_PIN))
while True:
if uart1.any():
received_msg = uart1.read().decode('utf-8')
print("Received: ", received_msg)
time.sleep(0.1)
# Function for core 0 to send a message
def uart0_send():
while True:
uart0.write('hello from uart 0\n')
time.sleep(1)
# Start receiving on core 1
_thread.start_new_thread(uart1_receive, ())
# Start sending on core 0
uart0_send()