Error whilst writing and manipulating to the File

So i wanted to make a program that would suite my amateur rocket as a part of the avionics package which had called for a BMP180 shield which would read the temperature,pressure and sea level pressure to compute the altitude.These values would then be stored in an SD Card through the help of the SD Card Module(MicroSD Adapter) so that i could later procure these values to log them onto an excel sheet.The only issue i have is that the File is unable to open and write even though the SD Card initialization is Successful..and if it does open successfully it would only write to the file for a particular amount of times beyond which it would then result in an error .Added to that,the file itself will have no content even though the file would have been initially opened..bit confusing , i know.I have attatched the code below.
Thanking the Community in Advance,
Vibe :slight_smile:

Sample_bmp.ino (1.93 KB)

The OP's code. Auto formatted in the IDE and posted here in code tags

#include <Wire.h>
#include<SD.h>
#include<SPI.h>
#include <Adafruit_BMP085.h>
#define seaLevelPressure_hPa 1013.25//The average pressure at mean sea-level (MSL) in the International Standard Atmosphere (ISA) is 1013.25 hPa
int pinCS = 10;
File myFile;

Adafruit_BMP085 bmp;
float h, p0, p, t;
void setup()
{
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
  if (!bmp.begin())
  {
    Serial.println("Could not find a valid BMP180 sensor, check wiring!");
    while (1) {}
  } if (SD.begin())
  {
    Serial.println(F("SD Card Ready for use"));
  }
  else
  {
    Serial.println(F("SD Card initialization failed "));
    return;
  }
  myFile = SD.open("t1.txt", FILE_WRITE);
  myFile.close();
  Serial.println("File created");
}

void altitudem(float P0, float P, float T)
{
  h = ((pow((P0 / P), (1 / 5.257)) - 1) * (T + 273.15)) / 0.0065;
}

void loop()
{
  Serial.print("Temperature = ");
  t = bmp.readTemperature();
  Serial.print(t);
  Serial.println(" *C");
  Serial.print("Pressure = ");
  p = bmp.readPressure();
  Serial.print(p);
  Serial.println(" Pa");
  Serial.print("Altitude = ");
  Serial.print(bmp.readAltitude());
  Serial.println(" meters");
  Serial.print("Pressure at sealevel (calculated) = ");
  p0 = bmp.readSealevelPressure();
  Serial.print(p0);
  Serial.println(" Pa");
  Serial.print("Real altitude = ");
  altitudem(p0, p, t);
  Serial.print(h);
  Serial.println(" meters,height above sea level");//Formula
  myFile = SD.open("t1.txt", FILE_WRITE);
  if (myFile)
  {
    Serial.println("File can be written too!");
    myFile.print(t);
    myFile.println(" *C");
    myFile.print(p);
    myFile.println(" Pa");
    myFile.print(p0);
    myFile.println(" Pa,Sea level");
    myFile.print(h);
    myFile.println(" Metres");
  }
  else
  {
    Serial.println("Eroor - File cannot be written to ");
  }
  delay(200);
}

he only issue i have is that the File is unable to open and write even though the SD Card initialization is Successful..
and if it does open successfully it would only write to the file for a particular amount of times beyond which it would then result in an error .

Added to that,the file itself will have no content even though the file would have been initially opened.
yes indedd your post is very confusing me.

can you write data to the file yes or no?

if yes can you write data a particular amount of times ? yes or no?

if yes how can it be that the file has no content ?

A suggest you add serial output to your code that logs to the serial monitor what commands your code is doing
let it run
and then copy & paste the code into a first code-section
and the serial-output into a second code-section.

best regards Stefan