1
+ from PIL import Image
2
+ from PIL import ImageDraw
3
+ from PIL import ImageFont
4
+
5
+ import digitalio
6
+ import busio
7
+ import board
8
+ from adafruit_epd .epd import Adafruit_EPD
9
+ from adafruit_epd .il0373 import Adafruit_IL0373
10
+
11
+ # create the spi device and pins we will need
12
+ spi = busio .SPI (board .SCK , MOSI = board .MOSI , MISO = board .MISO )
13
+ ecs = digitalio .DigitalInOut (board .D22 )
14
+ dc = digitalio .DigitalInOut (board .D13 )
15
+ srcs = digitalio .DigitalInOut (board .D8 )
16
+ rst = digitalio .DigitalInOut (board .D19 )
17
+ busy = digitalio .DigitalInOut (board .D26 )
18
+
19
+ # give them all to our driver
20
+ display = Adafruit_IL0373 (152 , 152 , rst , dc , busy , srcs , ecs , spi )
21
+ # Create blank image for drawing.
22
+ # Make sure to create image with mode '1' for 1-bit color.
23
+ width = disp .width
24
+ height = disp .height
25
+ image = Image .new ('RGB' , (width , height ))
26
+
27
+ WHITE = (0xFF , 0xFF , 0xFF )
28
+ RED = (0xFF , 0x00 , 0x00 )
29
+ BLACK = (0x00 , 0x00 , 0x00 )
30
+ GRAY = (0x7F , 0x7F , 0x7F )
31
+
32
+ # clear the buffer
33
+ display .clear_buffer ()
34
+
35
+ # Get drawing object to draw on image.
36
+ draw = ImageDraw .Draw (image )
37
+
38
+ # Draw a white filled box to clear the image.
39
+ draw .rectangle ((0 ,0 ,width ,height ), outline = BLACK , fill = WHITE )
40
+
41
+ # Draw some shapes.
42
+ # First define some constants to allow easy resizing of shapes.
43
+ padding = 2
44
+ shape_width = 30
45
+ top = padding
46
+ bottom = height - padding
47
+ # Move left to right keeping track of the current x position for drawing shapes.
48
+ x = padding
49
+ # Draw an ellipse.
50
+ draw .ellipse ((x , top , x + shape_width , bottom ), outline = RED , fill = GRAY )
51
+ x += shape_width + padding
52
+ # Draw a rectangle.
53
+ draw .rectangle ((x , top , x + shape_width , bottom ), outline = RED , fill = BLACK )
54
+ x += shape_width + padding
55
+ # Draw a triangle.
56
+ draw .polygon ([(x , bottom ), (x + shape_width / 2 , top ), (x + shape_width , bottom )], outline = BLACK , fill = RED )
57
+ x += shape_width + padding
58
+ # Draw an X.
59
+ draw .line ((x , bottom , x + shape_width , top ), fill = RED )
60
+ draw .line ((x , top , x + shape_width , bottom ), fill = RED )
61
+ x += shape_width + padding
62
+
63
+ # Load default font.
64
+ font = ImageFont .load_default ()
65
+
66
+ # Alternatively load a TTF font. Make sure the .ttf font file is in the same directory as the python script!
67
+ # Some other nice fonts to try: http://www.dafont.com/bitmap.php
68
+ #font = ImageFont.truetype('Minecraftia.ttf', 8)
69
+
70
+ # Write two lines of text.
71
+ draw .text ((x , top ), 'Hello' , font = font , fill = RED )
72
+ draw .text ((x , top + 20 ), 'World!' , font = font , fill = RED )
73
+
74
+ # Display image.
75
+ display .image (image )
76
+
77
+ display .display ()
0 commit comments