oled works on void setup, not in void loop

Hello world. I have this oled connected to a wemos D1 mini pro. It is supposed to display the readings from a flow meter. I noticed that the oled does not work when the function to read is placed in the void loop. However the display comes on when the call to read is in the void setup.

Can somone have a look at my code to see if something is off?

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#define PULSE_PIN 2  
#define LED_PIN 4    

volatile long pulseCount=0;
float calibrationFactor = 6.5;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
float totalLitres;

unsigned long oldTime;

void ICACHE_RAM_ATTR pulseCounter()
{
  pulseCount++;
}

void setup()
{
  Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0; 

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);  // We have an active-low LED attached
 
  pinMode(PULSE_PIN, INPUT);
//  pinMode(PULSE_PIN, INPUT_PULLUP);
//  digitalWrite(PULSE_PIN, HIGH);   ????
  attachInterrupt(PULSE_PIN, pulseCounter, FALLING);
    display.display();
 
}

void loop()
{
   if((millis() - oldTime) > 1000)    // Only process counters once per second
  {
    detachInterrupt(PULSE_PIN);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;     
    totalLitres = totalMilliLitres * 0.001;
    unsigned int frac;   
    Serial.print("flowrate: ");
    Serial.print(int(flowRate));  // Print the integer part of the variable
    Serial.print(".");             // Print the decimal point
    frac = (flowRate - int(flowRate)) * 10;
    Serial.print(frac, DEC) ;      // Print the fractional part of the variable
    Serial.print("L/min");
    Serial.print("  Current Liquid Flowing: ");             // Output separator
    Serial.print(flowMilliLitres);
    Serial.print("mL/Sec");
    Serial.print("  Output Liquid Quantity: ");             // Output separator
    Serial.print(totalLitres);
    Serial.println("L");
   // disp();
    //Serial.print(totalMilliLitres);
    //Serial.println("mL");

    pulseCount = 0;

    attachInterrupt(PULSE_PIN, pulseCounter, FALLING);

     
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Flowrate:");
  display.setTextSize(2);
  display.setCursor(0,10);
  display.print(flowRate);
  display.print("L/min");
  display.setTextSize(1);
  display.cp437(true);
  display.write(167);
  display.setTextSize(2);
    
  display.setTextSize(1);
  display.setCursor(0, 35);
  display.print("Liquid Quantity:");
  display.setTextSize(2);
  display.setCursor(0, 45);
  display.print(totalLitres);
  display.print("L");   
  display.display();

  }
}