Python Forum
Display moving pictures on E-ink screen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display moving pictures on E-ink screen
#1
Lightbulb 
I work on a project in university and I'm relatively beginnner in python for this part of the project, but I really want to help. We using a program to display pictures on an E-ink device run by Raspberry pi and programmed by python. The code works well when we use it for loading an existing picture, but we are considering to display moving pictures on it in the future, so first idea was to display a working digital clock.

I have read about something like insert a python-written digital clock somehow as a picture but I don't really know if that's the right idea, I feel there's a different method to our problem.

The code:
# For killing the process and call parameters
import sys

# With ctypes, one can import a DLL an access its functions
import ctypes

# Used for image processing
from PIL import Image

# Maps any T-CON error code to a descriptive string.
error_to_string = {
    0: "Success",
    -1: "Input / Output error",
    -2: "Invalid parameters",
    -3: "Access denied (insufficient permissions)",
    -4: "No such device",
    -5: "Entity not found",
    -6: "Resource busy",
    -7: "Operation timed out",
    -8: "Overflow",
    -9: "Pipe error",
    -10: "System call interrupted",
    -11: "Insufficient memory",
    -12: "Operation not supported or unimplemented on this platform",
    -99: "Other error"
}

print("ejump_usb - Displays an image onto a connected e-paper via an eJump T-CON board")
print("")

if len(sys.argv) != 2:
    print("Usage (assuming an image demo.bmp in same folder):")
    print("sudo python3 ejump_usb.py demo.bmp")
    sys.exit(0)

# Load API library via ctypes
tcon_lib = ctypes.cdll.LoadLibrary("/home/pi/e-paper/scripts/libtcon-dev_usb.so.2.0.4")
# "/home/pi/e-paper/scripts/libtcon-dev_usb.so.2.0.4"
# Before we can communicate with the T-CON board, the interface
# has to be initialized. The return value will be the number of
# T-CON boards detected. If return value is 0 or less, an error
# occured (in case of negative values, the error code's meaning
# will be in accordance with the dictionary error_to_string).
print("Trying to initialize T-CON board...")
tcon_num = tcon_lib.tcon_init()
if tcon_num < 0:
    print("Error: Failed to initialize T-CON board for reason:", error_to_string.get(tcon_num, "Unknown Error"))
elif tcon_num == 0:
    print("Error: No T-CON boards detected!")
else:
    print("Successfully initialized T-CON board.")

# Defines the target T-CON board: Set this variable to the configured
# ID of any connected T-CON board (e.g. by means of the rotary switch
# on EJ8951-1W devices) to communicate with that specific board or
# to -1 to communicate with the first T-CON board found.
board_id = -1

# Name of the image file to be displayed.
img_filename = sys.argv[1]

# Waveform mode used for displaying the image. Refer to the
# document "Information about E-Paper Waveform Modes" in the
# downloads section of your eJump card for more information.
wf_mode = 2
# Query the width and height of the e-paper connect to the chosen
# T-CON board.
epd_width = tcon_lib.tcon_get_panel_width(board_id)
print("Width of e-paper: ", epd_width, "px", sep = '')
epd_height = tcon_lib.tcon_get_panel_height(board_id)
print("Height of e-paper: ", epd_height, "px", sep = '')

# Query the temperature of the T-CON board.
print("Querying board temperature...")
temperature = tcon_lib.tcon_get_temp(board_id)
if temperature < 0:
    print("Error: Cannot read temperature for reason:", error_to_string.get(temperature, "Unknown Error"))
    sys.exit(temperature)
else:
    print("Current temperature: ", temperature, "°C", sep = '')

# Clear the screen of the e-paper display.
print("Clearing the screen...")
retval = tcon_lib.tcon_clr_scr(board_id)
if retval != 0:
    print("Error: Could not clear screen for reason:", error_to_string.get(retval, "Unknown Error"))
    sys.exit(retval)
else:
   print("Successfully cleared screen!")

# Clear the screen of the e-paper display.
print("Clearing the screen...")
retval = tcon_lib.tcon_clr_scr(board_id)
if retval != 0:
    print("Error: Could not clear screen for reason:", error_to_string.get(retval, "Unknown Error"))
    sys.exit(retval)
else:
   print("Successfully cleared screen!")

# Clear the image buffer of the T-CON board by setting it to a
# well defined value (0xF0: white, 0x00: black).
print("Clearing image buffer of T-CON board...")
# retval = tcon_lib.tcon_fill_img_all(board_id, 0x00)
# if retval != 0:
#     print("Unable to clear image buffer for reason:", error_to_string.get(retval, "Unknown Error"))
#     sys.exit(retval)
# else:
#     print("Successfully cleared the image buffer!")

# Now we need to load the image from file. We use OpenCV to do so.
# However, we might use any third-party library to do so, as long
# as the resulting image stream (i.e. a char array) has the same
# format as the OpenCV image below.
print("Loading image from disk...")
image = Image.open(img_filename)
image = image.convert('L') # convert to grayscale
image = image.resize((epd_width, epd_height), Image.ANTIALIAS)

data = (ctypes.c_uint8 * (epd_width * epd_height))()
pixels = image.load()

for y in range(epd_height):
   for x in range(epd_width):
    #   print(x)
      data[x + y * epd_width] = pixels[x, y]

# After loading the display into RAM, we transfer it to the T-CON
# board. If you only want to update a part of the screen, you may
# specify the area.
print("Transferring image into buffer of T-CON board...")
retval = tcon_lib.tcon_ld_img(board_id, data, epd_width, epd_height, 0, 0)
if retval != 0:
    print("Error: Could not transfer image for reason:", error_to_string.get(retval, "Unknown Error"))
    sys.exit(retval)
else:
    print("Successfully transferred image!")

# Now that the image is transfered, we can finally display it.
print("Displaying image onto the e-paper...")
retval = tcon_lib.tcon_dpy_img(board_id, wf_mode, epd_width, epd_height, 0, 0)
if retval != 0:
    print("Error: Could not display image for reason:", error_to_string.get(retval, "Unknown Error"))
    sys.exit(retval)
else:
    print("Successfully displayed image!")
If I provided too little information please ask, I hope I can answer it properly.

Thank you for reading this dear user.
Reply
#2
I don't understand what you mean by this:
(Mar-30-2023, 12:07 AM)Fandrew Wrote: I have read about something like insert a python-written digital clock somehow as a picture.
To make an analog clock you could start with an image of a clock with no hands that would be the base for making an image of a clock with hands that displays the current time. Copy the no-hands image, draw the hands in the image, draw the image to the screen. Repeat every second or every minute.

You can read about using PIL to draw inside images here:

https://pillow.readthedocs.io/en/stable/...eDraw.html
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020