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(":)"); }
platformio.ini
[env:teensy31]
platform = teensy
board = teensy31
framework = arduino
lib_archive = no
lib_deps =
Adafruit SSD1306@1.3.0
Adafruit GFX Library@1.5.6