Bird
0
0
Raspberry Piprogramming~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OLED Sensor Display 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 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()
AThe OLED displays: Temp: 25.30 C
BThe OLED displays: Temp: 25 C
CThe OLED displays: Temp: 25.3 C
DThe OLED displays nothing (blank screen)
Attempts:
2 left
💡 Hint
Look at how the sensor_value is formatted inside the text function.
🧠 Conceptual
intermediate
1: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()?
Aoled.text() writes text to a buffer; oled.show() updates the screen with the buffer content.
Boled.show() clears the screen before oled.text() writes text.
Coled.text() directly updates the screen; oled.show() is optional and does nothing.
Doled.show() turns the OLED on; oled.text() only works if the screen is on.
Attempts:
2 left
💡 Hint
Think about how drawing on a screen usually works with buffers.
🔧 Debug
advanced
2: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()
ANo error; code runs and displays 'Humidity: 55%'
BTypeError because humidity is an int, not a string
CRuntimeError because oled.text() does not accept % character
DSyntaxError due to % symbol inside f-string without escaping
Attempts:
2 left
💡 Hint
Check how % is used inside f-strings in Python.
📝 Syntax
advanced
2: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()
Aoled.text(f"Value: sensor", 0, 0, 1)
Boled.text(f"Value: {sensor}" 0, 0, 1)
Coled.text(f"Value: {sensor})", 0, 0, 1)
Doled.text(f"Value: {sensor}", 0, 0, 1)
Attempts:
2 left
💡 Hint
Check the placement of braces and commas inside the f-string.
🚀 Application
expert
1: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?
A32 lines
B4 lines
C8 lines
D16 lines
Attempts:
2 left
💡 Hint
Divide the total height by the height of one line.