All of these libraries are in the lib folder:
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
I’ve been unsuccessful reproducing my Arduino IDE success. This OLED has been making me crazy. In Arduino, this code is a breeze. I used it all the time. In PlatformIO, I was getting hung up on the declaration:
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Now it’s just not processing the libraries as expected or something. Here are the errors:
Compiling .pio\build\esp32doit-devkit-v1\src\main.cpp.o
src\main.cpp:27:3: error: 'display' does not name a type
display.display();
^
src\main.cpp:28:8: error: expected constructor, destructor, or type conversion before '(' token
delay(2000); // Pause for 2 seconds
^
src\main.cpp:32:3: error: 'display' does not name a type
display.drawPixel(10, 10, SSD1306_WHITE);
^
src\main.cpp:36:3: error: 'display' does not name a type
display.display();
^
src\main.cpp:37:8: error: expected constructor, destructor, or type conversion before '(' token
delay(2000);
^
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1
=========================================================================== [FAILED] Took 3.64 seconds
And here’s the code:
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(9600,SERIAL_8N1);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("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();
delay(2000); // Pause for 2 seconds
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
void loop() {
delay(2000);
}
It hasn’t gotten to the OLED code, so I don’t know what’s going to fail there. Why isn’t it using the OLED language? Display- that’s a word, right??