PlatformIO Community

Trying to install adafruit ssd1305 OLED library and compile failed

This is a library to drive an OLED that I have. I can do it on Arduino IDE so I thought I would try platformio on vscode. I’ve been using platformio on vscode for teensy development. So after installing ssd1305 library and adafruit gfx library, I was reminded that I was missing some .h files. I went down the path of gfx library dependency and installed adafruit busio, which has no dependency. After that, here is the compilation message. It seems that platformio can’t find simple files like Wire.h that should be in the core folder. I’m using ESP32 boards so I installed the package for that. I have a blank setup and loop just to see if it compiles and it doesn’t. I wonder what went wrong.

My code:

#include <Arduino.h>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

Compilation message:

> Executing task: C:\Users\user\.platformio\penv\Scripts\platformio.exe run --environment esp32doit-devkit-v1 <

Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Library Manager: Installing adafruit/Adafruit SSD1305 @ ^2.2.1
Unpacking  [####################################]  100%
Library Manager: Adafruit SSD1305@2.2.1 has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing Adafruit GFX Library
Unpacking  [####################################]  100%
Library Manager: Adafruit GFX Library@1.11.1 has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing Adafruit BusIO
Unpacking  [####################################]  100%
Library Manager: Adafruit BusIO@1.11.6 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 (4.2.0) > DOIT ESP32 DEVKIT V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20002.220503 (2.0.2)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit SSD1305 @ 2.2.1
|   |-- Adafruit GFX Library @ 1.11.1
|   |   |-- Adafruit BusIO @ 1.11.6
|   |-- Adafruit BusIO @ 1.11.6
|-- Adafruit GFX Library @ 1.11.1
|   |-- Adafruit BusIO @ 1.11.6
|-- Adafruit BusIO @ 1.11.6
Building in release mode
Compiling .pio\build\esp32doit-devkit-v1\src\main.cpp.o
Generating partitions .pio\build\esp32doit-devkit-v1\partitions.bin
Compiling .pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_I2CDevice.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_SPIDevice.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\Adafruit_GFX.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\Adafruit_SPITFT.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\glcdfont.c.o
Compiling .pio\build\esp32doit-devkit-v1\lib4c7\Adafruit SSD1305\Adafruit_SSD1305.cpp.o
Archiving .pio\build\esp32doit-devkit-v1\libFrameworkArduinoVariant.a
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_BusIO_Register.h:9,
                 from .pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_BusIO_Register.cpp:1:
.pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_I2CDevice.cpp:1:
.pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_SPIDevice.cpp:1:
.pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_SPIDevice.h:9:10: fatal error: SPI.h: No such file or directory

*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SPI.h"
* Web  > https://registry.platformio.org/search?q=header:SPI.h
*
*************************************************************

 #include <SPI.h>
          ^~~~~~~
compilation terminated.
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\Esp.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\FirmwareMSC.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\FunctionalInterrupt.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\HWCDC.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\IPv6Address.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\MD5Builder.cpp.o
Compiling .pio\build\esp32doit-devkit-v1\FrameworkArduino\Print.cpp.o
*** [.pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_SPIDevice.cpp.o] Error 1
*** [.pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_I2CDevice.cpp.o] Error 1
*** [.pio\build\esp32doit-devkit-v1\lib68e\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o] Error 1
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit GFX Library/Adafruit_GrayOLED.h:30,
                 from .pio/libdeps/esp32doit-devkit-v1/Adafruit GFX Library/Adafruit_GrayOLED.cpp:20:
.pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o] Error 1
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit GFX Library/Adafruit_SPITFT.cpp:36:
.pio/libdeps/esp32doit-devkit-v1/Adafruit GFX Library/Adafruit_SPITFT.h:26:10: fatal error: SPI.h: No such file or directory

*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SPI.h"
* Web  > https://registry.platformio.org/search?q=header:SPI.h
*
*************************************************************

 #include <SPI.h>
          ^~~~~~~
compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\lib44e\Adafruit GFX Library\Adafruit_SPITFT.cpp.o] Error 1
In file included from .pio/libdeps/esp32doit-devkit-v1/Adafruit GFX Library/Adafruit_GrayOLED.h:30,
                 from .pio/libdeps/esp32doit-devkit-v1/Adafruit SSD1305/Adafruit_SSD1305.h:18,
                 from .pio/libdeps/esp32doit-devkit-v1/Adafruit SSD1305/Adafruit_SSD1305.cpp:19:
.pio/libdeps/esp32doit-devkit-v1/Adafruit BusIO/Adafruit_I2CDevice.h:5:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\lib4c7\Adafruit SSD1305\Adafruit_SSD1305.cpp.o] Error 1
======================================================================================= [FAILED] Took 5.80 seconds =======================================================================================The terminal process "C:\Users\user\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'esp32doit-devkit-v1'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Duplicate of Library install problem - #3 by maxgerhardt. At least a

