This is on Raspberry Pi model 2b, using python 3.7.3 and Raspbian - latest version as of a week ago
I need to push some data through the pi serial port. I find that I have to call python as root user in order to be permitted to open the serial port. I import serial, open the port ttyAMA0 at 9600 baud as ser, and use ser.write(b'Hello'). This works fine. BUT I want to send a message that is not a fixed string: I use msg = input('message = ? ') to get the data - that works fine. But I haven't yet found the necessary conversion to get ser.write() to accept - I know I need bytes, but nothing I have found in the python library or in PySerial has worked - yet. I have tried many many things, but python (or the Pi) finds something wrong with all of them.
If you are thinking of being kind enough to help, please be very specific - I seem to misunderstand rather easily!!
import serial
import time
ser = serial.Serial('/dev/ttyAMA0', 9600, timeout = 4)
while True:
msg = input('message = ? ')
# here all the different attempts to manipulate msg
ser.write(.......)
rmsg = ser.read(100) #this works fine, too
....