Challenge - 5 Problems
OLED Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output on the OLED?
Given the following Python code snippet for a Raspberry Pi OLED display, what text will appear on the screen?
Raspberry Pi
from PIL import Image, ImageDraw, ImageFont import Adafruit_SSD1306 # Initialize display disp = Adafruit_SSD1306.SSD1306_128_64(rst=None) disp.begin() disp.clear() disp.display() # Create blank image for drawing width = disp.width height = disp.height image = Image.new('1', (width, height)) draw = ImageDraw.Draw(image) # Load default font font = ImageFont.load_default() # Draw text draw.text((0, 0), 'Hello, Pi!', font=font, fill=255) # Display image disp.image(image) disp.display()
Attempts:
2 left
💡 Hint
Look at the coordinates used in draw.text and the font loading method.
✗ Incorrect
The text 'Hello, Pi!' is drawn at coordinates (0, 0) using the default font, so it appears at the top-left corner. The display is cleared before drawing, so the text is visible.
🧠 Conceptual
intermediate1:30remaining
Why do we call disp.display() after drawing?
In Raspberry Pi OLED programming, why is it necessary to call disp.display() after drawing on the image?
Attempts:
2 left
💡 Hint
Think about what happens after you draw on an image but before you see it on the screen.
✗ Incorrect
Drawing commands modify an image buffer in memory. Calling disp.display() sends this buffer to the OLED hardware so the changes appear on the screen.
🔧 Debug
advanced2:30remaining
Why does this OLED text not show?
This code runs without errors but the OLED screen stays blank. What is the problem?
Raspberry Pi
from PIL import Image, ImageDraw, ImageFont import Adafruit_SSD1306 disp = Adafruit_SSD1306.SSD1306_128_64(rst=None) disp.begin() width = disp.width height = disp.height image = Image.new('1', (width, height)) draw = ImageDraw.Draw(image) font = ImageFont.load_default() draw.text((10, 10), 'Test', font=font, fill=255) # Missing disp.image(image) call # Missing disp.display() call
Attempts:
2 left
💡 Hint
Check if the image is sent to the display after drawing.
✗ Incorrect
Drawing on the image alone does not update the OLED. You must call disp.image(image) to set the buffer and disp.display() to refresh the screen.
📝 Syntax
advanced1:30remaining
Identify the syntax error in this OLED text code
Which option contains the correct syntax to draw text on the OLED using PIL and Adafruit_SSD1306?
Raspberry Pi
draw.text((0, 0), 'Hello World', font=font, fill=255)
Attempts:
2 left
💡 Hint
Check the function call syntax and parameter separators.
✗ Incorrect
Option C uses correct function call syntax with parentheses and commas. Option C uses brackets incorrectly. Option C misses a comma. Option C uses fill as a string instead of an integer.
🚀 Application
expert2:00remaining
How many characters fit on a 128x64 OLED with default font?
Using the default PIL font (approximately 6 pixels wide and 8 pixels tall per character), how many characters can fit on a 128x64 OLED screen in a single line?
Attempts:
2 left
💡 Hint
Divide the screen width by the character width to find how many fit horizontally.
✗ Incorrect
128 pixels width divided by 6 pixels per character equals about 21 characters per line. However, the default font is actually 6 pixels wide including spacing, so 21 is correct. But since 6*21=126, 21 fits. Option B says 32 which is too many. So correct answer is A.
