Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adafruit_SS1306.begin hangs #280

Open
sloopjohnt opened this issue Dec 23, 2024 · 1 comment
Open

Adafruit_SS1306.begin hangs #280

sloopjohnt opened this issue Dec 23, 2024 · 1 comment

Comments

@sloopjohnt
Copy link

sloopjohnt commented Dec 23, 2024

  • Arduino board: Nano Every

  • Arduino IDE version 2.3.4

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

The following code appears to hang in Adafruit_SSD1306.begin rather than returns False if the screen is not present, or at least not powered. This is inconvenient, can't it be fixed with e.g. a timeout?

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for half a second
digitalWrite(LED_BUILTIN, LOW);
Serial.begin(9600);
while (!Serial) {
static long int time_out_time = millis() + 1000;
if ( millis() > time_out_time) break;
}; // wait for Serial set up to complete
Serial.println("\nFirst OLED SSD1306 Screen Test V0.1 Starting");
Serial.println("\nSetting up display");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for half a second
digitalWrite(LED_BUILTIN, LOW);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("Screen Set up failed");
for(;;); // Don't proceed, loop forever
}
Serial.println("SCreen Set up succeeded");
display.clearDisplay();
display.display();
Serial.println("Display Cleared");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.setCursor(0, 0);
Serial.println("About to Write");
int characters = display.write('X');
Serial.print("Wrote ");
Serial.println(characters);
display.display();
delay(1000);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}

// the loop function runs over and over again forever
void loop() {
}

@sloopjohnt
Copy link
Author

Sorry, please disregard this. I've tried it again on another set up and it does not hang. I'm investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant