Challenge - 5 Problems
OLED Sensor Display 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 for this code?
This code reads a temperature sensor and displays the value on an OLED screen. What will the OLED show?
Raspberry Pi
import board import adafruit_ssd1306 import digitalio import time i2c = board.I2C() oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) sensor_value = 25.3 oled.fill(0) oled.text(f"Temp: {sensor_value} C", 0, 0, 1) oled.show()
Attempts:
2 left
💡 Hint
Look at how the sensor_value is formatted inside the text function.
✗ Incorrect
The f-string inserts the float value 25.3 directly, so the OLED shows exactly 'Temp: 25.3 C'. No rounding or extra decimals are added.
🧠 Conceptual
intermediate1:30remaining
Why do we call oled.show() after oled.text()?
In code that writes text to an OLED screen, why is it necessary to call oled.show() after oled.text()?
Attempts:
2 left
💡 Hint
Think about how drawing on a screen usually works with buffers.
✗ Incorrect
The oled.text() function writes text to an internal memory buffer. The oled.show() function sends this buffer to the OLED hardware to update the visible display.
🔧 Debug
advanced2:00remaining
Why does this OLED code raise an error?
This code tries to display humidity on the OLED but raises an error. What is the cause?
Raspberry Pi
import board import adafruit_ssd1306 i2c = board.I2C() oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) humidity = 55 oled.fill(0) oled.text(f"Humidity: {humidity}%", 0, 0, 1) oled.show()
Attempts:
2 left
💡 Hint
Check how % is used inside f-strings in Python.
✗ Incorrect
The % character inside an f-string is treated as a normal character unless used in formatting expressions. Here it is safe and does not cause errors.
📝 Syntax
advanced2:00remaining
Which option fixes the syntax error in this OLED display code?
This code has a syntax error. Which option fixes it?
Raspberry Pi
import board import adafruit_ssd1306 i2c = board.I2C() oled = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) sensor = 30 oled.fill(0) oled.text(f"Value: {sensor", 0, 0, 1) oled.show()
Attempts:
2 left
💡 Hint
Check the placement of braces and commas inside the f-string.
✗ Incorrect
Option D correctly closes the curly brace and the string, and separates arguments with commas. Others have missing braces, quotes, or commas causing syntax errors.
🚀 Application
expert1:30remaining
How many lines of text can fit on a 128x32 OLED if each line is 8 pixels tall?
You want to display multiple sensor readings on a 128x32 OLED screen. Each text line uses 8 pixels in height. How many lines can you display without overlap?
Attempts:
2 left
💡 Hint
Divide the total height by the height of one line.
✗ Incorrect
The screen height is 32 pixels. Each line is 8 pixels tall. 32 / 8 = 4 lines fit exactly.
