Maxbotix ultrasonic data log on SD

Need some help with the data logging code so let me describe:

Project description:
Need to take Water Level measurements in a pipe every 1s (a variable that I could change) and log the readings on a SD card with a RTC time stamp for later data processing.

BOM:
Arduino: - Adafruit METRO 328
Datalog shield: - Adafruit Assembled Data Logging shield
LCD Display shield: - LCD Shield Kit w/ 16x2 Character Display
Maxbotix ultrasonic: - MB1030 Ultrasonic Range Finder - LV-MaxSonar-EZ3

What I did:
Tested the sensor on Arduino - all OK, it reads correctly (PW mode)
Added the LCD shield - all OK, I have data displayed correctly
Added the DATA LOG shield - ERROR, the file cant be opened to write

Not sure how to implement the RTC time stamp at every SD log recording entry?

What I tested:
Uploaded the SD card Example to read write and it works

What is wrong:
Something in my code is definitely wrong.

ANY HELP OR HINT IS GREATLY Appreciated!

CODE:

/*
Test code for the Arduino Uno
Written by Tom Bonar for testing
Sensors being used for this code are the MB10X0 from MaxBotix
All PW inputs are coded in this for simplicity.
Remove the comments to use the additional sensor inputs
*/

// include the library code:
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>

File dataFile;

// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;
const int pwPin1 = 7;
long pulse1, sensor1;

void setup () {
  Serial.begin(9600);
  pinMode(pwPin1, INPUT);

//SDcard
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

    if (SD.exists("datalog.txt")) {
    Serial.println("datalog.txt exists.");
  } else {
    Serial.println("datalog.txt doesn't exist.");
  }

}

//SDcard

  lcd.begin(16, 2);       // set up the LCD number of rows and columns: 
  lcd.setBacklight(HIGH); // Set backlight on (HIGH on, LOW off)

}

void read_sensor(){
  pulse1 = pulseIn(pwPin1, HIGH);
 sensor1 = pulse1/58; //147 for inches
}

//This section of code is if you want to print the range readings to your computer too remove this from the code put /* before the code section and */ after the code
void printall(){         
  Serial.print("S1");
  Serial.print(" ");
  Serial.print(sensor1);
  Serial.println(" ");
}

void loop () {
//SDcard
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  {
   // int sensor = pulse1;
    dataString += String(sensor1);
//    if (analogPin < 2) {
      dataString += ",";
    }
 // }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
    dataFile.close();
  }

//SDcard

  read_sensor();
  printall();
  delay(5000); // This delay time changes by 50 for every sensor in the chain.  For 5 sensors this will be 250

  lcd.setCursor(0, 0);                // write data to LCD display via I2C backpack
  lcd.print("Range: ");               // write to LCD
  lcd.setCursor(7,0); 
  lcd.print("    ");
  lcd.setCursor(7,0);
  lcd.print(pulse1);
  lcd.setCursor(11,0);
  lcd.print("   mm");

}

Something in my code is definitely wrong.

Post the error messages, and other evidence you have.

Here is the console message I get:

error opening datalog.txt
S1 7 
error opening datalog.txt
S1 8 
error opening datalog.txt
S1 7 
error opening datalog.txt
S1 7 
14:31:06.853 -> error opening datalog.txt
14:31:06.947 -> S1 7 
14:31:12.080 -> error opening datalog.txt
14:31:12.127 -> S1 7 
14:31:17.268 -> error opening datalog.txt
14:31:17.337 -> S1 7 
14:31:22.478 -> error opening datalog.txt
14:31:22.525 -> S1 35

the SDcard has nothing on it when I insert in a PC to check