Go Down

Topic: problems arduino ethernet and sd (Read 341 times) previous topic - next topic

EJTR


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: [Select]

#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();
        }
      }
    }
  }
}

PaulS

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

What do you need help with?

EJTR

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

zoomkat

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: [Select]

  // 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");
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy