0

I have a RPI 3 receiving a string over UART every 4.5 seconds. on a serial terminal ( im using cutecom) the string prints perfectly and horizontal. However once i use a python code to read the UART port and print the string, it prints it vertically bit by bit. I used the same code on a UpSquared board but it worked perfectly

import mraa

# Initialise UART
port = '/dev/ttyS0'
u = mraa.Uart(port)

# Set UART parameters
u.setBaudRate(115200)
u.setMode(8, mraa.UART_PARITY_NONE, 0)
u.setFlowcontrol(False, False)

# Start a neverending loop waiting for data to arrive.
# Press Ctrl+C to get out of it.
while True:
    if u.dataAvailable():
        # We are doing 1-byte reads here
        data_byte = (u.readStr(12))
        print (data_byte)

i expected to receive:

11SITFYPRPL1 -23
11SITFYPRPL1 -23
11SITFYPRPL1 -23

But what i printed was:

1
1
S
I
T
F
Y
P
R
P
L
1
  • 1
    `python2` or `python3` ? If `python3`, use `print(data_byte, end='')`, if `python2` then `print data_byte,` # not the `,` at the end – han solo Apr 11 '19 at 12:42
  • 1
    Possible duplicate of [How do I print two strings vertically side by side](https://stackoverflow.com/questions/55573915/how-do-i-print-two-strings-vertically-side-by-side) – Lucas Apr 11 '19 at 12:46
  • i am using python 2.7! i changed the code to [ print data_byte, ] but now it does not display anything – timothy zhang Apr 11 '19 at 13:23

0 Answers0