Nano33 Datalogger NOt working: SD card failure

Hi,
I bought two identical dataloggers for Nanoi33 (https://www.aliexpress.com/item/32799192133.html?spm=a2g0o.order_detail.0.0.206df19cCBFUU6) that are supposed to be used both with Nano and with Nano33.
However, when I tried both of them with two different 4 Gb SD cards formatted as advised I've always got the message "SD card failure".
Since I don't think that both dataloggers and both SD cards are faulty I think that maybe I've made some mistake either in the physical arrangement or in the code ( that I copied from an example I found on this site https://publiclab.org/wiki/nano-data-logger)
For what attains the circuit I've just plugged the Nano33 on top of the datalogger and I connected an I2C OLED (which works) and a DHT22 to D2 pin (which also works), while the datalogger is not working.
I'm enclosing a simplified version of the code without the DHT sensor

#include <SdFat.h>                            // https://github.com/greiman/SdFat/
#include  <SPI.h>
#include <Wire.h>
#include <RTClib.h>                           // library from https://github.com/adafruit/RTClib    

RTC_DS1307 rtc;                               // The real time clock object is "RTC"
#define DS1307_I2C_ADDRESS 0x68
SdFat SD;                                     // The SdFat object is "SD"
#define MOSIpin 11                            // For SD card
#define MISOpin 12                            // For SD card
const int chipSelect = 10;                    // CS pin for the SD card
char tmeStrng[ ] = "0000/00/00,00:00:00";     // a template for a data/time string

long utc;
unsigned long logSeconds = 5;                  // ****** Enter ****** the number of seconds between logging events
unsigned long logMillis = logSeconds * 1000;      
                         
void setup() {  
  Serial.begin(9600);              // Open serial communications and wait for port to open:
  Wire.begin();                    // initialize the I2C interface
  rtc.begin();                     // initialize the RTC 
  
      // Uncomment the line below and load the sketch to the Nano to set the RTC time. Then the line must 
      // be commented out and the sketch loaded again or the time will be wrong.
 //rtc.adjust(DateTime((__DATE__), (__TIME__)));    //sets the RTC to the time the sketch was compiled.

  while (!Serial) {
    ;                              // wait for serial port to connect. Needed for native USB port only
  }
 
  Serial.print("Find SD card: ");          // initialize and display the status of the SD card:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed");
    while(1);
  }
  Serial.println(" SD card OK");   
  Serial.print("Logging to microSD card every "); 
  Serial.print(logSeconds);   
  Serial.println(" seconds.");  
  Serial.print("Which equals "); 
  Serial.print(logMillis); 
  Serial.println(" milliseconds."); 
  Serial.println();     
                                           //print a header to the data file with column headings
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {                          // if the file is available, write to it:
    dataFile.println("Date,Time,UTCtime,Temp_C,Pressure_hPa,Altitude_M");
    dataFile.close();
  }
  else {
    Serial.println("file error");          // if the file is not open, display an error:
  }
    
    delay(2000);                           // Wait so the sensor can initialize 
}                                          // end of setup
void loop() 
{
    DateTime now = rtc.now(); 
    utc = (now.unixtime());  
    sprintf(tmeStrng, "%04d/%02d/%02d,%02d:%02d:%02d", now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second()); // [added seconds]
                                    
    Serial.print("RTC utc Time: ");                               // Display results on the serial monitor:   
    Serial.print(now.unixtime());
    Serial.println();
    Serial.print("RTC time: ");
    Serial.println(tmeStrng);

                                                         // write the data to the SD card:                                                                 
    File dataFile = SD.open("datalog.txt", FILE_WRITE);         // if the file is available, write to it:
      dataFile.print(tmeStrng);dataFile.print(",");
      dataFile.print(utc);dataFile.print(",");
      dataFile.flush();                                        // wait for serial data to complete transmission
      dataFile.close();
    delay(logMillis);                                          // Write data every logMillis/1000 seconds
}                                                              // end of the MAIN LOOP

Thanks for your help

Hi,
Since I got no answer to my question, I'm going to rewrite it in a different way
Which datalogger can I use with Nano 33?
My need is to record data from temperature and humidity sensors every six hours and, besides storing them on a SD card, to transmit them to a remote PC through WiFi
Thx again for your help

Hi Bruno,

Some time ago I posted following wiring schema that worked for me while connecting sd card readers with Nano33 iot as well

I know it’s not a complete data logger solution since the time stamp must be got from Internet but with 33 iot and Wi-Fi this can be solved for some use cases.

Andrea

Hi apagliari,
sorry for the long delay in my answering your useful post but I was out of town AND without a computer.
I read your interesting post but, since i'm a newbie, I'm going to sum up what I've understood:
a) I have to put aside the two dataloggers with RTC supposedly devised for Nano 33 that are NOT working ( at least in my hands)
2) I have to use a RTC ( for example a DS3231) AND a SD card breakout board I've to connect to Nano 33
3) the RTC will be connected to the SCL/SDA pins of Nano 33 (besides obviously VCC and GND)
4) the SD card board will be connected MISO to D12 , MOSI to D11 , SCK to 13 and CS to 10 ( are they correct ?)
5) then I have to use a library for RTC working in Nano 33 and a library for SD card working in Nano 33
I'd be very grateful if you could confirm that this approach can work or correct the mistakes of it.
Thx in advance

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.