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