Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« on: May 26, 2012, 09:37:57 am » |
Questo è il mio programma: #include "RTClib.h" #include <SD.h> #include <Wire.h> #include <SoftwareSerial.h> #include <Adafruit_Thermal.h> #include <LiquidCrystal.h> #include <SD.h>
#define LOG_INTERVAL 1000 // mills between entries #define ECHO_TO_SERIAL 1 // echo data to serial port #define WAIT_TO_START 0 // Wait for serial input in setup() #define SYNC_INTERVAL 1000 // mills between calls to flush() - to write data to the card uint32_t syncTime = 0; // time of last sync()
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); while(1); }
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int printer_RX_Pin = 8; // this is the green wire int printer_TX_Pin = 9; // this is the yellow wire Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void setup() { Serial.begin(1200); lcd.begin(20,4); printer.begin(); #if WAIT_TO_START Serial.println("Type any character to start"); while (!Serial.available()); #endif //WAIT_TO_START Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); 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); Wire.begin(); if (!RTC.begin()) { logfile.println("RTC failed"); #if ECHO_TO_SERIAL Serial.println("RTC failed"); #endif //ECHO_TO_SERIAL } logfile.println("millis,time,light,temp"); #if ECHO_TO_SERIAL Serial.println("millis,time,light,temp"); #endif// ECHO_TO_SERIAL // If you want to set the aref to something other than 5v //analogReference(EXTERNAL); }
String line = "";
void loop() { DateTime now;
// delay for the amount of time we want between readings delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL)); // 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 2000 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); #if ECHO_TO_SERIAL Serial.print(now.unixtime()); // seconds since 2000 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); #endif //ECHO_TO_SERIAL //File dataFile = SD.open("datalog.txt", FILE_WRITE); if (Serial.available()) { char inByte = Serial.read(); switch (inByte) { case '\n': lcd.setCursor(0,0); lcd.print(line); printer.println(line); // if the file is available, write to it: logfile.print(", "); logfile.print(line); #if ECHO_TO_SERIAL Serial.println(line); //print complete line #endif //ECHO_TO_SERIAL line = ""; //reset to empty string break; default: line += inByte; //append inByte to the line String } } if ((millis() - syncTime) < SYNC_INTERVAL) return; syncTime = millis(); logfile.flush(); }
L'ho implementato copiando pari pari delle parti da un programma di esempio. Stessa path dove si trovano i pde, stesse librerie usate... l'esempio compila il mio no! Mi dice 'class RTC_DS1307' has no member named 'begin'. Perchèèèèè??? Son 3 ore che ci vado dietro ma non capisco perchè!?
|
|
|
|
« Last Edit: May 26, 2012, 09:52:44 am by 9six4 »
|
Logged
|
|
|
|
|
Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« Reply #1 on: May 26, 2012, 09:38:28 am » |
Questo è l'esempio: #include <SD.h> #include <Wire.h> #include "RTClib.h"
// 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
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter! #define bandgap_voltage 1.1 // this is not super guaranteed but its not -too- off
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(); // 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,vcc"); #if ECHO_TO_SERIAL Serial.println("millis,stamp,datetime,light,temp,vcc"); #endif //ECHO_TO_SERIAL // If you want to set the aref to something other than 5v analogReference(EXTERNAL); }
void loop(void) { 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
analogRead(photocellPin); delay(10); int photocellReading = analogRead(photocellPin); analogRead(tempPin); delay(10); int tempReading = analogRead(tempPin); // converting that reading to voltage, for 3.3v arduino use 3.3, for 5.0, use 5.0 float voltage = tempReading * aref_voltage / 1024; float temperatureC = (voltage - 0.5) * 100 ; float temperatureF = (temperatureC * 9 / 5) + 32; logfile.print(", "); logfile.print(photocellReading); logfile.print(", "); logfile.print(temperatureF); #if ECHO_TO_SERIAL Serial.print(", "); Serial.print(photocellReading); Serial.print(", "); Serial.print(temperatureF); #endif //ECHO_TO_SERIAL
// Log the estimated 'VCC' voltage by measuring the internal 1.1v ref analogRead(BANDGAPREF); delay(10); int refReading = analogRead(BANDGAPREF); float supplyvoltage = (bandgap_voltage * 1024) / refReading; logfile.print(", "); logfile.print(supplyvoltage); #if ECHO_TO_SERIAL Serial.print(", "); Serial.print(supplyvoltage); #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); }
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #2 on: May 26, 2012, 09:44:30 am » |
Ciao, metti un titolo più adeguato al Topic, le frasi ad effetto servono solo a chi le scrive 
|
|
|
|
|
Logged
|
|
|
|
|
Italia, Cefalù
Offline
Sr. Member
Karma: 0
Posts: 403
|
 |
« Reply #3 on: May 26, 2012, 09:48:02 am » |
uhm, se risolvi fammi sapere!
riportava anche a me questo errore. poi, stanco, ho deciso di comunicare con il DS1307 a mano, inviando i comandi direttamente con il Wire!
|
|
|
|
|
Logged
|
|
|
|
|
Forum Moderator
Italy
Offline
Brattain Member
Karma: 219
Posts: 16447
Don't know what I do
|
 |
« Reply #4 on: May 26, 2012, 09:52:59 am » |
Intanto se l'esempio compila ed il tuo no, non l'hai copiato pari pari ma hai apportato qualche modifica  Poi vedo ad esempio che includi 2 volte la libreria SD.h. Poi con che IDE stai compilando? Hai visto se la RTCLib è compatibile con l'IDE che stai usando?
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #5 on: May 26, 2012, 09:56:42 am » |
Prova a compilare eliminando tutte le lib "extra" così si vede se non ci sia qualche conflitto; altra cosa: stai lavorando direttamente su Arduino o su un qualche chip in stand-alone?
|
|
|
|
|
Logged
|
|
|
|
|
Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« Reply #6 on: May 26, 2012, 10:03:46 am » |
Poi vedo ad esempio che includi 2 volte la libreria SD.h. Piccola svista  cancellata ma non cambia nulla... Poi con che IDE stai compilando? Hai visto se la RTCLib è compatibile con l'IDE che stai usando? Uso IDE 1.0, ho provato anche con IDE 1.0.1 ma niente da fare. La RTClib l'ho usata anche in molti altri codici, mai dato problemi. Ma ti dico, quello che proprio non capisco, a parte ovviamente come dici tu il fatto di aver modificato qualche cosine  è che se guardi, la parte iniziale, fino al comando if (!RTC.begin()) { ovvero il comando incriminato, è identica!  Prova a compilare eliminando tutte le lib "extra" Provato... niente da fare... stai lavorando direttamente su Arduino o su un qualche chip in stand-alone? Arduino UNO col suo chip originale e shield http://www.adafruit.com/products/243. Mi da problemi gia solo in verifica.
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #7 on: May 26, 2012, 10:06:30 am » |
e se togli lo shield e la relativa lib?
|
|
|
|
|
Logged
|
|
|
|
|
Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« Reply #8 on: May 26, 2012, 10:09:42 am » |
Non credo dia fastidio lo shield perchè non ho neanche collegato arduino al pc, ho solamente fatto la verifica. Togliendo le librerie e le parti relative va... ma l'esempio con relative librerie funziona però, senza nessun problema.
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #9 on: May 26, 2012, 10:14:03 am » |
Parti dall'esempio ed aggiungi un componente per volta, se arrivi a mettere tutto senza errori ti basta sostituire/modificare lo sketch
|
|
|
|
|
Logged
|
|
|
|
|
Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« Reply #10 on: May 26, 2012, 10:16:13 am » |
E' quello che sto facendo  Adesso ti dico... 
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #11 on: May 26, 2012, 10:20:30 am » |
E' quello che sto facendo  Adesso ti dico...  scusa, era solo per darti un suggerimento, non dubito che te la cavi da solo, ci mancherebbe  ma alle volte uno segue una sua idea fissa e non pensa alle cose più sceme, mentre io che sono scemo non so pensare ad altro, ecco il perché dei mei suggerimenti del zzz 
|
|
|
|
|
Logged
|
|
|
|
|
Padova
Offline
Full Member
Karma: 0
Posts: 197
|
 |
« Reply #12 on: May 26, 2012, 10:25:52 am » |
No Michele mi hai frainteso, il diavoletto l'ho messo perchè stavo facendo una furbata per aggirare il problema, non ti fare problemi figurati, anzi, hai ragione, a volte sono le cavolate a creare i problemi più grossi. Comunque, tornando al problema fatto... e... COMPILA!!!  Mistero da 100 punti! Perchè su una pagina compila e una no??? Stessa posizione, stesso IDE, stesse librerie, tutto identico, uno va e uno no! Misteroooooo!
|
|
|
|
|
Logged
|
|
|
|
|
Lamezia Terme
Offline
Shannon Member
Karma: 386
Posts: 10239
Le domande di chi vuol imparare rappresentano la sua sete di sapere
|
 |
« Reply #13 on: May 26, 2012, 10:32:41 am » |
Fammi capire, tu hai fatto una copia SOLO di alcune parti dell'esempio? Se è così penso che tu abbia solo omesso di copiare una qualche riga fondamentale. L'esempio quindi è molto più complesso del tuo sketch, se ho ben capito, se compila lui questa è la conferma che manca semplicemente qualcosa. Prova a recuperare tutti i riferimenti al DS1307 oppure, sempre con la prova dello scemo (che sarei sempre io), riparti dall'esempio ed elimina una cosa per volta facendo sempre la verifica, è da squilibrati ma si arriva di sicuro ad un punto certo 
|
|
|
|
|
Logged
|
|
|
|
|
Padova
Offline
Jr. Member
Karma: 4
Posts: 87
|
 |
« Reply #14 on: May 26, 2012, 10:49:22 am » |
Non è che l'include della RTClib vada dopo quello della Wire, visto che la prima dipende dalla seconda?
|
|
|
|
|
Logged
|
|
|
|
|
|