adafruit / Adafruit_SH110x

Arduino library for SH110x based monochrome OLEDs
Other
67 stars 30 forks source link

Adafruit_SH1106G not working on SPI #10

Closed gps79 closed 2 years ago

gps79 commented 2 years ago

Expected result: Software runs without errors.

Actual result: Software crashes.

Root cause:

ladyada commented 2 years ago

are you using adafruit hardware? if so please post a photo!

gps79 commented 2 years ago

I don't use adafruit hardware. I just pointed an error (i2c_dev is a null pointer and causes crash). The fix for that is to move line: uint16_t maxbuff = i2c_dev->maxBufferSize() - 1; below line: if (i2c_dev) { // I2C

so it's executed only when i2c_dev structure is initialized. Then the SW doesn't crash.

caternuson commented 2 years ago

What code are you running? Is it calling begin() on the display instance?

EDIT - oh, this is for SPI usage. OK, seeing it now. For the SPI case, i2c_dev never gets init'd: https://github.com/adafruit/Adafruit-GFX-Library/blob/4a33fcd467e373d1eedd3aef6f5f9be36f5c276b/Adafruit_GrayOLED.cpp#L242-L252 so the call to display() will try to access a null pointer here: https://github.com/adafruit/Adafruit_SH110x/blob/2f7d9fbdc6596d449d303bd7d8b44399012a27de/Adafruit_SH110X.cpp#L170

caternuson commented 2 years ago

@gps79 If you can, please test the changes in PR #11.

gps79 commented 2 years ago

It's working fine with your fix. No more crashes. Thank you.