#include <Adafruit_SSD1305.h> 
#include < Adafruit_GFX.h>

should be placed in src/main.cpp.

Thanks for the pointer. I added Wire.h and SPI.h instead of those two and the “empty” project compiled.

Now a different problem arose. When I have the following program in Arduino IDE, it works as expected. But when I have it in platformio, it doesn’t work. The Serial pass through isn’t working properly. I chose DOIT ESP32 module although mine is an unknown dev board. Each passed through message starts with a few messed up characters. In Arduino IDE, every character works. Then I changed from esp32doit-devkit-v1 to esp32dev and the program completely halted. I can see bootloader message at 115200 but nothing else. There should be some messages at 9600 at start up and the OLED should have content. I got nothing.

So what differences do these different ESP32 dev board names have? I know some ESP32 modules have PSRAM and larger FLASH. What else? It seems that I can develop code in vscode+platformio for ESP32 but have to compile in Arduino IDE.

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1305.h>

// Used for software SPI
#define OLED_CLK 18
#define OLED_MOSI 23

// Used for software or hardware SPI
#define OLED_CS 5
#define OLED_DC 4

// Used for I2C or SPI
#define OLED_RESET 2

Adafruit_SSD1305 display(128, 64, &SPI, OLED_DC, OLED_RESET, OLED_CS, 7000000UL);

uint8_t read_buf[256];

void testdrawchar(void) {
  display.setTextSize(1);
  display.setTextWrap(false);
  display.setTextColor(WHITE);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    if ((i > 0) && (i % 21 == 0))
      display.println();
  }    
  display.display();
}

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600,SERIAL_8N1,27,26);  // begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL);
  Serial.println("ESP32 SDI-12");

  while (! Serial) delay(100);
  Serial.println("SSD1305 OLED test");
  
  if ( ! display.begin(0x3C) ) {
     Serial.println("Unable to initialize OLED");
     while (1) yield();
  }

  // init done
  display.clearDisplay();   // clears the screen and buffer

  // draw a single pixel
  display.drawPixel(10, 10, WHITE);
  display.display();
  delay(1000);

  testdrawchar();
  delay(3000);
  display.clearDisplay();
  display.display();
}

void loop()
{
  uint32_t avl1=Serial1.available();
  uint32_t avl0=Serial.available();
  if (avl0)
  {
    Serial.read(read_buf,avl0);
    Serial1.write(read_buf,avl0);
  }
  if (avl1)
  {
    Serial1.read(read_buf,avl1);
    Serial.write(read_buf,avl1);
  }
}

Even after commenting out the display code and Serial1, I still got no running code at all.
I erased FLASH once also. No go. On Arduino IDE I chose ESP32 Dev module, not a problem.

Regardless what code I compile, the esp32 just hangs after bootloader message. Never printing anything out.

What’s the Arduino-ESP32 tools settings menu? (selected board, flash frequency, flash mode, etc.). Have you matched that with PlatformIO settings 1:1?

image
This is from arduino IDE. How do I access this on platformio? I was wondering about that but there’s no a list or options I can find on platformio.

I also get this error sometimes:
image

My platformio.ini is bare:

