Challenge - 5 Problems
OLED Mastery Badge
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 display?
Given the following Python code snippet for an SSD1306 OLED display connected via I2C on a Raspberry Pi, what text will appear on the screen?
Raspberry Pi
from PIL import Image, ImageDraw, ImageFont import board import busio import adafruit_ssd1306 i2c = busio.I2C(board.SCL, board.SDA) display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) display.fill(0) display.show() image = Image.new('1', (display.width, display.height)) draw = ImageDraw.Draw(image) font = ImageFont.load_default() draw.text((0, 0), 'Hello, Pi!', font=font, fill=255) display.image(image) display.show()
Attempts:
2 left
💡 Hint
Look at the coordinates used in draw.text and the display size.
✗ Incorrect
The text is drawn at position (0, 0), which is the top-left corner of the display. The display size is 128x32 pixels, so the text appears there. The code clears the display first, then draws the text and updates the screen.
🧠 Conceptual
intermediate1:30remaining
Why is the display.fill(0) method called before drawing?
In the SSD1306 OLED display code, what is the purpose of calling display.fill(0) before drawing new content?
Attempts:
2 left
💡 Hint
Think about what 'fill(0)' might mean for a pixel-based screen.
✗ Incorrect
Calling display.fill(0) turns off all pixels, effectively clearing the screen before drawing new content. This prevents old images or text from overlapping.
🔧 Debug
advanced2:30remaining
Identify the error causing the display to remain blank
This code is intended to display 'Test' on the OLED, but the screen stays blank. What is the cause?
Raspberry Pi
from PIL import Image, ImageDraw, ImageFont import board import busio import adafruit_ssd1306 i2c = busio.I2C(board.SCL, board.SDA) display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c) display.fill(0) display.show() image = Image.new('1', (display.width, display.height)) draw = ImageDraw.Draw(image) font = ImageFont.load_default() draw.text((0, 0), 'Test', font=font, fill=255) # Missing display.image(image) here display.show()
Attempts:
2 left
💡 Hint
Check if the image is sent to the display before calling show().
✗ Incorrect
The image with the drawn text must be sent to the display buffer using display.image(image) before calling display.show(). Without this, the display shows the previous or blank content.
📝 Syntax
advanced2:00remaining
Which code snippet correctly initializes the SSD1306 display?
Choose the correct Python code to initialize a 128x32 SSD1306 OLED display over I2C on a Raspberry Pi.
Attempts:
2 left
💡 Hint
Check the order of pins and display dimensions.
✗ Incorrect
Option C correctly uses board.SCL and board.SDA in the right order and specifies the correct display size 128x32 for this OLED. Option C swaps pins and dimensions incorrectly. Option C uses SPI class instead of I2C. Option C uses wrong display height.
🚀 Application
expert3:00remaining
How many pixels are lit after this drawing code runs?
Consider this code drawing a white rectangle on a 128x32 SSD1306 OLED display. How many pixels are lit (set to 1) after running?
Raspberry Pi
from PIL import Image, ImageDraw import board import busio import adafruit_ssd1306 i2c = busio.I2C(board.SCL, board.SDA) display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) display.fill(0) display.show() image = Image.new('1', (display.width, display.height)) draw = ImageDraw.Draw(image) draw.rectangle((10, 5, 20, 15), outline=255, fill=255) display.image(image) display.show()
Attempts:
2 left
💡 Hint
Calculate width and height of the rectangle and multiply.
✗ Incorrect
The rectangle covers from x=10 to 20 (inclusive) and y=5 to 15 (inclusive). Width = 20 - 10 + 1 = 11 pixels, height = 15 - 5 + 1 = 11 pixels. Total pixels lit = 11 * 11 = 121.
