ciao a tutti,
sto facendo delle prove con la shield in oggetto, visibile a questo link.
è impilata su un arduino UNO, con una SD da 1 GB inserita. lo sketch CardInfo funziona e mi rileva la SD correttamente.
ho regolato l'ora del RTC, con lo skethc fornito al link e funziona anche quello.
ho però dei problemi di scrittura. precisamente, ho caricato lo script seguente (che ho preso sempre dal link, ma ho semplificato, in modo da scrivere ogni 2 secondi, anzichè al rilevamento del movimento, come prevedeva lo script, per non attaccare alcun sensore e fare il tutto più velocemente):
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
// 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
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
while (1);
}
void setup(void)
{
Serial.begin(9600);
Serial.println();
// use debugging LEDs
#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.txt";
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,status");
#if ECHO_TO_SERIAL
Serial.println("millis,stamp,datetime,status");
#endif //ECHO_TO_SERIAL
}
void loop(void)
{
delay(2000);
logData();
}
void logData() {
DateTime now;
// 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
now = RTC.now();
// log time
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.println(now.second(), DEC);
#if ECHO_TO_SERIAL
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.println(now.second(), DEC);
#endif //ECHO_TO_SERIAL
}
sul terminale vedo correttamente i millisecondi e la data, ogni 2 secondi, ma sulla SD non scrive nulla.
o, meglio, scrive il file, che però rimane vuoto!
dove sto sbagliando?
grazie!