Bird
0
0
Arduinoprogramming~20 mins

OLED display with I2C (SSD1306) in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
OLED Mastery Badge
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 display?

Consider this Arduino code snippet using the SSD1306 OLED display with I2C. What text will appear on the screen?

Arduino
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 10);
  display.println("Hi!");
  display.display();
}

void loop() {}
AThe OLED shows the text 'Hi!' near the top-left corner.
BThe OLED shows the text 'Hi!' centered on the screen.
CThe OLED remains blank because display.display() is missing.
DThe OLED shows random pixels because display.clearDisplay() is called after display.display().
Attempts:
2 left
💡 Hint

Look at where the cursor is set and what text is printed before calling display.display().

Predict Output
intermediate
2:00remaining
What happens if you call display.clearDisplay() after display.display()?

In this Arduino code, what will be the visible result on the OLED screen?

Arduino
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Hello");
  display.display();
  display.clearDisplay();
}

void loop() {}
AThe OLED screen remains blank.
BThe OLED shows 'Hello' text on the screen.
CThe OLED shows 'Hello' but flickers continuously.
DThe OLED shows random pixels because clearDisplay() corrupts the buffer.
Attempts:
2 left
💡 Hint

Remember that display.display() sends the buffer to the screen, but clearDisplay() clears the buffer after that.

🔧 Debug
advanced
2:00remaining
Why does this code fail to display text on the OLED?

Look at this Arduino code snippet. It compiles but the OLED screen stays blank. What is the main reason?

Arduino
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.println("Test");
  display.display();
}

void loop() {}
AThe display.begin() call is missing the reset pin argument.
BThe text size 1 is too small to be visible on the OLED.
CThe display.clearDisplay() must be called after display.display().
DThe I2C address 0x3D is incorrect for this OLED module; it should be 0x3C.
Attempts:
2 left
💡 Hint

Check the I2C address used in display.begin().

📝 Syntax
advanced
2:00remaining
Which option causes a compilation error?

Which of these code snippets will cause a compilation error when using the Adafruit_SSD1306 library?

Adisplay.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.println("Hi"); display.display();
Bdisplay.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.print("Hi"); display.display();
Cdisplay.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Hi"); display.display();
Ddisplay.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.println("Hi");
Attempts:
2 left
💡 Hint

Check the constant used for text color.

🚀 Application
expert
3:00remaining
How many pixels are lit after this code runs?

This code draws a filled rectangle on the OLED screen. How many pixels will be lit (white) after running?

Arduino
#include <Wire.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.fillRect(10, 10, 20, 15, SSD1306_WHITE);
  display.display();
}

void loop() {}
A300 pixels
B320 pixels
C310 pixels
D290 pixels
Attempts:
2 left
💡 Hint

Calculate width × height of the rectangle.