Start a new topic

Phyton Script to change an Picture

Hi,


first i am an beginner with nextion display


i want to change the pciture by excute an python script like this one


import serial

ser = serial.Serial(
  port='/dev/ttyama0',
  baudrate = 9600,
  parity=serial.PARITY_NONE,
  stopbits=serial.STOPBITS_ONE,
  bytesize=serial.EIGHTBITS,
  timeout=1
)

while 1:
  EndCom = "\xff\xff\xff"
  ser.write('p0.pic=4'+EndCom)


if i try this i got following error message

TypeError: unicode strings are not supported, please encode to bytes: 'p0.pic=4ÿÿÿ'


it would be great if some could help



See if your python has a ser.print function and try with ser.print instead of ser.write.

It appears as if your error is being generated from ser.write requiring a byte parameter.


I am not familiar with python wondering about use of both double " and single ' quotes.

My guess is that ser.print('p0.pic=4ÿÿÿ')  or  ser.print('p0.pic=4'+EndCom) should work.

thanks for your reply.

i change the script to use only ' qoutes and tried ser.print but unfortunately print isn't know in python 

Ok now it works thanks  again


import serial

ser = serial.Serial("/dev/ttyama0", 9600)

EndCom = b"\xff\xff\xff"

ser.write(b"p1.pic=4"+EndCom)  


Glad to hear it is working.

Login or Signup to post a comment