Hello guys, I was working on a project which involves writing the pressure and temperature onto an sd card. I use an sd card shield. When running the code on my Arduino Uno it only writes 1 measurement. I was wondering if any of you could help me. (It does work on the serial monitor)
Code:
#include <Wire.h>
#include <SFE_BMP180.h>
#include <SPI.h>
#include <SD.h>
SFE_BMP180 bmp180;
File logData;
int buttonPin = 3;
int ledPin = 13;
bool logStatus = false;
void setup() {
Serial.begin(9600);
bool success = bmp180.begin();
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
if (success) {
Serial.println("BMP180 init success");
} else {
Serial.println("Sensor not initialized!!");
}
//SD Shizzle
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
logData = SD.open("log.txt", FILE_WRITE);
}
void loop() {
char status;
double T, P;
bool success = false;
if(digitalRead(buttonPin) == LOW){
if (logStatus == true){
logStatus = false;
logData.println("Jelle");
logData.close();
Serial.println("Jelle");
digitalWrite(ledPin, LOW);
} else {
logStatus = true;
digitalWrite(ledPin, HIGH);
}
}
status = bmp180.startTemperature();
if (status != 0) {
delay(1000);
status = bmp180.getTemperature(T);
if (status != 0) {
status = bmp180.startPressure(3);
if (status != 0) {
delay(status);
status = bmp180.getPressure(P, T);
if (status != 0 && logStatus == true) {
logData.print("Pressure: ");
logData.print(P);
logData.println(" hPa");
logData.print("Temperature: ");
logData.print(T);
logData.println(" C");
Serial.print("Pressure: ");
Serial.print(P);
Serial.println(" hPa");
Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" C");
}
}
}
}
}