Basic include questions

Hi there,

I have a question regarding includes, it seems quite straight forward but I am having difficulty finding the answer.

I have a UNO R3 and Ethernet Shield and I am using the Arduino IDE version 1.0.3

I have successfully used to example code (http://arduino.cc/en/Reference/ClientConnect) to connect to my server.

I copied and pasted the code into a new project, editing the approparite ip addresses and it worked great.

However, I would like to place this code into a separate ‘my_connection.h’ file.

The problem is that when I include <Ethernet.h> into anything other than the main project file it does not seem to include dependencies - specifically EthernetClient - I get the error: error: ‘EthernetClient’ does not name a type

I believe I am missing some fundamentals about including files.

An example of my code:

project_a.ino:

#include "my_connection.h"

my_connection.h:

#include <Ethernet.h>
EthernetClient client;

The error I get is:

my_connection.h:2: error: 'EthernetClient' does not name a type

And yet when this code is in the main project file (.ino) it works fine?

Many thanks in advance for your assistance, I hope that wasn’t too confusing.

Mike

An annoying little bug with the Arduino IDE seems to be that if you include anything from the standard library into your code files you need the include at the top of both the cpp file and the Arduino sketch file (ino).

Ah ok, that is quite annoying! Thanks for the quick response!