I’m using an Adafruit SSD1306 128x64 OLED display with a Teensy 3.2 on a project I’m working on.
I’ve recently updated to version 1.3.0 of the Adafruit SSD1306 library in hopes that I will no longer have to modify the header within my projects for the library to work with the 128x64 OLED display. Unfortunately, the display does not do anything when code is uploaded with the PlatormIO plugin for VSCode. To make sure the display was working properly, I ran the Adafruit example program from the Arduino IDE, which works fine. However, if I copy the code into PIO and upload it there, nothing happens.
I imagine this is related to some library not being where it should / up to date or the recent update to PIO 4.0. Whatever the cause, I have no idea why this is happening and would appreciate any help. Thanks!
The Arduino Teensy framework comes with its own version of the Adafruit SSD1306 library. But if specified as above, PlatformIO picks the latest one from Adafruit.
Thanks! However, I think I forgot to mention that I am running the SSD1306 display using I2C, not SPI. I tried adding the library versions to my platformio.ini , however it the screen still does not display.
Note that the logic for deriving the I2C address didn’t work in my case. It’s 0x3C but the library uses 0x3D for all displays with a height other than 32 pixels.
I really appreciate your help, but unfortunately the display still isn’t working from the PIO IDE in VSCode. I’ve included all my code from the Arduino IDE and PIO. The only difference I can see initially is that I am using pin 5 for Reset, but it still works from the Arduino IDE if I disable that (it fails on a power cycle, but initial upload is fine). I have tried both addresses, 0x3C and 0x3D from both IDEs. Arduino only works with 0x3D, which makes sense, however PIO still won’t worth with either.
Arduino:
#include <Adafruit_SSD1306.h>
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 5 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();
display.drawPixel(10, 10, WHITE);
display.display();
}
void loop() { Serial.println(":)"); }
PlatformIO
#include <Arduino.h>
#include <Adafruit_SSD1306.h>
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 5 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
// Clear the buffer
display.clearDisplay();
display.drawPixel(10, 10, WHITE);
display.display();
}
void loop() { Serial.println(":)"); }
I’ve been struggling with this exact problem for 3 long weeks now. Put a delay(100) after Serial.begin(9600); and before if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C);.
I discovered this little fix by Using a scanner() to poll all I2C addresses and did one before and after display.begin(). and only the second one returned the address 0x3C is available.
Thinking about it, this screen uses an RC Timer to send a reset signal to the OLED. So in order for the screen to initialized the reset pulse must finish