python3 pySerial TypeError: unicode strings are not supported, please encode to bytes:

Encode your data which you are writing to serial,in your case "serialcmd" to bytes.try the following :

ser.write(serialcmd.encode())


i found same you problem for learn "Arduino Python Serial"
You can do another way this:

ser.write(str.encode('allon'))

If we have the string itself and not in a variable, we can do like this:

    ser.write(b'\x0101')

This will convert the string to bytes type