[Python] How to send a 200×200 1bit image to a lilygo wrist-e-paper through python [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    How do I send an image (200×200) to a wrist-e-paper from lilygo?

    I've been playing around with the WiFiSendTest example and this is working, but I manually need to select an image and manually send it. I want to take these steps to a python script which does the work. It will need to display a QR code which I automatically create through a different python script.

    I've already got this code:

    import requests
    from PIL import Image
    import numpy as np

    # Device IP Address
    DEVICE_IP = "10.13.100.100"
    UPLOAD_URL = f"http://{DEVICE_IP}/"
    SHOW_URL = f"http://{DEVICE_IP}/SHOW_"

    # Convert image to 1-bit array (packed bit array)
    def convert_image(image_path):
    img = Image.open(image_path).convert("1") # Convert to 1-bit monochrome
    img = img.resize((200, 200)) # Ensure size is correct
    img_data = np.array(img, dtype=np.uint8) # Convert to NumPy array
    img_data = np.packbits(img_data) # Pack bits into bytes
    return img_data

    # Encode the image data to a custom format (no base64, just raw packed bits)
    def encode_image_data(img_data):
    encoded_data = "".join(chr(byte) for byte in img_data)
    return encoded_data

    # Upload the image to the device
    def upload_image(image_path):
    img_data = convert_image(image_path)
    encoded_data = encode_image_data(img_data)

    # Send the encoded data
    response = requests.post(UPLOAD_URL + encoded_data + "LOAD_", headers={"Content-Type": "text/plain"})

    print("Upload Response:", response.status_code, response.text)

    # Send the SHOW command to refresh the display
    show_response = requests.post(SHOW_URL)
    print("Show Response:", show_response.status_code, show_response.text)

    # Run the script
    if __name__ == "__main__":
    # Example image path
    image_path = "BarCode.bmp"
    upload_image(image_path)


    This script is timing out.

    In the meantime, I also tried this:

    import requests
    from PIL import Image
    import numpy as np
    import base64

    # Device IP Address
    DEVICE_IP = "10.13.100.100"
    UPLOAD_URL = f"http://{DEVICE_IP}/"
    SHOW_URL = f"http://{DEVICE_IP}/SHOW_"

    # Convert image to 1-bit array
    def convert_image(image_path):
    img = Image.open(image_path).convert("1") # Convert to 1-bit monochrome
    img = img.resize((200, 200)) # Ensure size is correct
    img_data = np.array(img, dtype=np.uint8) # Convert to NumPy array
    img_data = np.packbits(img_data) # Pack bits into bytes
    return img_data

    # Encode the image for transmission
    def encode_image_data(img_data):
    encoded_data = ""
    for byte in img_data:
    encoded_data += chr((byte & 0xF) + 97) # Convert to ASCII character encoding
    encoded_data += chr(((byte >> 4) & 0xF) + 97)

    return encoded_data

    # Upload the image to the device
    def upload_image(image_path):
    img_data = convert_image(image_path)
    encoded_data = encode_image_data(img_data)

    # Send the encoded data
    response = requests.post(UPLOAD_URL + encoded_data + "LOAD_", headers={"Content-Type": "text/plain"})
    print("Upload Response:", response.status_code, response.text)

    # Send the SHOW command to refresh the display
    show_response = requests.post(SHOW_URL)
    print("Show Response:", show_response.status_code, show_response.text)

    # Run the script
    if __name__ == "__main__":
    image_path = "BarCode.png"
    upload_image(image_path)


    This is sending something, but the e-paper goes "white" instead of showing the QR code.

    Continue reading...

Compartilhe esta Página