Instructions

import serial
import time
# Opening the serial port
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3.0)
print ("Starting test...")
port.write(bytes("Please enter Test-String: \n",'ascii'))
# Message is being sent
while True:
testString = port.readline() # Something is read
testString = testString.decode('utf-8') # Convert to String
if testString != "":
print("The Test-String received is: " ,testString) # Output to console
print("----------------------------------------------")
time.sleep(2)
port.write(bytes("Please enter Test-String: \n",'ascii'))
You can now execute the script with the following command:
Now you can communicate with your Raspberry Pi via a terminal pro-
gram such as HTerm. Make sure that you set the baud rate to the same
speed as in your Python code, in this example 9600. The data received
from the Raspberry Pi will be displayed in the console.
python3 ttlToRS485.py