Las pruebas que estoy haciendo son unir el código de mi shield SD y de mi Shiel Ethernet, para luego poder usarlo para guardar datos de sensores de temperatura humedad etc (data logger) y tener un servidor que me muestre el estado actual de los sensores y poder apagar y prender unos rele.
pero como puedes ver el código esta en base de prueba. realice el cableado como me lo dijiste me funcionaron ambos shield, así que ahora solo me queda configurar y poder generar el server con ayuda de la SD, lo tengo pensado en ajax.
PD. cuantos shield puedo conectar al mismo miso, mosi, sck, tienes alguna idea de cuanto puede manejar el mega?
http://es.zimagez.com/zimage/img20140529215943.php
// This is a demo of the RBBB running as webserver with the Ether Card
// 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
#include <SD.h>
// declara ethernet
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,102 };
byte Ethernet::buffer[500];
BufferFiller bfill;
//declara SD
File dataFile;
int led = 13;
void setup () {
// iniciq ether
if (ether.begin(sizeof Ethernet::buffer, mymac, 7) == 0)
Serial.println( "Failed to access Ethernet controller");
ether.staticSetup(myip);
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
//inicia SD mas comentarios
Serial.begin(9600);
pinMode(led, OUTPUT);
Serial.print("Iniciando SD card...");
pinMode(6, OUTPUT);
pinMode(led, OUTPUT);
digitalWrite(6, HIGH);
if (!SD.begin(6)) {
Serial.println("Fallo comunicacion o no existe SD");
digitalWrite(led, HIGH);
return;}
digitalWrite(led, LOW);
Serial.println("SD Iniciada.");
dataFile = SD.open("datalog.txt", FILE_WRITE);
/////////
if (dataFile) {
Serial.println("Escribiendo Informacion...");
dataFile.println("Escribiendo Informacion...");
Serial.println("");
dataFile.println("");
Serial.println("Programo: Alejandro Acosta Elias");
dataFile.println("Programo: Alejandro Acosta Elias");
Serial.println("");
dataFile.println("");
Serial.println("<<< Datalogger >>>");
dataFile.println("<<< Datalogger >>>");
dataFile.close();}
else {
Serial.println("error opening test.txt");}
////////////
}
static word homePage() {
long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
"\r\n"
"<meta http-equiv='refresh' content='2'/>"
"<title>RBBB server</title>"
"<h2>$D$D:$D$D:$D$D</h2>"
"<h1>Hello from Arduino!</h1>"
"<p>A web page from the Arduino server</p>"
),
h/10, h%10, m/10, m%10, s/10, s%10);
return bfill.position();
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) // check if valid tcp data is received
ether.httpServerReply(homePage()); // send web page data
//guarda SD
String dataString = "";
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ","; }}
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
digitalWrite(led, LOW);
dataFile.println(dataString);
delay(1);
dataFile.close();
Serial.println(dataString);
}
else {
Serial.println("Fallo comunicacion.txt");
Serial.println("Revise conecxion");
digitalWrite(led, HIGH);
delay(1); }
}