Hello, I am doing a project that I need to save all the data collected in the BMP180 to the SDcard, this is a project already done by someone else and I am only following his instructions, I verified that the SDcard and the BMP180 are working fine but for some reason it is not saving the data on the card, could you please help me guys?
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include "Wire.h" // imports the wire library for talking over I2C
#include "Adafruit_BMP085.h" // import the Pressure Sensor Library We are using Version one of Adafruit API for this sensor
Adafruit_BMP085 mySensor; // create sensor object called mySensor
float tempC; // Variable for holding temp in C
float tempF; // Variable for holding temp in F
float pressure; //Variable for holding pressure reading
int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to
void setup(){
Serial.begin(9600); //turn on serial monitor
mySensor.begin(); //initialize pressure sensor mySensor
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader
}
void loop() {
tempC = mySensor.readTemperature(); // Read Temperature from BMP180
tempF = tempC*1.8 + 32.; // Convert degrees C to F
pressure=mySensor.readPressure(); //Read Pressure
mySensorData = SD.open("PTData.txt", FILE_WRITE);
if (mySensorData) {
Serial.print("The Temp is: "); //Print Your results
Serial.print(tempF);
Serial.println(" degrees F");
Serial.print("The Pressure is: ");
Serial.print(pressure);
Serial.println(" Pa.");
Serial.println("");
delay(250); //Pause between readings.
mySensorData.print(tempF); //write temperature data to card
mySensorData.print(","); //write a commma
mySensorData.println(pressure); //write pressure and end the line (println)
mySensorData.close(); //close the file
}
}
Thank you for the attention.
PS: The project is in this link: Arduino LESSON 21: Log Sensor Data to an SD Card | Technology Tutorials
Here are the pictures of how I installed that and the window without any information that should be showing. One alteration I did shows the information on the window but do not save the data on the SDcard. Here it is the code:
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include "Wire.h" // imports the wire library for talking over I2C
#include "Adafruit_BMP085.h" // import the Pressure Sensor Library We are using Version one of Adafruit API for this sensor
Adafruit_BMP085 mySensor; // create sensor object called mySensor
float tempC; // Variable for holding temp in C
float tempF; // Variable for holding temp in F
float pressure; //Variable for holding pressure reading
int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to
void setup(){
Serial.begin(9600); //turn on serial monitor
mySensor.begin(); //initialize pressure sensor mySensor
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader
}
void loop() {
Serial.println("made the loop");
tempC = mySensor.readTemperature(); // Read Temperature from BMP180
tempF = tempC*1.8 + 32.; // Convert degrees C to F
pressure=mySensor.readPressure(); //Read Pressure
mySensorData = SD.open("PTData.txt", FILE_WRITE);
Serial.println(mySensorData);
//if (mySensorData) {
Serial.print("The Temp is: "); //Print Your results
Serial.print(tempF);
Serial.println(" degrees F");
Serial.print("The Pressure is: ");
Serial.print(pressure);
Serial.println(" Pa.");
Serial.println("");
delay(250); //Pause between readings.
mySensorData.print(tempF); //write temperature data to card
mySensorData.print(","); //write a commma
mySensorData.println(pressure); //write pressure and end the line (println)
mySensorData.close(); //close the file
//}
}
PS: the window that appears data is the one running this code.
Perhaps the SD card is not compatible. Do you have an older SD card of about 1G...4Gbyte ?
Try formatting the SD card as written here : Don't Format SD cards with OS utilities! - Storage - Arduino Forum
I prefer to remove the "delay(250)" and add a delay at the end of loop().
You could try to create a test file, for example in setup().
How is the SD card connected ? Which SD module do you use ?
What happens when you try this example : http://www.arduino.cc/en/Tutorial/Files