EtherMega - Question about SD / ETHERNET port
EtherMega - Question about SD / ETHERNET port
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.
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.
- jonoxer
- Freetronics Staff
- Posts: 298
- Joined: Sat Oct 15, 2011 11:31 am
- Location: Melbourne, Australia
- Contact:
Re: EtherMega - Question about SD / ETHERNET port
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
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
Re: EtherMega - Question about SD / ETHERNET port
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.
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.
Re: EtherMega - Question about SD / ETHERNET port
This is my code that works for some reason.
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.
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();
}
Re: EtherMega - Question about SD / ETHERNET port
But doesn't ethermega have 256k of flash ?bfisher wrote:If my sketch size is 31, 600 bytes (out of 32, 256 bytes)
Are you sure you're configured for the correct board ?
Re: EtherMega - Question about SD / ETHERNET port
Ah, I guess I didn't even realize that I was posting on an EtherMega thread in the EtherTen forum! I have an Etherten.
Re: EtherMega - Question about SD / ETHERNET port
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).
then add a few of these:
to see how you're tracking.
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);
}
Code: Select all
Serial.println(freeRam); //
Re: EtherMega - Question about SD / ETHERNET port
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.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
Thanks,
-Tim.