Arduino Framerwork, Arduino Code, libraries still don't work

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??

Thanks for sharing the code AND compiler output… rather than a screenshot :wink: … the issue is not with the compiler, or PlatformIO, but is in the code itself… There is a } where is shouldn’t be… methinks you’re closing the setup function too early…

And VSCode is trying to tell you that something is wrong… see line 28 has a red sqiggle under display.display()… that’s your cue that there is something wrong at or above that line. Move that closing brace on line 24 to just above above the loop statement… (line 38 by my count) and it should now work. Or, at least it does for me… with the following platformio.ini configuration, and that one change to the code.

[env:esp32doit]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
lib_deps =
    Adafruit SSD1306
    Adafruit GFX Library

What exactly do you mean by this? That they exist, or that you have put them in the \lib folder of your project?

The ‘physical’ files are in the ‘physical’ folder.

Which I suppose is located in the second drawer down of the filing cabinet on the left? :rofl:

You said “All of these libraries are in the lib folder” … what lib folder? :man_facepalming:

1 Like

Every project has its own lib folder.

Yes… that is true. So with your statement

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>

Are you trying to say you found all of those files, and put them in the lib folder for your project? If so… I’m not surprised you’ve been having problems! Those header files are all provided by the framework or libraries, and should not be in the project lib folder unless you have modified them.

Then how do I get them in when they’re not available through library manager?
Since I’m linking my Arduino libraries, should I put these new libraries in there?

Bah! Typing! Need more characters to post this reply

Fixing the brace let it complile and upload once, but the OLED didn’t light up.
I was unable to upload it to a second DOIT, because:

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
*** [upload] Error 2

There’s nothing else on COM7.

OLED is lit up now, but 'Hello wold" isn’t displaying. It’s showing the Adafruit logo, unmoving.

1 Like

These two are provided by the Arduino framework - you will NEVER find them in the library manager.

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

These three …

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>

… are part of the Adafruit GFX library, and Adafruit SSD1306 library… if you have the library installed and PlatformIO knows where they are installed, they will be found.

Yes. If you are using lib_extra_dirs to tell PlatformIO where you Arduino libraries folder is, just instal libraries via the Arduino Library Manager as normal, and PlatformIO will find them.

To be saying ‘hello world’, you must be using different code to that you showed above. What does the code look like now?