Hi , everyone
When I create an OLED object, the program seems to be crushing . I am not sure if there is something wrong with the way I create the object. Could you please help me check it out?
[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-
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() {}