import serial # configure the serial connections ser = serial.Serial() ser.baudrate = 115200 ser.port = 'COM8' ser.open() # print(ser.name) # check which port was really used print(ser.is_open) # for y in range(32): x = b'\x90\xeb' #start character x = x + b'\x80\x02' #write length 128 (two words per pixel) if (y%2) == 1: #address to write, lsb x = x + b'\x89' else: x = x + b'\x09' x = x + (y>>1).to_bytes(1,byteorder='big') #msb address for z in range(64): if (z==0) or (z==1) or (z==62) or (z==63) or (y==0) or (y==31): x = x + b'\xff\x00\xff\x00' elif z==2*y: x = x + b'\xff\x00\x00\x00' elif (y==16): if z==8: x = x + b'\x00\x00\x01\x00' elif z==9: x = x + b'\x00\x00\x02\x00' elif z==10: x = x + b'\x00\x00\x04\x00' elif z==11: x = x + b'\x00\x00\x08\x00' elif z==12: x = x + b'\x00\x00\x10\x00' elif z==13: x = x + b'\x00\x00\x20\x00' elif z==14: x = x + b'\x00\x00\x40\x00' elif z==15: x = x + b'\x00\x00\x80\x00' else: x = x + b'\x00\x0f\x00\x00' elif (y==17): if z==8: x = x + b'\x00\x01\x00\x00' elif z==9: x = x + b'\x00\x02\x00\x00' elif z==10: x = x + b'\x00\x04\x00\x00' elif z==11: x = x + b'\x00\x08\x00\x00' elif z==12: x = x + b'\x00\x10\x00\x00' elif z==13: x = x + b'\x00\x20\x00\x00' elif z==14: x = x + b'\x00\x40\x00\x00' elif z==15: x = x + b'\x00\x80\x00\x00' else: x = x + b'\x00\x0f\x00\x00' elif (y==18): # 18 if z==8: x = x + b'\x01\x00\x00\x00' elif z==9: x = x + b'\x02\x00\x00\x00' elif z==10: x = x + b'\x04\x00\x00\x00' elif z==11: x = x + b'\x08\x00\x00\x00' elif z==12: x = x + b'\x10\x00\x00\x00' elif z==13: x = x + b'\x20\x00\x00\x00' elif z==14: x = x + b'\x40\x00\x00\x00' elif z==15: x = x + b'\x80\x00\x00\x00' else: x = x + b'\x00\x0f\x00\x00' else: x = x + b'\x00\x08\x00\x00' print(y,x) ser.write(x) # write a string # ser.close()