I used i2c oled display after power not working.

Hi,

Project.
Speedo meter.
Arduino NANO clone.
Hall Sensor.
I2C Display OLED.(ssd1306_128x32_i2c)

Once upload this code working good. but when I remove the power and connect again(Switch off and back on). The display not showing anything. Then I need to again upload the code for work.

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

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

float radius_of_wheel = 0.33;  //Measure the radius of your wheel and enter it here
volatile byte rotation; // variale for interrupt fun must be volatile
float timetaken,rpm,dtime;
int v;
unsigned long prevtime;

void setup() {
 //Serial.begin(9600);

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
 attachInterrupt(0, magnet_detect, RISING); //secound pin of arduino used as interrupt and magnet_detect will be called for each interrupt
 rotation = rpm = prevtime = 0; //Initialize all variable to zero
  //display.display();
  //delay(1000);

 // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(5);
  display.setCursor(0, 0);
  display.setTextColor(WHITE);

}

void loop() {
 /* int sensor=analogRead(A0);
  display.setCursor(20, 0);
//  display.print("Value: ");
  display.println(sensor);
  display.display(); //you have to tell the display to...display
  delay(200);
  display.clearDisplay();*/



    /*To drop to zero if vehicle stopped*/
 if(millis()-dtime>500) //no magnet found for 1500ms
 {
  rpm= v = 0; // make rpm and velocity as zero
  //Serial.println(v);
  display.setCursor(20, 0);
  display.println(v);
  display.display();
  delay(100);
  display.clearDisplay();
  dtime=millis();
 }
 //Serial.println(v);
   display.setCursor(20, 0);
  display.println(v);
  display.display();
  delay(100);
  display.clearDisplay();
}
 
void magnet_detect() //Called whenever a magnet is detected
{
  rotation++;
  dtime=millis();
  if(rotation>=3)
  {
    timetaken = millis()-prevtime; //time in millisec for two rotations
    rpm=(1000/timetaken)*60;    //formulae to calculate rpm
    v = radius_of_wheel * rpm * 0.37699; //0.33 is the radius of the wheel in meter
    prevtime = millis();
    rotation=0;
    //Cycle_BT.println("Magnet detected...."); //enable while testing the hardware
  }
}

what is the problem ?.

It is working... fine... Solved...

SureshKumar2610:
It is working... fine... Solved...

I am having the same problem. How did you get it resolved?

I just ran into the same issue. I needed to add a "delay(1500) before the first call to display.begin
The supply voltage generated by the display has to swing in....