epd_blinka.py
1 import digitalio 2 import busio 3 import board 4 5 from PIL import Image 6 from PIL import ImageDraw 7 from PIL import ImageFont 8 from adafruit_epd.epd import Adafruit_EPD 9 from adafruit_epd.il0373 import Adafruit_IL0373 # pylint: disable=unused-import 10 from adafruit_epd.il91874 import Adafruit_IL91874 # pylint: disable=unused-import 11 from adafruit_epd.il0398 import Adafruit_IL0398 # pylint: disable=unused-import 12 from adafruit_epd.ssd1608 import Adafruit_SSD1608 # pylint: disable=unused-import 13 from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import 14 from adafruit_epd.ssd1675b import Adafruit_SSD1675B # pylint: disable=unused-import 15 from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import 16 17 # create the spi device and pins we will need 18 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 19 20 # create the spi device and pins we will need 21 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 22 ecs = digitalio.DigitalInOut(board.D4) 23 dc = digitalio.DigitalInOut(board.D5) 24 srcs = None 25 rst = digitalio.DigitalInOut(board.D6) # can be None to not use this pin 26 busy = digitalio.DigitalInOut(board.D7) # can be None to not use this pin 27 28 29 # give them all to our driver 30 print("Creating display") 31 # display = Adafruit_SSD1608(200, 200, spi, # 1.54" HD mono display 32 # display = Adafruit_SSD1681(200, 200, spi, # 1.54" HD mono display (alt) 33 # display = Adafruit_SSD1675(122, 250, spi, # 2.13" HD mono display 34 # display = Adafruit_IL91874(176, 264, spi, # 2.7" Tri-color display 35 # display = Adafruit_IL0373(152, 152, spi, # 1.54" Tri-color display 36 # display = Adafruit_IL0373(128, 296, spi, # 2.9" Tri-color display 37 # display = Adafruit_IL0398(400, 300, spi, # 4.2" Tri-color display 38 # display = Adafruit_IL0373(104, 212, spi, # 2.13" Tri-color display 39 display = Adafruit_SSD1675B( 40 122, 41 250, 42 spi, # 2.13" HD mono display (rev B) 43 cs_pin=ecs, 44 dc_pin=dc, 45 sramcs_pin=srcs, 46 rst_pin=rst, 47 busy_pin=busy, 48 ) 49 50 display.rotation = 3 51 # Create blank image for drawing. 52 # Make sure to create image with mode '1' for 1-bit color. 53 width = display.width 54 height = display.height 55 image = Image.new("RGB", (width, height)) 56 57 WHITE = (0xFF, 0xFF, 0xFF) 58 RED = (0xFF, 0x00, 0x00) 59 BLACK = (0x00, 0x00, 0x00) 60 61 # clear the buffer 62 display.fill(Adafruit_EPD.WHITE) 63 64 # Get drawing object to draw on image. 65 draw = ImageDraw.Draw(image) 66 # empty it 67 draw.rectangle((0, 0, width, height), fill=WHITE) 68 69 # Draw an outline box 70 draw.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE) 71 72 # Draw some shapes. 73 # First define some constants to allow easy resizing of shapes. 74 padding = 5 75 shape_width = 30 76 top = padding 77 bottom = height - padding 78 # Move left to right keeping track of the current x position for drawing shapes. 79 x = padding 80 # Draw an ellipse. 81 draw.ellipse((x, top, x + shape_width, bottom), outline=RED, fill=WHITE) 82 x += shape_width + padding 83 # Draw a rectangle. 84 draw.rectangle((x, top, x + shape_width, bottom), outline=RED, fill=BLACK) 85 x += shape_width + padding 86 # Draw a triangle. 87 draw.polygon( 88 [(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)], 89 outline=BLACK, 90 fill=RED, 91 ) 92 x += shape_width + padding 93 # Draw an X. 94 draw.line((x, bottom, x + shape_width, top), fill=RED) 95 draw.line((x, top, x + shape_width, bottom), fill=RED) 96 x += shape_width + padding 97 98 # Load default font. 99 font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20) 100 101 # Alternatively load a TTF font. Make sure the .ttf font 102 # file is in the same directory as the python script! 103 # Some other nice fonts to try: http://www.dafont.com/bitmap.php 104 # font = ImageFont.truetype('Minecraftia.ttf', 8) 105 106 # Write two lines of text. 107 draw.text((x, top), "Hello", font=font, fill=RED) 108 draw.text((x, top + 20), "World!", font=font, fill=RED) 109 110 # Display image. 111 display.image(image) 112 113 display.display()