0

2.14" diagonal eInk display with Metro M4 express boot don't
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

2.14" diagonal eInk display with Metro M4 express boot don't

by deryaakitis on Thu Aug 08, 2019 2:03 pm

Hi, I am trying to display a bmp file with 2.13" diagonal e-Ink display by using Metro M4 express boot. When I try the basic code (from CircuitPython website) below, it seems like working well, it follows the code to the end and prints every command they I put in the code on the pc screen. But nothing changes on e-Ink display device. Do you have an idea about how I can make it work?

output:
Code: Select all | TOGGLE FULL SIZE
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Creating display
File opened
Size: 66200
Image offset: 54
Header size: 40
Width: 212
Height: 104
Bit depth: 24
Image OK! Drawing...
Finished drawing
done

code:
Code: Select all | TOGGLE FULL SIZE
import digitalio
import busio
import board
from adafruit_epd.epd import Adafruit_EPD
from adafruit_epd.il0373 import Adafruit_IL0373

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
ecs = digitalio.DigitalInOut(board.D9)
dc = digitalio.DigitalInOut(board.D10)
srcs = None
rst = None
busy = None

print("Creating display")
display = Adafruit_IL0373(104, 212, spi, # 2.13" Tri-color display
cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
rst_pin=rst, busy_pin=busy)

display.rotation = 3

FILENAME = "blinka.bmp"

def read_le(s):
# as of this writting, int.from_bytes does not have LE support, DIY!
result = 0
shift = 0
for byte in bytearray(s):
result += byte << shift
shift += 8
return result

class BMPError(Exception):
pass

def display_bitmap(epd, filename):

try:
    f = open("/" + filename, "rb")
except OSError:
    print("Couldn't open file")
    return

print("File opened")
try:
    if f.read(2) != b'BM':  # check signature
        raise BMPError("Not BitMap file")

    bmpFileSize = read_le(f.read(4))
    f.read(4)  # Read & ignore creator bytes

    bmpImageoffset = read_le(f.read(4))  # Start of image data
    headerSize = read_le(f.read(4))
    bmpWidth = read_le(f.read(4))
    bmpHeight = read_le(f.read(4))
    flip = True

    print("Size: %d\nImage offset: %d\nHeader size: %d" %
          (bmpFileSize, bmpImageoffset, headerSize))
    print("Width: %d\nHeight: %d" % (bmpWidth, bmpHeight))

    if read_le(f.read(2)) != 1:
        raise BMPError("Not singleplane")
    bmpDepth = read_le(f.read(2))  # bits per pixel
    print("Bit depth: %d" % (bmpDepth))
    if bmpDepth != 24:
        raise BMPError("Not 24-bit")
    if read_le(f.read(2)) != 0:
        raise BMPError("Compressed file")

    print("Image OK! Drawing...")

    rowSize = (bmpWidth * 3 + 3) & ~3  # 32-bit line boundary

    for row in range(bmpHeight):  # For each scanline...
        if flip:  # Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize
        else:  # Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize

     
        f.seek(pos)
        rowdata = f.read(3*bmpWidth)
        for col in range(bmpWidth):
            b, g, r = rowdata[3*col:3*col+3]  # BMP files store RGB in BGR
            if r < 0x80 and g < 0x80 and b < 0x80:
                epd.pixel(col, row, Adafruit_EPD.BLACK)
            elif r >= 0x80 and g >= 0x80 and b >= 0x80:
                pass  # epd.pixel(row, col, Adafruit_EPD.WHITE)
            elif r >= 0x80:
                epd.pixel(col, row, Adafruit_EPD.RED)
except OSError:
    print("Couldn't read file")
except BMPError as e:
    print("Failed to parse BMP: " + e.args[0])
finally:
    f.close()
print("Finished drawing")
display.fill(Adafruit_EPD.WHITE)
display_bitmap(display, FILENAME)
display.display()

print ("done")
Attachments
IMG_9970-min.JPG
IMG_9970-min.JPG (925.49 KiB) Viewed 45 times
Last edited by adafruit_support_carter on Thu Aug 08, 2019 2:05 pm, edited 1 time in total.
Reason: added [code] tags

deryaakitis
 
Posts: 14
Joined: Thu Aug 08, 2019 12:54 pm

Re: 2.14" diagonal eInk display with Metro M4 express boot d

by adafruit_support_carter on Thu Aug 08, 2019 2:11 pm

Let's back up and try a non-BMP test code. Try this one:
https://github.com/adafruit/Adafruit_Ci ... pletest.py

You'll need to modify the code slightly to select the display you are using. See the section of code that looks like this:
Code: Select all | TOGGLE FULL SIZE
# give them all to our driver
print("Creating display")
#display = Adafruit_SSD1608(200, 200, spi,        # 1.54" HD mono display
#display = Adafruit_SSD1675(250, 122, spi,        # 2.13" HD mono display
#display = Adafruit_IL91874(176, 264, spi,        # 2.7" Tri-color display
#display = Adafruit_IL0373(152, 152, spi,         # 1.54" Tri-color display
#display = Adafruit_IL0373(128, 296, spi,         # 2.9" Tri-color display
#display = Adafruit_IL0398(400, 300, spi,         # 4.2" Tri-color display
display = Adafruit_IL0373(104, 212, spi,          # 2.13" Tri-color display
                          cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
                          rst_pin=rst, busy_pin=busy)


Change that to this:
Code: Select all | TOGGLE FULL SIZE
# give them all to our driver
print("Creating display")
#display = Adafruit_SSD1608(200, 200, spi,        # 1.54" HD mono display
display = Adafruit_SSD1675(250, 122, spi,        # 2.13" HD mono display
#display = Adafruit_IL91874(176, 264, spi,        # 2.7" Tri-color display
#display = Adafruit_IL0373(152, 152, spi,         # 1.54" Tri-color display
#display = Adafruit_IL0373(128, 296, spi,         # 2.9" Tri-color display
#display = Adafruit_IL0398(400, 300, spi,         # 4.2" Tri-color display
#display = Adafruit_IL0373(104, 212, spi,          # 2.13" Tri-color display
                          cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
                          rst_pin=rst, busy_pin=busy)

adafruit_support_carter
 
Posts: 13216
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.