Skip to content

Commit 27f023e

Browse files
authored
Merge pull request #61 from ladyada/master
blinka image
2 parents f3924f6 + b55552f commit 27f023e

6 files changed

+187
-32
lines changed

adafruit_epd/epd.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def display(self): # pylint: disable=too-many-branches
107107
databyte = self._spi_transfer(databyte)
108108
self.sram.cs_pin.value = True
109109
else:
110-
for databyte in self._buffer1:
111-
self._spi_transfer(databyte)
110+
self._spi_transfer(self._buffer1)
112111

113112
self._cs.value = True
114113
self.spi_device.unlock()
@@ -140,8 +139,7 @@ def display(self): # pylint: disable=too-many-branches
140139
databyte = self._spi_transfer(databyte)
141140
self.sram.cs_pin.value = True
142141
else:
143-
for databyte in self._buffer2:
144-
self._spi_transfer(databyte)
142+
self._spi_transfer(self._buffer2)
145143

146144
self._cs.value = True
147145
self.spi_device.unlock()
@@ -171,23 +169,39 @@ def command(self, cmd, data=None, end=True):
171169

172170
if data is not None:
173171
self._dc.value = True
174-
for b in data:
175-
self._spi_transfer(b)
172+
self._spi_transfer(data)
176173
if end:
177174
self._cs.value = True
178175
self.spi_device.unlock()
179176

180177
return ret
181178

182-
def _spi_transfer(self, databyte):
183-
"""Transfer one byte, toggling the cs pin if required by the EPD chipset"""
184-
self._spibuf[0] = databyte
185-
if self._single_byte_tx:
186-
self._cs.value = False
187-
self.spi_device.write_readinto(self._spibuf, self._spibuf)
188-
if self._single_byte_tx:
189-
self._cs.value = True
190-
return self._spibuf[0]
179+
def _spi_transfer(self, data):
180+
"""Transfer one byte or bytearray, toggling the cs pin if required by the EPD chipset"""
181+
if isinstance(data, int): # single byte!
182+
self._spibuf[0] = data
183+
184+
# easy & fast case: array and no twiddling
185+
if not self._single_byte_tx and isinstance(data, bytearray):
186+
self.spi_device.write(data)
187+
return None
188+
189+
# if its a single byte
190+
if isinstance(data, int): # single byte!
191+
if self._single_byte_tx:
192+
self._cs.value = False
193+
try:
194+
self.spi_device.write_readinto(self._spibuf, self._spibuf)
195+
except NotImplementedError:
196+
self.spi_device.write(self._spibuf)
197+
if self._single_byte_tx:
198+
self._cs.value = True
199+
return self._spibuf[0]
200+
201+
if isinstance(data, bytearray):
202+
for x in data:
203+
self._spi_transfer(x)
204+
return None
191205

