Go Down

Topic: Ethernet W5100 Shield - no COSM access whenever microSD installed. (Read 752 times) previous topic - next topic

yusrij

Hi,

I am using arduino with ethernet shield (W5100) attached with microSD slot. I wrote a sketch that can send data to COSM. At this moment, there is no problem with the internet connection.

My next move is to have a file in SD. Now, I got a problem. After a few troubleshooting and cut everything short, I found whenever I put microSD in the slot, my sketch can only send data to COSM only once. The next data cannot be send to COSM until I restart the arduino.

And sometimes, network for ethernet shield went down. I ping the arduino, but no reply.

The problem with the SD, maybe not related with the first sketch I wrote because I still not write the sketch for the SD yet.

I read about SS for SD and Ethernet but, I wonder if SD and Ethernet library were should be enough to get a good sketch without modifying the library?

Need someone help to give me an idea to make SD and ethernet working.

SurferTim

Here is the setup function that works for me. I use the SD and w5100 together.
Code: [Select]
void setup() {
  Serial.begin(9600);

  // disable w5100 SPI while starting SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print(F("Starting SD..."));
  if(SD.begin(4) == 0) Serial.println(F("fail"));
  else Serial.println(F("ok"));

  Serial.print(F("Starting w5100..."));
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());

  Serial.println(F("Ready."));
}


Nick_Pyner

Here is mine:

The setup is about the same as Surfer's but I don't have the

  digitalWrite(10,HIGH);

and I don't know how operative that is. What I do emphasise is that the SD operation is exclusive i.e. the filewrite is open only when required, and nothing else is attempted while it is.

Code: [Select]

void setup() {
   lcd.begin(84, 48);
     // Register the custom symbols...
  lcd.createChar(DEGREES_CHAR, degrees_glyph);
  lcd.createChar(SLASH_CHAR, slash_glyph);
  Wire.begin();
  Serial.begin(9600);
  delay(300);//Wait for newly restarted system to stabilize
  lcd.setCursor (0,0);
  lcd.print("Initializing");
  delay(2000);
  lcd.setCursor (0,1);

  pinMode(10, OUTPUT);

  if (!SD.begin(4))
  {
    lcd.print("failed!");
    delay (2000);
    return;
  }
  lcd.print("init. OK!");
  delay(2000);
      getFileName();
      Serial.println(filename);
  lcd.clear();

  sensors.setResolution(InThermo, 12);
  sensors.setResolution(OutThermo, 12);
  sensors.setResolution(DrainThermo, 12);

  Serial.println("Starting multiple datastream upload to Cosm...");
  Serial.println();

  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(10000);
  }
}

void loop() {
  running();
  GetClock();
  if (hour == 0 && minute == 0 && second <2)
  {
    getFileName();
  }
Serial.print("DATA,TIME,       ");
  int ret=0;
  //get the values from the DS8B20's
  sensors.requestTemperatures();

  float InTemp = (sensorValue(InThermo));
  float OutTemp = (sensorValue(OutThermo)); 
  float DrainTemp = (sensorValue(DrainThermo));

  float diff = OutTemp - InTemp;

  datastreams[0].setFloat(InTemp);
  datastreams[1].setFloat(OutTemp);
  datastreams[2].setFloat(DrainTemp);
  datastreams[3].setFloat(diff);
  Serial.print(InTemp);
  Serial.print(" ,  ");
  Serial.print(OutTemp);
  Serial.print(" ,  ");
  Serial.print(DrainTemp);
  Serial.println(" ,  ");

  lcd.setCursor(49,0);
  lcd.print(InTemp);
  lcd.setCursor(49,1);
  lcd.print (OutTemp);
  lcd.setCursor(49,2);
  lcd.print(DrainTemp);

  k=k+1; 

  if (k>9 )
  {   
      ret = cosmclient.put(feed, cosmKey);    // SEND FEED TO COSM
     
      myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",");

  myFile.print(InTemp);
  myFile.print(",");
  myFile.print(OutTemp);
  myFile.print(",");
  myFile.print(DrainTemp);
  myFile.print(",");
  myFile.println();
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
       
      k=0;
  }
  delay(850);
}  // loop ends here


yusrij

Hi

It seems like I need to disable 1 module at a time.

But, my next lame question. If the ethernet already got an IP (can be ping from other PC), when ethernet is disabled, to give a way for the SD to be accessed, is there any network error happen to the ethernet? Something like ping got no replied?

TQ

Nick_Pyner

Disable is a relative term. While I open and close the SD operation, that may be deemed disabled, but  I don't do anything to the Ethernet.
I can't comment on the rest, I have never knowingly pinged anything in my life. But now that you are using language like that, I'm inclined to get suss about the rest of your code that I haven't seen. So I ask the perennial question that should not be perennial any more - are you using the latest cosm libraries cosm.h and httpClient.h? If not, it is vital that you do so.  If you are, I guess your problem is just the order of operations.

SurferTim

Quote
The setup is about the same as Surfer's but I don't have the

  digitalWrite(10,HIGH);

Without that on a Mega, it is almost always fatal. On the Uno, I think it is covered by the SD startup, but that would only apply if the default slave select is D10, but on a Mega it is D53.

Nick_Pyner

#6
Apr 22, 2013, 02:27 am Last Edit: Apr 23, 2013, 06:38 am by Nick_Pyner Reason: 1
OK. While I started my foray into cosm with an Etherten, I believe it was the addition of SD that obliged me to move to a Mega. Etherten has SD and ethernet built-in, and all the Megas use a combined ethernet and SD shield. I made no changes to the code, only additions. I haven't had a problem with Mega after several weeks of continuous operation, but maybe I have been living in a fool's paradise.

I have just trawled up the following
http://arduino.cc/forum/index.php?topic=63011.0;wap2
http://arduino.cc/forum/index.php?topic=125646.10;wap2

which don't think exactly agree with each other and I wonder if my tight open/write/close filewrite sequence is a reasonable alternative. I can't recall if I did that to fix a problem, or I was just trying to be neat. What Robillaart wrote seems the bleeding obvious and, if I had seen it before, I would have done that.

Go Up