• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Logowanie danych
#1
Witajcie,

Czy macie jakiś pomysł w jaki sposób rozwiązać logowanie odczytów z czujników aby każdego dnia zmieniała się nazwa pliku na bieżącą datę?
Chcę aby plik z dnia x był zamykany o 23.59 i tworzony nowy o nazwie pliku jako data y.

Pozdrawiam,
Piotr
 
Odpowiedź
#2
Witaj,
Prześlij proszę nam swój kod, będzie łatwiej Ci pomóc. Smile
Pozdrawiam
[Obrazek: Sygnatura1-w60.jpg]
 
Odpowiedź
#3
Kod:
#include <SPI.h>
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DS1302.h>
DS1302 rtc(8, 9, 10);
char file;
char currDate;

File myFile;

#define ONE_WIRE_BUS 5  //wyjscie dla DS18B20


   

   OneWire oneWire(ONE_WIRE_BUS);
   DallasTemperature sensors(&oneWire);

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }
rtc.halt(false);
     rtc.writeProtect(false);

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

 if (!SD.begin(4)) {
   Serial.println("initialization failed!");
   return;
 }
 Serial.println("initialization done.");

 // open the file. note that only one file can be open at a time,
 // so you have to close this one before opening another.
 sensors.requestTemperatures(); // Send the command to get temperature readings
    // Serial.print("Temperatura za zdjęciami: ");
    // Serial.print(sensors.getTempCByIndex(0));
    // Serial.println(" *C ");
     myFile = SD.open("test5.csv", FILE_WRITE);
      // if the file opened okay, write to it:
     
 if (myFile) {
   for(int i=0; i <= 15; i++){
    //Serial.print("Temperatura: ");
   
    myFile.print(rtc.getDateStr());
    myFile.print("  ");
    myFile.print(rtc.getTimeStr());
    myFile.print(" ");
   myFile.println(sensors.getTempCByIndex(0));
   delay(4000);
   }
   // close the file:
   myFile.close();
   Serial.println("done.");
   
 }
    else {
   // if the file didn't open, print an error:
   Serial.println("error opening test.txt");
 }
   
 myFile = SD.open("test5.csv");
 if (myFile) {
   while (myFile.available()) {
     Serial.write(myFile.read());
   }
   // close the file:
   myFile.close();
 } else {
   // if the file didn't open, print an error:
   Serial.println("error opening test.txt");
 }
 
   
 
}
int temp;
void loop() {
 // nothing happens after setup
 
 }
 
To jest jeszcze w pętli setup bo właśnie nie wiem jak zatrzymać się w loop Sad

Pozdrawiam,
Piotr

EDIT:
Pomyślałem trochę nad tym i wymyśliłem taką prowizorkę:
Kod:
#include <SPI.h>
#include <SD.h>
#include <OneWire.h> 
#include <DallasTemperature.h>
#include <DS1302.h> 
DS1302 rtc(8, 9, 10);
char date;
char currDate;

File myFile;

 #define ONE_WIRE_BUS 5  //wyjscie dla DS18B20


     
 
    OneWire oneWire(ONE_WIRE_BUS); 
    DallasTemperature sensors(&oneWire);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
    rtc.halt(false);
    rtc.writeProtect(false);
    Serial.print("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");
    
     // Serial.print("Temperatura za zdjęciami: ");
     // Serial.print(sensors.getTempCByIndex(0)); 
     // Serial.println(" *C ");
    
  
}
int temp;
void loop() {
    
    date=rtc.getDateStr();
    date=date+".csv";
    
    sensors.requestTemperatures(); // Send the command to get temperature readings 
    myFile = SD.open(&date, FILE_WRITE);
              
    if (myFile) {
    
     //Serial.print("Temperatura: ");
     
     myFile.print(rtc.getDateStr());
     myFile.print("  ");
     myFile.print(rtc.getTimeStr());
     myFile.print(" ");
     myFile.println(sensors.getTempCByIndex(0));
    
    
    // close the file:
    myFile.close();
    Serial.println("done.");
    
  }
     else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
    
  myFile = SD.open(date);
  if (myFile) {
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.print("error opening ");
    Serial.println(date);
  }
  delay(4000);
  currDate=rtc.getDateStr();
  currDate=currDate+".csv";
  if(currDate!=date)
  
      date=currDate;
    
  
  }
  
     
Tylko teraz nie mogę stworzyć pliku o takiej nazwie. Czy macie na to jakiś pomysł?
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości