cannot use OLED and instrument to ptint data simultaneously

I am using a spectrometer and OLED 0.06' OLED with digital pins only. Analog pins cannot be used. Now when i try to printData() the oled display goes. Commenting the printData() gives the display back. Please help. I need both data on serial monitor and the display

#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 SSD1306 display connected using software SPI (default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
  OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
  

#define SPEC_TRG         A0
#define SPEC_ST          A1
#define SPEC_CLK         A2
#define SPEC_VIDEO       A3
#define WHITE_LED        A4
#define LASER_404        A5



#define SPEC_CHANNELS    288 // New Spec Channel
uint16_t data[SPEC_CHANNELS];

void setup(){

  display.begin(SSD1306_SWITCHCAPVCC);
  
  display.clearDisplay();
   display.setTextColor(WHITE);
   display.setTextSize(2);
   display.setCursor(30,30);
   display.print("S K P");
   display.display();
    delay(1);

  //Set desired pins to OUTPUT
  pinMode(SPEC_CLK, OUTPUT);
  pinMode(SPEC_ST, OUTPUT);
  pinMode(LASER_404, OUTPUT);
  pinMode(WHITE_LED, OUTPUT);
  pinMode(12, OUTPUT);

  digitalWrite(SPEC_CLK, HIGH); // Set SPEC_CLK High
  digitalWrite(SPEC_ST, LOW); // Set SPEC_ST Low



  Serial.begin(115200); // Baud Rate set to 115200
  digitalWrite(12, HIGH);
//  digitalWrite(WHITE_LED, HIGH);
//  delay(1000);
//  digitalWrite(WHITE_LED, LOW);
//  delay(1000);
//  digitalWrite(LASER_404, HIGH);
//  delay(1000);
//  digitalWrite(LASER_404, LOW);
//  delay(1000);

//display.begin(SSD1306_SWITCHCAPVCC);
//  
//  display.clearDisplay();
//   display.setTextColor(WHITE);
//   display.setTextSize(2);
//   display.setCursor(30,30);
//   display.print("S K P");
//   display.display();
//    delay(1);
  
  
}

/*
 * This functions reads spectrometer data from SPEC_VIDEO
 * Look at the Timing Chart in the Datasheet for more info
 */
void readSpectrometer(){

  int delayTime = 1; // delay time

  // Start clock cycle and set start pulse to signal start
  digitalWrite(SPEC_CLK, LOW);
  delayMicroseconds(delayTime);
  digitalWrite(SPEC_CLK, HIGH);
  delayMicroseconds(delayTime);
  digitalWrite(SPEC_CLK, LOW);
  digitalWrite(SPEC_ST, HIGH);
  delayMicroseconds(delayTime);

  //Sample for a period of time
  for(int i = 0; i < 15000; i++){

      digitalWrite(SPEC_CLK, HIGH);
      delayMicroseconds(delayTime);
      digitalWrite(SPEC_CLK, LOW);
      delayMicroseconds(delayTime); 
 
  }

  //Set SPEC_ST to low
  digitalWrite(SPEC_ST, LOW);

  //Sample for a period of time
  for(int i = 0; i < 85; i++){

      digitalWrite(SPEC_CLK, HIGH);
      delayMicroseconds(delayTime);
      digitalWrite(SPEC_CLK, LOW);
      delayMicroseconds(delayTime); 
      
  }

  //One more clock pulse before the actual read
  digitalWrite(SPEC_CLK, HIGH);
  delayMicroseconds(delayTime);
  digitalWrite(SPEC_CLK, LOW);
  delayMicroseconds(delayTime);

  //Read from SPEC_VIDEO
  for(int i = 0; i < SPEC_CHANNELS; i++){

      data[i] = analogRead(SPEC_VIDEO);

      digitalWrite(SPEC_CLK, HIGH);
      delayMicroseconds(delayTime);
      digitalWrite(SPEC_CLK, LOW);
      delayMicroseconds(delayTime);
        
  }

  //Set SPEC_ST to high
  //digitalWrite(SPEC_ST, HIGH);

  //Sample for a small amount of time
  for(int i = 0; i < 7; i++){
    
      digitalWrite(SPEC_CLK, HIGH);
      delayMicroseconds(delayTime);
      digitalWrite(SPEC_CLK, LOW);
      delayMicroseconds(delayTime);
    
  }

  digitalWrite(SPEC_CLK, HIGH);
  delayMicroseconds(delayTime);
}
  

/*
 * The function below prints out data to the terminal or 
 * processing plot
 */
void printData(){
  
  for (int i = 0; i < SPEC_CHANNELS; i++){
    
    Serial.print(data[i]);
    Serial.print(',');
    
  }
  
  Serial.print("\n");
}

void loop(){
      
  readSpectrometer();
  printData();
  delay(500);  
   
}

Why do you have "#include <Wire.h>" in this sketch?

I built the sketch for a Uno:

Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.9\hardware\arduino\avr\libraries\SPI 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.9\hardware\arduino\avr\libraries\Wire 
Using library Adafruit_GFX_Library at version 1.5.6 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Adafruit_SSD1306 at version 1.3.0 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_SSD1306 
"C:\\Program Files (x86)\\Arduino-1.8.9\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_429179/soumendras_oled.ino.elf"
Sketch uses 14104 bytes (43%) of program storage space. Maximum is 32256 bytes.
Global variables use 1096 bytes (53%) of dynamic memory, leaving 952 bytes for local variables. Maximum is 2048 bytes.

As you can see, there is only 952 bytes for variables. Adafruit in their wisdom allocate a 1024 byte buffer at runtime. The allocation should fail. The program will crash.

You should be ok with an Arduino with more SRAM e.g. Mega2560, Due, ...

Regarding Wire.h and SPI.h
This is common in SSD1306 examples. You only need to change the constructor statement if you want I2C or SPI display.
It does no harm. The Linker will remove the unused code.

David.

If you just need to display text on the OLED, then you can use my library (ss_oled); it's in the Arduino library manager and on AVRs (Like the UNO / ATmega328), it defaults to not using 1K of RAM for the backing buffer.