Displaying Serial Monitor Data On OLED

I have a project that will measure height above ground level and add 1 to a file when a preset threshold it exceeded using a Nano, BMP280, and an SD card. I have that portion of the sketch working and would like to display the info that I see on the serial monitor on an OLED (128x64). I did a test sketch on the monitor and it works but can't figure out how to get the serial monitor data to display. Any guidance would be greatly appreciated.

Welcome to the forum!
In general, you'll replace every serial.print() with an equivalent function call to print to the OLED. You'll need to manage location on screen as well, it's much more manipulable than Serial Monitor.

But, please show us your code, indicate which OLED you have, what OLED library you're using, which SD and SD library, and what Arduino you're using(there are several Nano products, we can no longer safely assume you're using the old classic Nano, even though there are so many out there).
Is the OLED connected via SPI or I2C?

BTW, you must have missed

or most of this would have been answered in your first post.

You simply print to the screen the same info you send to the serial port.

An imaginary example

Serial.print(level);
Display.drawText(0,0,level);

You will need a library to run your OLED. The examples included therein will have all you need to know. If you just need the same text as you see on your serial monitor, click here for a post that may be of interest.

Thanks, camsysca. I'm new to the forum and my brain is fried from working on this project all evening. :zany_face:

I'm using a Nano V3, BMP280 pressure sensor, ADA254 SD card reader, and 64X32 OLED display using SD1306 library. I've been able to get the arduino to add 1 to a file after a unit has elevated above the trigger altitude and also have gotten the display to work correctly with a separate sketch, but not in my current sketch (see below for sketch without the display.) My primary means of learning so far has been researching it on the web and looking at other sketches to figure things out but I'm stuck. Right now the sketch writes "1" to a file every time the trigger altitude is reached. Ideally, I'd like to:

  1. Have the sketch ready the file and add 1 to the existing number. For example, if it's exceeded the altitude 5 times, have it recall the 5 and add 1 to it and store it as 6 etc.
  2. On the display, I'd like to display the pressure altitude at startup, current elevation, and number of cycles above the trigger altitude as read from the SD card.

Here is the sketch I currently have without the display:

 #include <Wire.h>
 #include <Adafruit_BMP280.h>
 #include <SD.h>
 #include <Adafruit_SSD1306.h>
 #include  <Adafruit_GFX.h>      //Libraries for the OLED and BMP280

 #define BMP280_ADDRESS 0x76 // BMP280 I2C address, usually 0x76 or 0x77
 Adafruit_BMP280 bmp; // I2C
 #define SD_CS 4   // Chip Select pin for the SD card module

 
    float groundAltitude = 0;
    float altitudeThreshold =   50.0; // Altitude rise in meters to trigger increment
    bool groundAltitudeSet = false;
    const char* filename = "count.txt"; // File to store the count

    void setup() {
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }

      Serial.println(F("BMP280 Test"));

     if (!bmp.begin(BMP280_ADDRESS)) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

      // Configure BMP280 settings (optional, but good for stability)
      bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     // Operating Mode
                      Adafruit_BMP280::SAMPLING_X2,     // Temp. oversampling
                      Adafruit_BMP280::SAMPLING_X16,    // Pressure oversampling
                      Adafruit_BMP280::FILTER_X16,      // Filtering
                      Adafruit_BMP280::STANDBY_MS_500); // Standby time

      Serial.print("Initializing SD card...");
      if (!SD.begin(SD_CS)) {
        Serial.println("Card failed, or not present");
        while (1);
      }
      Serial.println("Card initialized.");

      // Read initial count from file or create if not exists
      int currentCount = 0;
      File dataFile = SD.open(filename, FILE_READ);
      if (dataFile) {
        String line = dataFile.readStringUntil('\n');
        currentCount = line.toInt();
        dataFile.close();
        Serial.print("Initial count from file: ");
        Serial.println(currentCount);
      } else {
        Serial.println("count.txt not found, creating new file.");
        File newFile = SD.open(filename, FILE_WRITE);
        if (newFile) {
          newFile.println(0);
          newFile.close();
        } else {
          Serial.println("Error creating file!");
        }
      }
    }

    void loop() {
      if (!groundAltitudeSet) {
        groundAltitude = bmp.readAltitude(1013.25); // Set ground altitude (adjust sea level pressure if needed)
        groundAltitudeSet = true;
        Serial.print("Ground altitude set to: ");
        Serial.print(groundAltitude);
        Serial.println(" meters.");
        delay(2000); // Give some time for stabilization
      }

      float currentAltitude = bmp.readAltitude(1013.25); // Read current altitude
      float altitudeChange = currentAltitude - groundAltitude;

      Serial.print("Current Altitude: ");
      Serial.print(currentAltitude);
      Serial.print("m, Change: ");
      Serial.print(altitudeChange);
      Serial.println("m");

      if (altitudeChange >= altitudeThreshold) {
        Serial.println("Altitude threshold reached! Incrementing count.");

        // Read current count
        File dataFile = SD.open(filename, FILE_READ);
        int currentCount = 0;
        if (dataFile) {
          String line = dataFile.readStringUntil('\n');
          currentCount = line.toInt();
          dataFile.close();
        }

        // Increment and write back
        currentCount++;
        File newFile = SD.open(filename, FILE_WRITE); // Open in write mode to overwrite
        if (newFile) {
          newFile.println(currentCount);
          newFile.close();
          Serial.print("New count: ");
          Serial.println(currentCount);
        } else {
          Serial.println("Error writing to file!");
        }

        // Reset ground altitude to prevent continuous increments
        groundAltitude = currentAltitude;
      }

      delay(1000); // Read every second
    }

Here is a simulation that you can practice with... rather than the command Serial.print();, use display.print(); (for this simulation). Read about OLED on the internet.