Skip to content

Commit 02e70fa

Browse files
committed
DM: adding blinka support
1 parent c2a05b6 commit 02e70fa

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

adafruit_epd/il0373.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ def display(self):
166166

167167
self.update()
168168

169+
def image(self, image):
170+
"""Set buffer to value of Python Imaging Library image. The image should
171+
be in RGB mode and a size equal to the display size.
172+
"""
173+
if image.mode != 'RGB':
174+
raise ValueError('Image must be in mode RGB.')
175+
imwidth, imheight = image.size
176+
if imwidth != self.width or imheight != self.height:
177+
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
178+
.format(self.width, self.height))
179+
# Grab all the pixels from the image, faster than getpixel.
180+
pix = image.load()
181+
182+
for y in xrange(image.size[1]):
183+
for x in xrange(image.size[0]):
184+
if x == 0:
185+
x = 1
186+
p = pix[x, y]
187+
188+
addr = int(((self.width - x) * self.height + y)/8)
189+
if color == Adafruit_EPD.RED:
190+
addr = addr + self.bw_bufsize
191+
current = self.sram.read8(addr)
192+
193+
if p in ((0xFF, 0, 0), (0, 0, 0)):
194+
current = current & ~(1 << (7 - y%8))
195+
else:
196+
current = current | (1 << (7 - y%8))
197+
198+
self.sram.write8(addr, current)
199+
169200
def draw_pixel(self, x, y, color):
170201
"""draw a single pixel in the display buffer"""
171202
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):

examples/epd_blinka.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)