Hallo zusammen,
meine SanDisk Extrem PRO 32GB Karte mag nicht so recht im Ethernet Shield 2 des Arduino Mega 2560.
Wenn ich mit dem Beispiel-Sketch "CardInfo" mir meine Karte anschauen, schaut alles gut aus:
/*
SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 4 used here for consistency with other Arduino examples
created 28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 4;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.println();
Serial.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
while (1);
}
Serial.print("Clusters: ");
Serial.println(volume.clusterCount());
Serial.print("Blocks x Cluster: ");
Serial.println(volume.blocksPerCluster());
Serial.print("Total Blocks: ");
Serial.println(volume.blocksPerCluster() * volume.clusterCount());
Serial.println();
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("Volume type is: FAT");
Serial.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
Serial.print("Volume size (Kb): ");
Serial.println(volumesize);
Serial.print("Volume size (Mb): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Gb): ");
Serial.println((float)volumesize / 1024.0);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
23:02:25.878 ->
23:02:25.878 -> nitializing SD card...
23:02:26.785 -> Initializing SD card...Wiring is correct and a card is present.
23:02:27.285 ->
23:02:27.285 -> Card type: SDHC
23:02:27.319 -> Clusters: 973601
23:02:27.352 -> Blocks x Cluster: 64
23:02:27.392 -> Total Blocks: 62310464
23:02:27.392 ->
23:02:27.392 -> Volume type is: FAT32
23:02:27.428 -> Volume size (Kb): 31155232
23:02:27.463 -> Volume size (Mb): 30425
23:02:27.498 -> Volume size (Gb): 29.71
23:02:27.498 ->
23:02:27.533 -> Files found on the card (name, date and size in bytes):
23:02:27.569 -> SPOTLI~1/ 2022-02-08 22:48:56
23:02:27.604 -> STORE-V2/ 2022-02-08 22:48:56
23:02:27.637 -> FAAB0A~1/ 2022-02-08 22:48:56
23:02:27.710 -> PSID.DB 2022-02-08 22:49:06 8192
23:02:27.745 -> TM~1.LIO 2022-02-08 22:48:56 0
23:02:27.782 -> LIO~1.CRE 2022-02-08 22:48:56 0
23:02:27.819 -> TMP.CAB 2022-02-08 22:48:56 0
23:02:27.858 -> CA~1.CRE 2022-02-08 22:48:56 0
23:02:27.932 -> TM~1.STA 2022-02-08 22:48:56 0
23:02:27.967 -> INDEXS~1 2022-02-08 22:49:04 28
23:02:28.002 -> ~~~~~~21.IND 2022-02-08 22:49:04 68544
23:02:28.075 -> ~~2.IND 2022-02-08 22:49:04 16
23:02:28.111 -> ~~~3.IND 2022-02-08 22:49:04 8
23:02:28.146 -> ~5.SHA 2022-02-08 22:49:04 20564.IND 2022-02-08 22:49:02 3277~4.SHA 2022-02-08 22:49:04 8
23:02:28.184 -> 90.IND 2022-02-08 22:49:04 087.IND 2022-02-08 22:48:56 6553630.IND 2022-02-08 22:49:04 483.IND 2022-02-08 22:49:02 1024
23:02:28.260 -> ~80.IND 2022-02-08 22:49:02 82245.IND 2022-02-08 22:49:04 37677.IND 2022-02-08 22:48:56 8192
23:02:28.298 -> 74.IND 2022-02-08 22:48:56 409671.IND 2022-02-08 22:48:56 819236.IND 2022-02-08 22:49:04 2056~5.IND 2022-02-08 22:48:56 4096
23:02:28.333 -> ~4.IND 2022-02-08 22:48:56 3277~3.IND 2022-02-08 22:48:56 1638439.IND 2022-02-08 22:49:04 82.IND 2022-02-08 22:48:56 32768
23:02:28.367 -> ~1.SHA 2022-02-08 22:49:04 4096
23:02:28.436 -> ~1.DIR 2022-02-08 22:49:04 65536
23:02:28.476 -> 0DIREC~1.SHA 2022-02-08 22:49:04 1088
23:02:28.533 -> LIVE~1.IND 2022-02-08 22:49:04 4096
23:02:28.583 -> LIVE
23:02:28.621 -> LIVE
23:02:28.689 -> LIVE
23:02:28.725 -> LIVE
23:02:28.763 -> LIVE
23:02:28.834 -> LIVE
23:02:28.869 -> LIVE
23:02:28.907 -> LIVE
23:02:28.945 -> LIVE
23:02:29.021 -> LIVE
23:02:29.055 -> LIVE
23:02:29.093 -> LIVE~1.DIR 2022-02-08 22:48:56 65536
23:02:29.169 -> STORE.DB 2022-02-08 22:49:04 36864
23:02:29.207 -> STOR~1.DB 2022-02-08 22:49:06 36864
23:02:29.245 -> DBSTR-~1.HEA 2022-02-08 22:49:04 56
23:02:29.283 -> DBSTR-~1.DAT 2022-02-08 22:49:04 16384
23:02:29.355 -> DBSTR-~1.OFF 2022-02-08 22:49:04 16384
23:02:29.393 -> DBSTR-~1.BUC 2022-02-08 22:49:04 16384
23:02:29.426 -> DBSTR-~2.HEA 2022-02-08 22:49:04 56
23:02:29.494 -> DBSTR-~2.DAT 2022-02-08 22:49:04 16384
23:02:29.527 -> DBSTR-~2.OFF 2022-02-08 22:49:04 16384
23:02:29.593 -> DBSTR-~2.BUC 2022-02-08 22:49:04 16384
23:02:29.628 -> DBSTR-~3.HEA 2022-02-08 22:49:04 56
23:02:29.700 -> DBSTR-~3.DAT 2022-02-08 22:48:56 16384
23:02:29.738 -> DBSTR-~3.OFF 2022-02-08 22:48:56 16384
23:02:29.776 -> DBSTR-~3.BUC 2022-02-08 22:48:56 16384
23:02:29.809 -> DBSTR-~4.HEA 2022-02-08 22:49:04 56
23:02:29.880 -> DBSTR-~4.DAT 2022-02-08 22:49:04 16384
23:02:29.914 -> DBSTR-~4.OFF 2022-02-08 22:49:04 16384
23:02:29.980 -> DBSTR-~4.BUC 2022-02-08 22:49:04 16384
23:02:30.018 -> DBSTR-~5.HEA 2022-02-08 22:49:04 56
23:02:30.056 -> DBSTR-~5.DAT 2022-02-08 22:49:04 16384
23:02:30.127 -> DBSTR-~5.OFF 2022-02-08 22:49:04 16384
23:02:30.165 -> DBSTR-~5.BUC 2022-02-08 22:49:04 16384
23:02:30.203 -> REVERS~1 2022-02-08 22:49:04 65536
23:02:30.241 -> TMPSPO~1.STA 2022-02-08 22:49:04 4096
23:02:30.315 -> STORE_~1 2022-02-08 22:48:56 4
23:02:30.347 -> JOURNA~1.COR/ 2022-02-08 22:48:56
23:02:30.385 -> JOURNA~1.LIV/ 2022-02-08 22:48:56
23:02:30.423 -> JOURNA~2.LIV/ 2022-02-08 22:48:56
23:02:30.492 -> JOURNA~3.LIV/ 2022-02-08 22:48:56
23:02:30.529 -> JOURNA~4.LIV/ 2022-02-08 22:48:56
23:02:30.567 -> JOURNA~1.ASS/ 2022-02-08 22:48:56
23:02:30.605 -> JOURNA~2.ASS/ 2022-02-08 22:48:56
23:02:30.639 -> JOURNA~1.HEA/ 2022-02-08 22:48:56
23:02:30.677 -> JOURNA~1.MIG/ 2022-02-08 22:48:56
23:02:30.749 -> JOURNA~2.MIG/ 2022-02-08 22:48:56
23:02:30.784 -> JOURNA~1 2022-02-08 22:48:56 0
23:02:30.822 -> JOURNA~1.SCA/ 2022-02-08 22:48:56
23:02:30.860 -> SHUTDO~1 2022-02-08 22:49:06 4
23:02:30.932 -> REVERS~1.SHA 2022-02-08 22:48:58 3136
23:02:30.970 -> STOR~1.UPD 2022-02-08 22:49:04 3
23:02:31.008 -> ~1.IND 2022-02-08 22:49:04 4096
23:02:31.046 -> ~~3.SHA 2022-02-08 22:49:00 0234.SHA 2022-02-08 22:49:02 22.SHA 2022-02-08 22:49:00 0
23:02:31.084 -> LIVE~1.SHA 2022-02-08 22:49:04 4096
23:02:31.151 -> LIVE
23:02:31.189 -> LIVE
23:02:31.227 -> LIVE
23:02:31.265 -> LIVE
23:02:31.339 -> LIVE~255.SHA 2022-02-08 22:49:04 65536
23:02:31.372 -> LIVE0D~1.SHA 2022-02-08 22:49:04 1088
23:02:31.439 -> LIVE~262.SHA 2022-02-08 22:49:00 1
23:02:31.473 -> REVERS~1.UPD 2022-02-08 22:49:04 2
23:02:31.511 -> TMPSPO~1.LOC 2022-02-08 22:49:02 2081
23:02:31.550 -> VOLUME~1.PLI 2022-02-08 22:48:56 4457
23:02:31.622 -> FSEVEN~1/ 2022-02-08 22:48:56
23:02:31.660 -> FSEVEN~1 2022-02-08 22:49:06 36
23:02:31.693 -> 000000~1 2022-02-08 22:49:06 138
23:02:31.728 -> 000000~2 2022-02-08 22:49:06 72
Wenn ich mein Sketch nehme:
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"};
bool syncOnFirstStart = true;
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
char SD_Dateiname[13];
int SD_Tag, SD_Monat, SD_Jahr;
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x88, 0xAD};
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial);
if (! rtc.begin())
{
Serial.println("Kann RTC nicht finden");
while (1);
}
if (rtc.lostPower())
{
Serial.println("Stromverlust des RTC, Zeit wird neu synchronisiert");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
if (!card.init(SPI_HALF_SPEED, chipSelect))
{
Serial.println(" SD-Karte fehlerhaft.");
return;
}
else
{
Serial.println(" SD-Karte gefunden.");
}
Ethernet.begin(mac);
Serial.print("IP-Addresse: ");
Serial.println(Ethernet.localIP());
if (Ethernet.begin(mac) == 0)
{
Serial.println(" DHCP-Server nicht gefunden.");
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println(" Keine Netzwerkkarte vorhanden.");
}
else if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println(" Netzwerkkabel nicht vorhanden.");
}
}
}
void loop() {
DateTime now = rtc.now();
SD_Jahr = now.year(), DEC;
SD_Monat = now.month(), DEC;
SD_Tag = now.day(), DEC;
static char SD_Dateiname_alt[13];
snprintf_P(SD_Dateiname,13, PSTR("%04d%02d%02d.csv"), SD_Jahr, SD_Monat, SD_Tag);
if (strcmp(SD_Dateiname_alt, SD_Dateiname) != 0)
{
strcpy(SD_Dateiname_alt, SD_Dateiname);
if (!SD.exists(SD_Dateiname))
{
File dataFile = SD.open(SD_Dateiname, FILE_WRITE);
dataFile.print(F("Datum ;Zeit ;Ereignis; Wert; Einheit"));
dataFile.close();
Serial.print("Log-Datei ");
Serial.print(SD_Dateiname);
Serial.println(" erstellt");
}
}
File dataFile = SD.open(SD_Dateiname, FILE_WRITE);
if (dataFile) {
dataFile.print(now.day(), DEC);
dataFile.print(".");
dataFile.print(now.month(), DEC);
dataFile.print(".");
dataFile.print(now.year(), DEC);
dataFile.print(" ;");
dataFile.print(now.hour(), DEC);
dataFile.print(":");
dataFile.print(now.minute(), DEC);
dataFile.print(":");
dataFile.print(now.second(), DEC);
dataFile.print(" ;Temeratur FaWoWa ;");
dataFile.print("25");
dataFile.println(" ;°C");
dataFile.close();
}
else
{
Serial.print("Konnte Log-Datei ");
Serial.print(SD_Dateiname);
Serial.println(" nicht öffnen");
}
}
Kommt das raus:
23:12:50.446 -> SD-Karte gefunden.
23:12:59.171 -> IP-Addresse: 192.168.178.15
23:12:59.281 -> Log-Datei 20220208.csv erstellt
23:12:59.319 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.357 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.433 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.471 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.509 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.547 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.619 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.652 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.688 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.758 -> Konnte Log-Datei 20220208.csv nicht öffnen
23:12:59.792 -> Konnte Log-Datei 20220208.csv nicht öffnen
Kann mir jemand sagen woran das liegt?
Danke vorab...