Consider this Arduino code snippet using the SSD1306 OLED display with I2C. What text will appear on the screen?
#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() {}
Look at where the cursor is set and what text is printed before calling display.display().
The code sets the cursor at (10,10) and prints 'Hi!' with text size 2. Then display.display() updates the screen. So the text appears near the top-left corner.
In this Arduino code, what will be the visible result on the OLED screen?
#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() {}
Remember that display.display() sends the buffer to the screen, but clearDisplay() clears the buffer after that.
display.display() pushes the buffer (with 'Hello') to the screen. clearDisplay() then clears the internal buffer, but since there's no further display.display() call and loop() is empty, the screen retains the 'Hello' text.
Look at this Arduino code snippet. It compiles but the OLED screen stays blank. What is the main reason?
#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() {}
Check the I2C address used in display.begin().
Most SSD1306 OLED modules use I2C address 0x3C. Using 0x3D means the display is not found, so nothing shows.
Which of these code snippets will cause a compilation error when using the Adafruit_SSD1306 library?
Check the constant used for text color.
SSD1306_WHITE is the correct constant for white color in this library. Using WHITE alone causes a compilation error because it is undefined.
This code draws a filled rectangle on the OLED screen. How many pixels will be lit (white) after running?
#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() {}
Calculate width × height of the rectangle.
The rectangle is 20 pixels wide and 15 pixels tall. 20 × 15 = 300 pixels lit.
