Takahashi79
Posts: 1
Joined: Mon Jun 17, 2019 1:24 am

UART not receiving data

Mon Jun 17, 2019 1:37 am

I have Raspberry model 3 B+
I've connected it via UART with my Laptop and connected with PUTTY , to test UART communication .
Used Code:

Code: Select all

from __future__ import print_function
import serial

test_string = "Testing 1 2 3 4".encode('utf-8')
#test_string = b"Testing 1 2 3 4" ### Will also work

port_list = ["/dev/serial0",  "/dev/ttyS0"]

for port in port_list:

    try:
        serialPort = serial.Serial(port, 115200, timeout = 2)
        serialPort.flushInput()
        serialPort.flushOutput()
        print("Opened port", port, "for testing:")
        bytes_sent = serialPort.write(test_string)
        print ("Sent", bytes_sent, "bytes")
        loopback = serialPort.read(bytes_sent)
        if loopback == test_string:
            print ("\r\nReceived", len(loopback), "valid bytes, Serial port", port, "working \n")
        else:
            print ("\r\nReceived incorrect data", loopback, "over Serial port", port, "loopback\n")
        serialPort.close()
    except IOError:
        print ("Failed at", port, "\n")
However I received 2 problematic results:
for /dev/ttyS0:
Received incorrect data b'' over Serial port /dev/ttyS0 loopback

and for /dev/serial0 absolutely nothing except one line space

Can anyone tell me what's wrong in here? Especially - why there's such weird response on serial0 and how to fix it?

Return to “Interfacing (DSI, CSI, I2C, etc.)”