EtherMega - Question about SD / ETHERNET port

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
shooter
Posts: 1
Joined: Sat Dec 03, 2011 3:44 pm

EtherMega - Question about SD / ETHERNET port

Post by shooter » Sat Dec 03, 2011 3:48 pm

Hi

I recently purchased a ethermega board. Im a new person to this whole things, and im having HUGE troubles trying to figure out how to get the ethernet port AND the SD card to work.

It seems if i want to use one i have to disable the other?

Im just using the examples a the moment to play around, but all I have found is

To use ethernet you need to put the following file befroe your start the ethernet
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);



To use the SD card you need to do the fllowing
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!


But the problem is when switching between them I end up getting mixed results, code that worked once now doesnt...

Can you point me in the right direction on this topic? Seems to be a specific one as most other boards have it as sheilds not built in.

User avatar
jonoxer
Freetronics Staff
Freetronics Staff
Posts: 298
Joined: Sat Oct 15, 2011 11:31 am
Location: Melbourne, Australia
Contact:

Re: EtherMega - Question about SD / ETHERNET port

Post by jonoxer » Sun Dec 04, 2011 11:23 pm

You should be able to use both at the same time, although when I say "at the same time" I mean your sketch should be able to access both the SD card and the network sequentially, not literally simultaneously. Because the SD card and the Wiznet Ethernet chip both interface via SPI, your sketch needs to alternate between talking to one and talking to the other.

Our QA test process for the EtherTen includes loading a test sketch that brings up the network, access an SD card, and displays a file list from the card when its accessed using a web browser. The test is based on the code in Limor's tutorial here:

http://www.ladyada.net/learn/arduino/ethfiles.html

Perhaps that would be a good place to start?
--
Jon

bfisher
Posts: 7
Joined: Thu Jul 26, 2012 6:19 am

Re: EtherMega - Question about SD / ETHERNET port

Post by bfisher » Sun Jul 29, 2012 11:51 pm

I'm also having issues with utilizing the SD and ETH with each other. I have loaded in LadyAda's SD webserver and successfully been able to look at all files on the SD card through my web browser. I would assume that if that worked and setup() in MY code is almost the same, then it should work as well.

I am also running:
-Cosm Client (uploads once a day)
-Read/Write on the SD card all the time.
-Ethernet NTP client

If my sketch size is 31, 600 bytes (out of 32, 256 bytes) then could I be running into buffer problems that would affect this? In the Serial Monitor my code never gets out of the setup() section. It hangs up and sometimes sends gibberish into the monitor window. I've tried so many different things from deleting all serial prints and saving code space, to deleting modules like Cosm and NTP to no avail.

bfisher
Posts: 7
Joined: Thu Jul 26, 2012 6:19 am

Re: EtherMega - Question about SD / ETHERNET port

Post by bfisher » Mon Jul 30, 2012 4:02 am

This is my code that works for some reason.

Code: Select all

void setup() {
  Serial.begin(9600);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());  
  
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH);                    // but turn off the W5100 chip!

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  delay(1000);
  
  // Debugging complete, we start the server!
  Ethernet.begin(mac, ip);
  server.begin();
  
}
And then say, for example, I remove one of the Serial.println, the code doesn't continue on and serial monitor gives me weird results. It's the strangest thing.

effgee
Posts: 64
Joined: Tue Aug 07, 2012 2:41 am

Re: EtherMega - Question about SD / ETHERNET port

Post by effgee » Thu Aug 16, 2012 5:48 am

bfisher wrote:If my sketch size is 31, 600 bytes (out of 32, 256 bytes)
But doesn't ethermega have 256k of flash ?
Are you sure you're configured for the correct board ?

bfisher
Posts: 7
Joined: Thu Jul 26, 2012 6:19 am

Re: EtherMega - Question about SD / ETHERNET port

Post by bfisher » Thu Aug 16, 2012 5:54 am

Ah, I guess I didn't even realize that I was posting on an EtherMega thread in the EtherTen forum! I have an Etherten.

effgee
Posts: 64
Joined: Tue Aug 07, 2012 2:41 am

Re: EtherMega - Question about SD / ETHERNET port

Post by effgee » Tue Aug 21, 2012 6:20 am

I've found a 'trap for young players' with Arduino is tha the C++ objects can quickly chew up all your sram, causing random runtime glitches & reboots.

Try adding this function to your code to see how much ram you have left (can't remember where I got this from, credit to whoever wrote it).

Code: Select all

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
then add a few of these:

Code: Select all

Serial.println(freeRam); //
to see how you're tracking.

timr49
Posts: 2
Joined: Sat Apr 07, 2012 9:22 am

Re: EtherMega - Question about SD / ETHERNET port

Post by timr49 » Wed Feb 06, 2013 3:49 am

jonoxer wrote:...Our QA test process for the EtherTen includes loading a test sketch that brings up the network, access an SD card, and displays a file list from the card when its accessed using a web browser. The test is based on the code in Limor's tutorial here:

http://www.ladyada.net/learn/arduino/ethfiles.html

Perhaps that would be a good place to start?
--
Jon
Jon, I am using an EtherMega and getting inconsistent results reading from the SD card (before attempting to use the Ethernet). For example listfiles from examples was working (after amending pin numbers per the ladyada tutorial) and but then later it wasn't. Could you please provide your QA test for the SD card on an EtherMega? That will enable me to confirm that I have a solid base before going forward again? Of course I may have scrambled the SD card contents or the hardware or the software or something else to cause it to go from working to not working, in which case knowing whether your basic test works or not would be a useful data point.
Thanks,
-Tim.

Post Reply