EthernetClient problems

Hi

I'm using an Ethernet shield and trying to initiate the client-part. This is my setup and start of the ethernetconnect().

void setup()
{
    Serial.begin(9600);
    Serial.println("Starting up.....");
    EthernetConnect();
    //Initialize all nessecary ports and variables
    pinMode(HLTFillValvePin, OUTPUT);
    pinMode(HLTHeater1Pin, OUTPUT);
    pinMode(HLTEmptyValvePin, OUTPUT);
    digitalWrite(HLTEmptyValvePin, LOW);    
    connected=0;
}

void EthernetConnect()
{

    EthernetClient Client;
    Serial.println("Initializing ethernet module");
    //Ethernet.begin(mac, ip);

If I remove the comment from Ethernet.begin my output goes crazy and shows the prints in setup() along with strange letters and goes into an infinite loop.. Anyone got any good tips? Here is some of the output I get: StaÔhernet module i pu| ÿ r8 Starting up..... Initializing ethernet module i pu| ÿ r8 Starting up..... Initializing ethernet module i pu| ÿ r8 Starting up..... Initializing ethernet module i pu| ÿ r8 Starting up.....

Anyone got any clue of what could be my problem?

//Morten

Anyone got any clue of what could be my problem?

Sure. You didn't post all of your code.

The fact that your output shows "Starting up....." over and over says that you are crashing, and the Arduino resets.

Why depends on what you didn't show us.

Complete code for startup and Ethernet init.

// Ethernet declarations
#include <SPI.h>
#include <Ethernet.h>
 
// the media access control (ethernet hardware) address for the shield:
// MAC For my ethernet shield BC:B1:F3:4A:B4:EA
byte mac[] = { 0xBC, 0xB1, 0xF3, 0x4A, 0xB4, 0xEA };  
//the IP address for the shield: 192.168.1.5
byte ip[] = { 192, 168, 1, 25 };    
// Default gateway
byte gateway[] = { 192,168,1,1 };
 
 //What server to connect to?
byte server[] = { 83, 143, 81, 42 };// 
void setup()
{
	Serial.begin(9600);
	Serial.println("Starting up.....");
	EthernetConnect();
	//Initialize all nessecary ports and variables
	pinMode(HLTFillValvePin, OUTPUT);
	pinMode(HLTHeater1Pin, OUTPUT);
	pinMode(HLTEmptyValvePin, OUTPUT);
	digitalWrite(HLTEmptyValvePin, LOW);	
	connected=0;
}

void EthernetConnect()
{

    EthernetClient Client;
	Serial.println("Initializing ethernet module");
	Ethernet.begin(mac, ip);
	delay(1000); 
	connected=Client.connect(server, 80);
	if(connected==1)
	{
		Serial.println("CONNECTED");
		//Client.stop();
	}
	return;
}

So my error must be inside EthernetConnect() since the call to this function is the thing that “triggers” the reset…
If I comment out from Ethernet.connect and the rest of the function it does not crash. If I add the Ethernet.connect and not the rest it starts to crash.

//Morten

Post ALL of your code. Not just the parts where you think the error might be.

When you comment out code, stuff gets left out of SRAM that might well be affecting your program's ability to operate. If you uncomment that code, and new overflow SRAM, that would cause the issue you are seeing. The only way to know is to see all of your code.

Here is all code. Most of it (everything except the ethernet-part) was written a few days ago and was working fine. Today I got my ethernet shield and wanted to use a client to post to a php website The code was too long to fit so added it to pastebin http://pastebin.com/2XwuCLUX

The code was too long to fit so added it to pastebin

Sounds like you may need to drop back to get simple working client code and then work from there.

Sounds like you may need to drop back to get simple working client code and then work from there.

That was actually what I did from the start. Made a simple working client capable of sending data to my php script. Then I took that code and implemented into the larger program causing it to fail :( Well.. I'll remove all the ethernet code again and try to re-implement it step by step.

//Morten