String to URTH and URTH to String
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Kc2021
- Posts: 28
- Joined: Mon Jul 19, 2021 11:42 am
String to URTH and URTH to String
Hi friends, I love your products and software. I need to send a string through UART using Circuitpython. I try some ways and keep getting errors. Could you provide a code example of how to do it? I am not good at programming, so please don't send me to read about it because I already try and cant follow. I am using tow pi pico. Thanks.
- Franklin97355
- Posts: 23903
- Joined: Mon Apr 21, 2008 2:33 pm
Re: String to URTH and URTH to String
Can you tell us what you want to send and receive and how you are connecting the picos? Your code and the errors will also be helpful.
- Kc2021
- Posts: 28
- Joined: Mon Jul 19, 2021 11:42 am
Re: String to URTH and URTH to String
In the sending part
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Define the string to send
string_to_send = "Hello, world!"
# Send the string
uart.write(string_to_send.encode())
in the receiving version 1: error > 'bytes' object has no attribute 'decode'
]0;🐍[email protected] AttributeError | 8.0.3\
Code done running.
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Wait for incoming data
while not uart.in_waiting:
pass
# Read the incoming data
received_data = uart.read(uart.in_waiting).decode()
print("Received data: ", received_data)
in the receiving version 2: it prints (b'\xff\xfd\xff\xfd\xff\xfd\xfd\xfd\xfe\xff7\xff\xff\xfd\xff\xfd\xff\xfd\xfd\xfd\xff\xfd7\xff\xfd\xff\xff\xfd\xfd\xff\xfd\xfd\xff\xfd\xfe\xfd\xfd\xfd\xff\xff\xfd\xff\xfd\xfd\xfd\xff\xff\xfd\xfd\xfd\xfd\xfd\xfd\xff\xff\xfd\xff\xff\xfd\x7f\xff\xfd\xfd\xff')
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Wait for incoming data
while not uart.in_waiting:
pass
# Read the incoming data
received_data = uart.read(uart.in_waiting) # I took out decode()
print("Received data: ", received_data)
Thanks!
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Define the string to send
string_to_send = "Hello, world!"
# Send the string
uart.write(string_to_send.encode())
in the receiving version 1: error > 'bytes' object has no attribute 'decode'
]0;🐍[email protected] AttributeError | 8.0.3\
Code done running.
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Wait for incoming data
while not uart.in_waiting:
pass
# Read the incoming data
received_data = uart.read(uart.in_waiting).decode()
print("Received data: ", received_data)
in the receiving version 2: it prints (b'\xff\xfd\xff\xfd\xff\xfd\xfd\xfd\xfe\xff7\xff\xff\xfd\xff\xfd\xff\xfd\xfd\xfd\xff\xfd7\xff\xfd\xff\xff\xfd\xfd\xff\xfd\xfd\xff\xfd\xfe\xfd\xfd\xfd\xff\xff\xfd\xff\xfd\xfd\xfd\xff\xff\xfd\xfd\xfd\xfd\xfd\xfd\xff\xff\xfd\xff\xff\xfd\x7f\xff\xfd\xfd\xff')
import board
import busio
uart = busio.UART(board.TX, board.RX, baudrate=9600)
# Wait for incoming data
while not uart.in_waiting:
pass
# Read the incoming data
received_data = uart.read(uart.in_waiting) # I took out decode()
print("Received data: ", received_data)
Thanks!
- Kc2021
- Posts: 28
- Joined: Mon Jul 19, 2021 11:42 am
Re: String to URTH and URTH to String
The main idea is to send a string using the GPIO from a pico to another. Any solution is usable.
Please be positive and constructive with your questions and comments.