Bird
0
0
Raspberry Piprogramming~20 mins

Displaying text on OLED in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OLED Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
AThe OLED displays the text 'Hello, Pi!' at the top-left corner.
BThe OLED displays an error message because the font is not loaded.
CThe OLED displays nothing because the display was not cleared.
DThe OLED displays the text 'Hello, Pi!' centered on the screen.
Attempts:
2 left
💡 Hint
Look at the coordinates used in draw.text and the font loading method.
🧠 Conceptual
intermediate
1: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?
ABecause disp.display() sends the drawn image buffer to the OLED hardware to update the screen.
BBecause disp.display() clears the screen before drawing new content.
CBecause disp.display() loads the font used for drawing text.
DBecause disp.display() initializes the OLED display hardware.
Attempts:
2 left
💡 Hint
Think about what happens after you draw on an image but before you see it on the screen.
🔧 Debug
advanced
2: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
AThe display is not initialized with disp.begin(), causing no output.
BThe font is not loaded correctly, so text cannot be drawn.
CThe image mode '1' is incorrect; it should be 'RGB'.
DThe code does not call disp.image(image) and disp.display(), so the image is never sent to the OLED.
Attempts:
2 left
💡 Hint
Check if the image is sent to the display after drawing.
📝 Syntax
advanced
1: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)
Adraw.text((0, 0), 'Hello World', font=font fill=255)
Bdraw.text[0, 0]('Hello World', font=font, fill=255)
Cdraw.text((0, 0), 'Hello World', font=font, fill=255)
Ddraw.text((0, 0), 'Hello World', font=font, fill='255')
Attempts:
2 left
💡 Hint
Check the function call syntax and parameter separators.
🚀 Application
expert
2: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?
A64 characters
B21 characters
C16 characters
D32 characters
Attempts:
2 left
💡 Hint
Divide the screen width by the character width to find how many fit horizontally.