Need to detect OLED connected - otherwise program locks
Hello, is there a way to detect if the OLED is connected before sending the oled.begin? I have an application where I want to connect the OLED just for monitoring and troubleshooting, otherwise the OLED is removed. However, when I remove the OLED the program locks up during the oled.begin(xxxxxxx) statement if the oled isn't present.
I'm used to the adafruit library where you can use this code:
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 Serial.println(F("SSD1306 allocation failed")); for(;;); }
Is there anything similar in Tiny4kOLED or some method I can detect if the OLED is connected within my program?
If you define TINY4KOLED_QUICK_BEGIN then the check that the screen is available, is skipped. See https://github.com/datacute/Tiny4kOLED/blob/master/src/Tiny4kOLED_Wire.h#L50
You can then call Wire.beginTransmission and Wire.endTransmission, checking the result.