Skip to content

Commit a990c87

Browse files
authored
Merge pull request #85 from waynedyck/fix-pillow-10-errors
Fix Pillow 10 errors when running example files
2 parents 9e77061 + 97e4c54 commit a990c87

7 files changed

+40
-11
lines changed

examples/ssd1306_pillow_animate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"SSD1306 ORGANIC LED DISPLAY. THIS IS AN OLD SCHOOL DEMO SCROLLER!!"
5252
+ "GREETZ TO: LADYADA & THE ADAFRUIT CREW, TRIXTER, FUTURE CREW, AND FARBRAUSCH"
5353
)
54-
maxwidth, unused = draw.textsize(text, font=font)
54+
bbox = draw.textbbox((0, 0), text, font=font)
55+
maxwidth = bbox[2] - bbox[0]
5556

5657
# Set animation and sine wave parameters.
5758
amplitude = height / 4
@@ -73,15 +74,17 @@
7374
break
7475
# Calculate width but skip drawing if off the left side of screen.
7576
if x < -10:
76-
char_width, char_height = draw.textsize(c, font=font)
77+
bbox = draw.textbbox((0, 0), c, font=font)
78+
char_width, char_height = bbox[2] - bbox[0], bbox[3] - bbox[1]
7779
x += char_width
7880
continue
7981
# Calculate offset from sine wave.
8082
y = offset + math.floor(amplitude * math.sin(x / float(width) * 2.0 * math.pi))
8183
# Draw text.
8284
draw.text((x, y), c, font=font, fill=255)
8385
# Increment x position based on chacacter width.
84-
char_width, char_height = draw.textsize(c, font=font)
86+
bbox = draw.textbbox((0, 0), c, font=font)
87+
char_width, char_height = bbox[2] - bbox[0], bbox[3] - bbox[1]
8588
x += char_width
8689

8790
# Draw the image buffer.

examples/ssd1306_pillow_clock.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020

2121
i2c = board.I2C() # uses board.SCL and board.SDA
2222
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
23-
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
23+
24+
# Create the SSD1306 OLED class.
25+
# The first two parameters are the pixel width and pixel height.
26+
# Change these to the right size for your display!
27+
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
28+
29+
# Note you can change the I2C address, or add a reset pin:
30+
# oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
2431

2532
# Clear display.
2633
oled.fill(0)

examples/ssd1306_pillow_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161

6262
# Draw Some Text
6363
text = "Hello World!"
64-
(font_width, font_height) = font.getsize(text)
64+
bbox = font.getbbox(text)
65+
(font_width, font_height) = bbox[2] - bbox[0], bbox[3] - bbox[1]
6566
draw.text(
6667
(oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2),
6768
text,

examples/ssd1306_pillow_image_display.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020

2121
i2c = board.I2C() # uses board.SCL and board.SDA
2222
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
23-
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
23+
24+
# Create the SSD1306 OLED class.
25+
# The first two parameters are the pixel width and pixel height.
26+
# Change these to the right size for your display!
27+
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
28+
29+
# Note you can change the I2C address, or add a reset pin:
30+
# oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
2431

2532
# Clear display.
2633
oled.fill(0)

examples/ssd1306_pillow_ip.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ def get_ip_address(ifname):
3737
# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display
3838
i2c = board.I2C() # uses board.SCL and board.SDA
3939
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
40-
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
40+
41+
# Create the SSD1306 OLED class.
42+
# The first two parameters are the pixel width and pixel height.
43+
# Change these to the right size for your display!
44+
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
45+
46+
# Note you can change the I2C address, or add a reset pin:
47+
# oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
4148

4249
# This sets TEXT equal to whatever your IP address is, or isn't
4350
try:

examples/ssd1306_pillow_text.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display
2121
i2c = board.I2C() # uses board.SCL and board.SDA
2222
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
23-
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
23+
24+
# Create the SSD1306 OLED class.
25+
# The first two parameters are the pixel width and pixel height.
26+
# Change these to the right size for your display!
27+
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
28+
29+
# Note you can change the I2C address, or add a reset pin:
30+
# oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
2431

2532
# Clear display.
2633
oled.fill(0)

examples/ssd1306_simpletest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
# This example and library is meant to work with Adafruit CircuitPython API.
66

77
import board
8-
import displayio
98
import adafruit_ssd1306
109

11-
displayio.release_displays()
12-
1310
# Create the I2C bus interface.
1411
i2c = board.I2C() # uses board.SCL and board.SDA
1512
# i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040

0 commit comments

Comments
 (0)