[env:esp32doit-devkit-v1]

platform = espressif32

board = esp32doit-devkit-v1

framework = arduino

lib_deps =

    adafruit/Adafruit SSD1305@^2.2.1

    adafruit/Adafruit GFX Library@^1.11.1

    adafruit/Adafruit BusIO@^1.11.6

I see on the compile message:
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
So the ram info is wrong and I don’t have the right flash size or PSRAM option. I ESP32 IDF I can set all these in the config and where are these in platformio?

Based on that you should be using

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_upload.flash_size = 16MB
build_flags =
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue
lib_deps =
    adafruit/Adafruit SSD1305@^2.2.1
    adafruit/Adafruit GFX Library@^1.11.1
    adafruit/Adafruit BusIO@^1.11.6

as your platformio.ini. Does that change anything?

Thanks for your time! I did a clean all, closed vscode (all windows), deleted the build folder. Restarted vscode, build and then upload. It turned out that this particular board has only 4MB FLASH. I checked with esptool flash_id command. So I changed flash to 4MB. The program works, but with an issue. I have a serial port device connected to Serial1. This device responds with correct info if I compiled and uploaded from arduino IDE but in platformio, the first few characters are messed up:
Here from Arduino IDE’s serial monitor.

08:54:05.080 -> rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
08:54:05.080 -> configsip: 0, SPIWP:0xee
08:54:05.080 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
08:54:05.080 -> mode:DIO, clock div:1
08:54:05.080 -> load:0x3fff0030,len:1324
08:54:05.080 -> ho 0 tail 12 room 4
08:54:05.080 -> load:0x40078000,len:13508
08:54:05.080 -> load:0x40080400,len:3604
08:54:05.080 -> entry 0x400805f0
08:54:06.040 -> ESP32 SDI-12
08:54:09.031 -> SSD1305 OLED test
08:54:25.374 -> ⸮⸮b⸮ՑɁ  SDITRD152
08:54:30.480 -> z0014
08:54:30.480 -> z
08:54:37.320 -> ⸮	r⸮⸮⸮⸮⸮j⸮r⸮⸮⸮⸮⸮j⸮r⸮⸮⸮⸮⸮j⸮r⸮⸮⸮⸮⸮j

I pressed reset on the board and my serial monitor is at 115200, 9600 for Serial1. You can see, down to “SSD1305 OLED test” line were all printed by esp32 and all correct. Then after that I sent some commands to the serial device and its responses were messed up. I can probe the Serial1 pins with my logic analyzer to see if there are any difference between arduino IDE and platformio.

I noticed that despite the ini change, this still says I have 320KB of RAM. Shouldn’t I have 520KB like typical ESP32 processors do?

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   5.4% (used 17824 bytes from 327680 bytes)
Flash: [==        ]  21.2% (used 278301 bytes from 1310720 bytes)

This still appears:
image

Try opening a CLI and doing a pio upgrade --dev to get the latest coe version then, then restart VSCode. If it still appears, there mightsomething wrong.

What version of the Arduino-ESP32 core are you using in the Arduino IDE? (Arduino IDE → Tools → Board → Board Manager → esp32)

My Arduino IDE has a relatively old ESP32-Arduino 1.0.6 (probably running on ESP-IDF 3v3). The highest I can see is 2.0.3
My platformio ESP32 arduino was installed yesterday so should be latest. It says “version”: “3.20002.220503”, probably pio version.
I upgraded pio core to 6.0.2a2. Hope it won’t break my teensy 4.1 toolchain based on pio as well. I hate to upgrade because of the unknowns and some of my work is critical.

After all these and a clean all, the library folder in pio, next to build folder, has disappeared, which never happened even with clean all. I restarted vscode, compile, upload. Opened arduino IDE serial monitor. Same thing. Display code is running but serial passthru is partly messed up. The error message continues to pop up:
image
Maybe I should uninstall esp32 arduino and start from scratch?

Then you should use platform = espressif32@3.5.0 in the platformio.ini instead of the previous platform = espressif32 to get the 1.0.6 core equivalently.