aspetta .... io ho la mega ti passo quello che uso io che funziona veditelo e smanetta ![]()
#include <SD.h>
byte err_sd=1;
byte SD_CS = 4; // pin 4 is the SPI select pin for the SDcard
byte ETHER_CS = 10; // pin 10 is the SPI select pin for the Ethernet
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
void setup()
{
Serial.begin(9600);
pinMode(ETHER_CS, OUTPUT); // Set the CS pin as an output
digitalWrite(ETHER_CS, HIGH); // Turn off the W5100 chip! (wait for configuration)
pinMode(SD_CS, OUTPUT); // Set the SDcard CS pin as an output
digitalWrite(SD_CS, HIGH); // Turn off the SD card! (wait for configuration)
Serial.println("inizializzazione SD card......Attendere......");
sd_init();
}
void sd_init()
{
err_sd=0;
if (!card.init(SPI_FULL_SPEED, SD_CS)) err_sd=1;
if (!volume.init(&card)) err_sd=1;
if (!root.openRoot(&volume)) err_sd=1;
if (err_sd==0) Serial.println("inizializzazione SD completata.");
else Serial.println("inizializzazione SD fallita.");
}
void log_write() // esempio di scrittura
{
//scrittura su file txt sd .... eventi
file.open(&root, "datalog.txt", O_APPEND | O_WRITE);
String data= giorno + "/" + mese + "/" + anno + " " + ore + ":" + minuti + ":" + secondi;
file.println(data+ " >> " + log_riga);
delay(1);
file.close();
}
cosi' a me funziona con mega+ethernet shield+sd a bordo
ciao