Install a jumper between RX and TX (see attached).
Then run this code that sends some data to the TX pin that goes directly to the RX pin and get displayed on the screen. If the data is displayed on the screen then you know the transmit and receive on the serial port is working.
import serial
sPortToUse = "/dev/ttyAMA0"
sTest = "This data was sent to the serial port ".encode('utf-8')
sReceive = b""
iBytesSent = 0
serialPort = serial.Serial(sPortToUse, 9600, timeout = 2)
serialPort.flushOutput()
serialPort.flushInput()
if serialPort.open:
print("Opened port", sPortToUse)
iBytesSent = serialPort.write(sTest)
print ("Sent", iBytesSent, "bytes")
sReceive = serialPort.readline()
print (sReceive.decode('utf-8'))
else:
print("Port", sPortToUse, "failed to open")
serialPort.close()
If the serial port is working you will see the following:
('Opened port', '/dev/ttyAMA0')
('Sent', 38, 'bytes')
This data was sent to the serial port