192206
def power_up(self):
193207
"""Power up the display in preparation for writing RAM and updating.

examples/epd_bonnet.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@
6161
draw.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE)
6262
# Draw some shapes.
6363
# First define some constants to allow easy resizing of shapes.
64-
padding = 5
65-
shape_width = 30
66-
top = padding
67-
bottom = height - padding
64+
PADDING = 5
65+
SHAPE_WIDTH = 30
66+
TOP = PADDING
67+
bottom = height - PADDING
6868
# Move left to right keeping track of the current x position for drawing shapes.
69-
x = padding
69+
x = PADDING
7070
# Draw an ellipse.
71-
draw.ellipse((x, top, x + shape_width, bottom), outline=BLACK, fill=WHITE)
72-
x += shape_width + padding
71+
draw.ellipse((x, TOP, x + SHAPE_WIDTH, bottom), outline=BLACK, fill=WHITE)
72+
x += SHAPE_WIDTH + PADDING
7373
# Draw a rectangle.
74-
draw.rectangle((x, top, x + shape_width, bottom), outline=WHITE, fill=BLACK)
75-
x += shape_width + padding
74+
draw.rectangle((x, TOP, x + SHAPE_WIDTH, bottom), outline=WHITE, fill=BLACK)
75+
x += SHAPE_WIDTH + PADDING
7676
# Draw a triangle.
7777
draw.polygon(
78-
[(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)],
78+
[(x, bottom), (x + SHAPE_WIDTH / 2, TOP), (x + SHAPE_WIDTH, bottom)],
7979
outline=BLACK,
8080
fill=WHITE,
8181
)
82-
x += shape_width + padding
82+
x += SHAPE_WIDTH + PADDING
8383
# Draw an X.
84-
draw.line((x, bottom, x + shape_width, top), fill=BLACK)
85-
draw.line((x, top, x + shape_width, bottom), fill=BLACK)
86-
x += shape_width + padding
84+
draw.line((x, bottom, x + SHAPE_WIDTH, TOP), fill=BLACK)
85+
draw.line((x, TOP, x + SHAPE_WIDTH, bottom), fill=BLACK)
86+
x += SHAPE_WIDTH + PADDING
8787

8888
# Load default font.
8989
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)
@@ -94,8 +94,8 @@
9494
# font = ImageFont.truetype('Minecraftia.ttf', 8)
9595

9696
# Write two lines of text.
97-
draw.text((x, top), "Hello", font=font, fill=BLACK)
98-
draw.text((x, top + 20), "World!", font=font, fill=BLACK)
97+
draw.text((x, TOP), "Hello", font=font, fill=BLACK)
98+
draw.text((x, TOP + 20), "World!", font=font, fill=BLACK)
9999

100100
while True:
101101
if not switch1.value:
@@ -106,7 +106,8 @@
106106
time.sleep(0.01)
107107
if not switch2.value:
108108
print("Switch 2")
109-
display.fill(Adafruit_EPD.WHITE)
109+
blinkaimage = Image.open("epd_bonnet_blinka_250x122.bmp")
110+
display.image(blinkaimage)
110111
display.display()
111112
while not switch2.value:
112113
time.sleep(0.01)
89.6 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT

examples/feather_epd_blinka.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import digitalio
6+
import busio
7+
import board
8+
from adafruit_epd.epd import Adafruit_EPD
9+
from adafruit_epd.ssd1680 import Adafruit_SSD1680
10+
11+
# create the spi device and pins we will need
12+
spi = busio.SPI(board.EPD_SCK, MOSI=board.EPD_MOSI, MISO=None)
13+
epd_cs = digitalio.DigitalInOut(board.EPD_CS)
14+
epd_dc = digitalio.DigitalInOut(board.EPD_DC)
15+
epd_reset = digitalio.DigitalInOut(board.EPD_RESET)
16+
epd_busy = digitalio.DigitalInOut(board.EPD_BUSY)
17+
srcs = None
18+
19+
display = Adafruit_SSD1680(
20+
122,
21+
250,
22+
spi,
23+
cs_pin=epd_cs,
24+
dc_pin=epd_dc,
25+
sramcs_pin=srcs,
26+
rst_pin=epd_reset,
27+
busy_pin=epd_busy,
28+
)
29+
30+
display.rotation = 3
31+
display.fill(Adafruit_EPD.WHITE)
32+
33+
display.fill_rect(20, 20, 50, 60, Adafruit_EPD.BLACK)
34+
display.hline(80, 30, 60, Adafruit_EPD.BLACK)
35+
display.vline(80, 30, 60, Adafruit_EPD.BLACK)
36+
37+
# draw repeatedly with pauses
38+
while True:
39+
display.display()
40+
time.sleep(15)

examples/feather_epd_blinka_pillow.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import digitalio
6+
import busio
7+
import board
8+
from PIL import Image
9+
from PIL import ImageDraw
10+
from PIL import ImageFont
11+
from adafruit_epd.epd import Adafruit_EPD
12+
from adafruit_epd.ssd1680 import Adafruit_SSD1680
13+
14+
# create the spi device and pins we will need
15+
spi = busio.SPI(board.EPD_SCK, MOSI=board.EPD_MOSI, MISO=None)
16+
epd_cs = digitalio.DigitalInOut(board.EPD_CS)
17+
epd_dc = digitalio.DigitalInOut(board.EPD_DC)
18+
epd_reset = digitalio.DigitalInOut(board.EPD_RESET)
19+
epd_busy = digitalio.DigitalInOut(board.EPD_BUSY)
20+
srcs = None
21+
22+
display = Adafruit_SSD1680(
23+
122,
24+
250,
25+
spi,
26+
cs_pin=epd_cs,
27+
dc_pin=epd_dc,
28+
sramcs_pin=srcs,
29+
rst_pin=epd_reset,
30+
busy_pin=epd_busy,
31+
)
32+
33+
display.rotation = 3
34+
# Create blank image for drawing.
35+
# Make sure to create image with mode '1' for 1-bit color.
36+
width = display.width
37+
height = display.height
38+
image = Image.new("RGB", (width, height))
39+
40+
WHITE = (0xFF, 0xFF, 0xFF)
41+
BLACK = (0x00, 0x00, 0x00)
42+
43+
# clear the display
44+
display.fill(Adafruit_EPD.WHITE)
45+
46+
# Get drawing object to draw on image.
47+
draw = ImageDraw.Draw(image)
48+
# empty it
49+
draw.rectangle((0, 0, width, height), fill=WHITE)
50+
51+
# Draw an outline box
52+
draw.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE)
53+
# Draw some shapes.
54+
# First define some constants to allow easy resizing of shapes.
55+
padding = 5
56+
shape_width = 30
57+
top = padding
58+
bottom = height - padding
59+
# Move left to right keeping track of the current x position for drawing shapes.
60+
x = padding
61+
# Draw an ellipse.
62+
draw.ellipse((x, top, x + shape_width, bottom), outline=BLACK, fill=WHITE)
63+
x += shape_width + padding
64+
# Draw a rectangle.
65+
draw.rectangle((x, top, x + shape_width, bottom), outline=WHITE, fill=BLACK)
66+
x += shape_width + padding
67+
# Draw a triangle.
68+
draw.polygon(
69+
[(x, bottom), (x + shape_width / 2, top), (x + shape_width, bottom)],
70+
outline=BLACK,
71+
fill=WHITE,
72+
)
73+
x += shape_width + padding
74+
# Draw an X.
75+
draw.line((x, bottom, x + shape_width, top), fill=BLACK)
76+
draw.line((x, top, x + shape_width, bottom), fill=BLACK)
77+
x += shape_width + padding
78+
79+
# Load default font.
80+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)
81+
82+
# Alternatively load a TTF font. Make sure the .ttf font
83+
# file is in the same directory as the python script!
84+
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
85+
# font = ImageFont.truetype('Minecraftia.ttf', 8)
86+
87+
# Write two lines of text.
88+
draw.text((x, top), "Hello", font=font, fill=BLACK)
89+
draw.text((x, top + 20), "World!", font=font, fill=BLACK)
90+
91+
display.image(image)
92+
display.display()
93+
94+
time.sleep(10)
95+
96+
blinkaimage = Image.open("examples/epd_bonnet_blinka_250x122.bmp")
97+
display.image(blinkaimage)
98+
display.display()

0 commit comments

Comments
 (0)