Au cas ou je te mets un petit code de test fonctionnel si ton problème n'est pas résolu:
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
/////PIN MAPPING////
D0: RX Serial
D1: TX Serial
D2:
D3:
D4: SS_SD_CARD (or CS PIN)
D5:
D6:
D7:
D8:
D9:
D10: SS_ETHERNET
D11: MOSI
D12: MISO
D13: CLK
A0:
A1:
A2:
A3:
A4:
A5:
*/
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define DEBUG_SD
#define DEBUG_ETHERNET
#define SS_SD_CARD 4
#define SS_ETHERNET 10
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};// give an unique adress on your network
IPAddress ip(192, 168, 1, 252);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
void setup() {
pinMode(SS_SD_CARD, OUTPUT);
pinMode(SS_ETHERNET, OUTPUT);
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
// Open serial communications and wait for port to open:
Serial.begin(9600);
SDCardCode_init();
ethernetCode_init();
}
void loop() {
ethernetCode();
SDCardCode();
}
void SDCardCode_init() {
// ...
digitalWrite(SS_SD_CARD, LOW); // SD Card ACTIVE
#ifdef DEBUG_SD
Serial.print(F("Initializing 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, SS_SD_CARD)) {
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card is inserted?"));
Serial.println(F("* Is your wiring correct?"));
Serial.println(F("* did you change the chipSelect pin to match your shield or module?"));
return;
} else {
Serial.println(F("Wiring is correct and a card is present."));
}
// print the type of card
Serial.print("Card type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println(F("SD1"));
break;
case SD_CARD_TYPE_SD2:
Serial.println(F("SD2"));
break;
case SD_CARD_TYPE_SDHC:
Serial.println(F("SDHC"));
break;
default:
Serial.println(F("Unknown"));
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println(F("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"));
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print(F("Volume type is FAT"));
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print(F("Volume size (bytes): "));
Serial.println(volumesize);
Serial.print(F("Volume size (Kbytes): "));
volumesize /= 1024;
Serial.println(volumesize);
Serial.print(F("Volume size (Mbytes): "));
volumesize /= 1024;
Serial.println(volumesize);
Serial.println(F("\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);
#endif
if (!SD.begin(SS_SD_CARD)) {
Serial.println(F("Card failed, or not present"));
// don't do anything more:
return;
}
Serial.println(F("card initialized."));
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
// ...
}
void SDCardCode() {
// ...
digitalWrite(SS_SD_CARD, LOW); // SD Card ACTIVE
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("data.txt", FILE_WRITE);
delay(10);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println(F("error opening datalog.txt"));
}
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
// ...
}
void ethernetCode_init() {
// ...
digitalWrite(SS_ETHERNET, LOW); // Ethernet ACTIVE
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
#ifdef DEBUG_ETHERNET
Serial.print(F("server is at "));
Serial.println(Ethernet.localIP());
#endif
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
// ...
}
void ethernetCode() {
// ...
digitalWrite(SS_ETHERNET, LOW); // Ethernet ACTIVE
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println(F("new client"));
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connection: close")); // the connection will be closed after completion of the response
//client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println(F("<!DOCTYPE HTML>"));
client.println(F("<html>"));
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print(F("analog input "));
client.print(analogChannel);
client.print(F(" is "));
client.print(sensorReading);
client.println(F("
"));
}
client.println(F("</html>"));
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println(F("client disconnected"));
}
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
// ...
}