Dataloggingshield

Hey Leute, ich habe Probleme mit dem loggen der Messdaten auf eine SD-Karte. Im Seriellen Monitor gibt er mir die korrekten Werte für die Fotodiode(analogpin 0) und den Temperatursensor(digitalpin 9) aus. Jedoch werden auf der SD-Karte lediglich die Analogwerte der Fotodiode geloggt, bei den Messwerten für den Temperatursensor loggt er immer 0. Weiß jemand, warum mir im Seriellen Monitor alle Werte korrekt angezeigt werden, jedoch nur die Analogwerte der Fotodiode auf der Speicherkarte geloggt werden und die digitalen Temperaturwerte nicht!? wäre echt nett wenn mir da jemand helfen könnte! Ich glaube es ist irgendeine Kleinigkeit, aber ich komm iwie nicht drauf. Vielen Dank schonmal.

P.S: Sry dass ich den kompletten Code poste, aber ich habe die eingefügten Zeilen des Temperatursketches auskommentiert, ich hoffe jemand nimmt sich kurz Zeit.Danke!

#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

//Eingefügt aus TempSketch


#include <OneWire.h>
#include <DallasTemperature.h>

//Eingefügt von MotorSketch

// defines pins numbers
const int stepPin = 7; 
const int dirPin = 6;


//Ende eingefügt aus MotorSketch


// Data wire is plugged into pin 9 on the Arduino
#define ONE_WIRE_BUS 9

// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Ende eingefügt TempSketch

// A simple data logger for the Arduino analog pins

// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL  1000 // mills between entries (reduce to take more/faster data)

// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to 
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3

// The analog pins that connect to the sensors
#define photocellPin 0           // analog 0
#define tempPin 1                // analog 1
#define BANDGAPREF 14            // special indicator that we want to measure the bandgap


RTC_DS1307 RTC; // define the Real Time Clock object

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();



//Eingefügt aus MotorSketch

 // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);


//Ende Eingefügt aus MotorSketch



//eingefügt aus TempSketch

 // Start up the library
 sensors.begin();


// Ende eingefügt TempSketch

  
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
  
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  

  logfile.println("millis,stamp,datetime,light,temp");    
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,light,temp");
#endif //ECHO_TO_SERIAL
 
  // If you want to set the aref to something other than 5v
  // falls Aref benötigt wird --> analogReference(EXTERNAL);
}

void loop(void)
{




  //Eingefügt aus MotorSketch

 digitalWrite(stepPin, HIGH);
 delay(500);
  
 digitalWrite(stepPin, LOW);
 delay(500);
 



  //Ende iengefügt aus MotorSketch

  DateTime now;

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  digitalWrite(greenLEDpin, HIGH);
  
  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif

  // fetch the time
  now = RTC.now();
  // log time
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL




//Eingefügt aus TempSketch


 // call sensors.requestTemperatures() to issue a global temperature
 // request to all devices on the bus
 sensors.requestTemperatures(); // Send the command to get temperatures


   // Ende eingefügt aus TempSketch



   
  analogRead(photocellPin);
  delay(10); 
  int photocellReading = analogRead(photocellPin);  


  //Eingefügt TempSketch
  float temperatur = sensors.getTempCByIndex(0);  
  
  //Ende Eingefügt TempSketch
  
  logfile.print(", ");    
  logfile.print(photocellReading);
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(photocellReading);
  Serial.print(", ");    
  Serial.print(temperatur);
#endif //ECHO_TO_SERIAL

  // Log the estimated 'VCC' voltage by measuring the internal 1.1v ref
  analogRead(BANDGAPREF); 
  delay(10);
  int refReading = analogRead(BANDGAPREF); 

  
  logfile.print(", ");
#if ECHO_TO_SERIAL
  Serial.print(", ");   
#endif // ECHO_TO_SERIAL

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  digitalWrite(greenLEDpin, LOW);

  // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(redLEDpin, HIGH);
  logfile.flush();
  digitalWrite(redLEDpin, LOW);
  
}

Gelöst!!! Danke trotzdem!   logfile.print(temperatur);  hatte gefehlt, warum auch immer, vielen Dank trotzdem! MfG