ESP32 reboot loop in creat OLED display object

Hi , everyone
When I create an OLED object, the program seems to be crushing :sob:. I am not sure if there is something wrong with the way I create the object. Could you please help me check it out? :shushing_face:

[my code]

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

class MainView
{
private:
    Adafruit_SSD1306 myDisplay;

public:
    MainView() : myDisplay(128, 64, &Wire, -1){};
    void Show() { myDisplay.display(); };
};

MainView mainView;

void setup()
{
    Serial.begin(115200);
    mainView.Show();
}
void loop() {}

[platfomio.ini]

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino

monitor_speed = 115200
monitor_rts = 1
monitor_filters = esp32_exception_decoder

lib_deps = 
	adafruit/Adafruit SSD1306@^2.5.7
	adafruit/Adafruit GFX Library@^1.11.7

[error information]

ELF file SHA256: c1f939fb7d5dee0f

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4
[    26][E][Wire.cpp:381] setClock(): could not acquire lock
[    26][E][Wire.cpp:422] beginTransmission(): could not acquire lock
[    27][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    32][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    37][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    42][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    47][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    52][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    57][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer
[    63][E][Wire.cpp:422] beginTransmission(): could not acquire lock
[    70][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    75][E][Wire.cpp:526] write(): NULL TX buffer pointer
[    80][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer
[    86][E][Wire.cpp:422] beginTransmission(): could not acquire lock
[    92][E][Wire.cpp:526] write(): NULL TX buffer pointer
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d1f22  PS      : 0x00060a30  A0      : 0x800d1575  A1      : 0x3ffc5340
A2      : 0x3ffc1c50  A3      : 0x000003ff  A4      : 0x00000000  A5      : 0x00000001  
A6      : 0x0000ffff  A7      : 0x0000007f  A8      : 0x800d1eef  A9      : 0x3ffc5310
A10     : 0x3ffc1ce8  A11     : 0x00000040  A12     : 0x00000000  A13     : 0x00000006  
A14     : 0x000000ff  A15     : 0x400d15a4  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x4008655d  LEND    : 0x4008656d  LCOUNT  : 0xfffffffe  


Backtrace: 0x400d1f1f:0x3ffc5340 0x400d1572:0x3ffc5370 0x400d390e:0x3ffc53a0

  #0  0x400d1f1f:0x3ffc5340 in Adafruit_SSD1306::display() at .pio/libdeps/nodemcu-32s/Adafruit SSD1306/Adafruit_SSD1306.cpp:1022
  #1  0x400d1572:0x3ffc5370 in MainView::Show() at src/main.cpp:11
      (inlined by) setup() at src/main.cpp:19
  #2  0x400d390e:0x3ffc53a0 in loopTask(void*) at C:/Users/001/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42   

thank you all

-edit-
:smile:
After reading DrDiettrich's answer, I looked at the OLED sample program again. After comparing it, I found that the 「begin」step was missing. After adding it, the program ran successfully.

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

class MainView
{
private:
    Adafruit_SSD1306 myDisplay;

public:
    MainView() : myDisplay(128, 64, &Wire, -1){};
    void Begin() { myDisplay.begin(SSD1306_SWITCHCAPVCC, 0x3C); }; 
    void Show() { myDisplay.display(); };
};

MainView mainView;

void setup()
{
    Serial.begin(115200);
    mainView.Begin(); // Just missing this step,now program ran successfully.
    mainView.Show();
}
void loop() {}

Put that initialization out of the class into the setup() of an otherwise empty sketch.
Put a Serial.begin(115200) and Serial.println("Starting...)" before and Serial.println("Done"); after that call. If the second message is not sent then the display library is not usable with and ESP32. That was at least my problem with a similar Adafruit (SH1106) OLED library.

:blush:Thank you DrDiettrich.
With your reminder, I compared the OLED sample program again and found that it was missing
「begin」steps, now the program executes successfully.

Is it just an academic exercise of building class based codes or are there really advantages?

I tried to use arduino to practice OOP, and I have learned C#-related MVP and MVC architecture before, so I wanted to try to see if I can use it on arduino.

As for the advantages, I think if Arduino uses the UI part, then using the architecture will make the program easier to read and design. :slightly_smiling_face:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.