Pages: [1]   Go Down
Author Topic: problems arduino ethernet and sd  (Read 285 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


someone  know how I can do to save the information from leds in sd card and I can see on the internet ? if LEER  was click on the web page I want to read the information from my sd card but I do not know where is the mistake . I read about the configurations of pins in the examples from  arduino and It say that both aplications use the similar pins . I am not sure how I can to do to works with two applications.Are there another library?

Code:
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x5C, 0x16};
IPAddress ip(192,168,1,5);
byte gateway  [] = {192,168,1, 1};
byte subred   [] = {255, 255, 255, 0};
int led = 7;
const int chipSelect = 4;
EthernetServer server(80);
String cad=String(100);
File myFile;

const char html[] =
//"HTTP/1.1 200 OK"
//"Content-Type: text/html"
"<!DOCTYPE HTML>"
"<html lang='es'>"
"<head><title> ARDUINO </title></head>"
"<body bgcolor='#FFFFFF' text='#FFFFFF' marginheight='125' marginwidth='125' link='#0033CC' vlink='#0033CC' alink='#0033CC'>"
"<center> <font face='Times New Roman, Times, serif' color='#0033CC' size='45'> ARDUINO </center>"
"<center> <font face='Times New Roman, Times, serif' color='#0033CC' size='5'><a href='http://www.arduino.cc'>arduino.cc </a> </center>"
"<br><br>"
"<form method=get><input type=hidden name=leer value=1><input type=submit value=LEER></form>"
"</body></html>";

void setup()
{
  pinMode(led, OUTPUT);
  Ethernet.begin(mac,ip,gateway,subred);
  server.begin();
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  pinMode(chipSelect, OUTPUT); 
  digitalWrite(chipSelect,HIGH); 
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}

void loop()
{   
  cad="";
  EthernetClient client = server.available();
  if (client) {
    server.print(html);
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        cad=cad+c;
        if (c == '\n')
        {
          if ( cad.lastIndexOf("leer") > 0)
          {
            digitalWrite(led,HIGH);
            delay(1000);
            myFile = SD.open("call.txt");
            if (myFile) {
            Serial.println("call.txt:");
            while (myFile.available()) {
        Serial.write(myFile.read());
          }
          myFile.close();
          } else {
          Serial.println("error opening call.txt");
          }
          }
          client.stop();
        }
      }
    }
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you having a specific problem, with a specific error message, or are you just complaining?

What do you need help with?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the trouble is that I can not to read or write on the sd card when I am on the internet
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the trouble is that I can not to read or write on the sd card when I am on the internet

Could be issues with your network setup. You might try the below startup code.

Code:
  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  server.begin();
  Serial.println("Ready");
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: