Bird
0
0

Identify the error in this code snippet meant to update an OLED with sensor data:

medium📝 Debug Q14 of 15
Raspberry Pi - Display and Output
Identify the error in this code snippet meant to update an OLED with sensor data:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=None)
disp.begin()
disp.clear()

image = Image.new('1', (disp.width, disp.height))
draw = ImageDraw.Draw(image)
font = ImageFont.load_default()

sensor_value = 30

draw.text((0, 0), f'Temp: {sensor_value}C', font=font, fill=255)

# Missing disp.image(image) here

disp.display()
AMissing disp.image(image) before disp.display()
BIncorrect font loading method
CImage size does not match display size
Ddisp.clear() should be called after disp.display()
Step-by-Step Solution
Solution:
  1. Step 1: Check display update sequence

    To update OLED, image must be sent with disp.image(image) before disp.display().
  2. Step 2: Identify missing command

    The code misses disp.image(image), so display shows old or blank content.
  3. Final Answer:

    Missing disp.image(image) before disp.display() -> Option A
  4. Quick Check:

    disp.image(image) needed before disp.display() [OK]
Quick Trick: Always call disp.image(image) before disp.display() [OK]
Common Mistakes:
MISTAKES
  • Forgetting to send image to display
  • Calling disp.clear() too late
  • Using wrong font loading method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes