If you are trying to send pictures to the HMI display. Here is somehelp

So first you need an display compatible with the ExPicture command.

  1. send the twfile comand like so: twfile ,

Here it comes the first problem, they also listed: twfile “ram/0.jpg” but I cannot make it work with ram memory, nor the EEPROM memory. I’ve added an SD card to the display to send it.

So, twfile “sd0/0.jpg”,10 should work if you have the SD card added and you should also get a xFE response from the screen.

After this, you need to send the header.

For this you need to send something like so:

0x3A, 0xA1, 0xBB, 0x44, 0x7F, 0xFF, 0xFE, 0x00, 0x00, 0x00, lower 8 bits (least significant byte) of the length, upper 8 bits (most significant byte) of the length

Then you can send the picture.

Here is the python code for doing so that I copied from another Thread in this website:

ser.write(('twfile "sd0/15.jpg",%d' %(len(image_to_send), )).encode("ISO-8859-1") + bytearray([255,255,255]))
sleep(1)
ser.write(bytearray([58,161,187,68,127,255,254,0,0,0, int(bin(len(image_to_send) & 0xff), 2), int(bin(len(image_to_send)>>8), 2)]) + image_to_send)

If everything goes right, you should get a xFD when all the bytes got recieve correctly by the screen.

you can then use ExPicture to show your image like so: exp0.path=“sd0/0.jpg”

If you are getting the error: “Show Picture Error!”, the problem is with the way the file was saved but at least the image was uploaded correctly and the command used in the ExPicture did also work fine.

“ExPicture can display images that are in the same selected orientation as the HMI and either Nextion’s *.xi format or JPEG Baseline DCT only.”

FOR PYTHON USERS:

Using the library PIL and saving there always gives me this problem. Using CV2 seems to fix it for now.

import cv2

# Read an image
image_path = "10.jpg"
image = cv2.imread(image_path)

# Save the image
output_path_opencv = "101.jpg"
cv2.imwrite(output_path_opencv, image)

print(f"OpenCV Image saved to {output_path_opencv}")

So, if anyone could explain me why using PIL does not work but OpenCV does I would appreciate it.

File size above 4096 Bytes will fail most of the times. At least for now. I’ve tried multiple baudrates and same. Cleary something about memory allocation or something because it fails exactly after 2^12.