Ajuda com shield datalogger + LCD 16x2

Boa tarde pessoal. Sou novo no fórum e completamente amador mundo da programação e eletrônica… rs. Minha área é a microbiologia mas estou precisando me “aventurar” na área de vcs para criar algumas soluções para minhas pesquisas. Neste caso específico, estou tentando montar um gasômetro (conta ciclos com volume pre-definido) que manda informação do volume acumulado para um LCD e para um cartão SD (shield datalogger) similar ao da Adafruit. Contudo, apesar do arquivo ser criado corretamente no cartão e as informações aparecerem no display LCD corretamente, nenhuma informação é gravada no arquivo. Não consigo encontrar o erro e gostaria de saber se alguém poderia me ajudar dando uma revisada no código para ver se encontra algum furo que não consigo ver. Desde já agradeço. Segue abaixo o código (me desculpem, não sei a maneira correta de postar o código aqui…):

#include “RTClib.h”
#include “SD.h”
#include <LiquidCrystal.h>
#include <Wire.h>

float volCiclo = 0.232;

//definições do datalogger
//#define ECHO_TO_SERIAL 0 // echo data to serial port
//#define WAIT_TO_START 0 // Wait for serial input in setup()

RTC_DS1307 RTC; // define the Real Time Clock object

//Define os pinos que serão utilizados para ligação ao display
//LiquidCrystal lcd inicial (12, 11, 5, 4, 3, 2);
//Modificação dos pinos para liberar 11 e 12
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

// 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)
{

//Define o número de colunas e linhas do LCD
lcd.begin(16, 2);

lcd.clear();
//Posiciona o cursor na coluna 1, linha 0;
lcd.setCursor(1, 0);
//Envia o texto entre aspas para o LCD
lcd.print(“error:”);
lcd.println(str);

while (1);
}

// this constant won’t change:
const int buttonPin = 8; // the pin that the pushbutton is attached to
const int ledPin = 9; // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int ledState = LOW;

// the following variables are unsigned long’s because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 1000; // ESTE VALOR DEFINE O TEMPO MÍNIMO QUE O CONTATO PRECISA FICAR FECHADO PARA CONTABILIZAR!!

void setup() {

// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
//Define o número de colunas e linhas do LCD
lcd.begin(16, 2);
// set initial LED state
digitalWrite(ledPin, ledState);

//initialize the SD card
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(10, OUTPUT);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(“Inicializando SD”);
delay (2000);

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
lcd.clear();
lcd.setCursor(1, 0);
lcd.print(“SD falhou”);
delay (10000);
// don’t do anything more:
return;
}

lcd.clear();
lcd.setCursor(1, 0);
lcd.print(“SD iniciado”);
delay (2000);

// 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(“ERRO DE ARQUIVO”);
}

lcd.clear();
lcd.setCursor(1, 0);
lcd.print(“Gravando em:”);
lcd.setCursor(1, 1);
lcd.println(filename);
delay (3000);

Wire.begin();
if (!RTC.begin()) {
logfile.println(“RTC failed”);
}

// attempt to write out the header to the file
logfile.println(“millis,tempo,biogas”);

}
void loop() {

DateTime now;

//Limpa a tela
lcd.clear();
//Posiciona o cursor na coluna 1, linha 0;
lcd.setCursor(1, 0);
//Envia o texto entre aspas para o LCD
lcd.print(“Gasometro”);
lcd.setCursor(15, 1);
//Envia o texto entre aspas para o LCD
lcd.print(“L”);
lcd.setCursor(1, 1);
lcd.print(“Biogas:”);
// read the pushbutton input pin:
int reading = digitalRead(buttonPin);

//Se “reading” diferir de “lastButtonState”, então o código atribui o valor de “millis” para "lastDebounceTime"
if (reading != lastButtonState) {
lastDebounceTime = millis();
ledState = LOW;
// set the LED:
digitalWrite(ledPin, ledState);
}
//Após alguns ciclos continuamente acionado o valor de “millis” se torna suficientemente alto para atender à condição
if ((millis() - lastDebounceTime) > debounceDelay) {
//Evita que a contagem seja contínua a cada ciclo enquanto o botão estiver acionado
if (reading != buttonState) {
//igual buttonState a reading
buttonState = reading;
//Se o valor atribuído a buttonState for HIGH, então adiciona na contagem
if (buttonState == HIGH) {
buttonPushCounter++;
ledState = HIGH;
// set the LED:
digitalWrite(ledPin, ledState);

    // log milliseconds since starting
    uint32_t m = millis();
    logfile.print(m);           // milliseconds since start
    logfile.print(", ");

    // fetch the time
    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.print(buttonPushCounter * volCiclo, 3);
  }
}

}
//Força igualdade de “lastButtonState” e “reading” a cada ciclo
lastButtonState = reading;

lcd.setCursor(8, 1);
lcd.print(buttonPushCounter * volCiclo, 3);

delay(1000);
}