Serial << F

Can anyone please explain the following line of code. Serial << is incomprehensible and cannot be Googled, which suggests it shouldn’t be allowed, but the programme compiles OK so I guess it’s kosher. It occurred to me that it wasn’t written in the Arduino IDE, in which case I would like to re-write it so it looks normal.

    Serial << F("Ethernet started, IP=") << Ethernet.localIP() << endl;

It's just using C++ cout methodology - check any c++ tutorial and you'll see it used to output to the console.

Use Serial.println instead to make it look more like a regular arduino sketch.

Thanks. I will try going through the entire programme.

The snippet you posted is from code that includes a header file that defines a lot of macros and functions that make it look like iostream functions are supported on the Arduino. They aren’t really, and they add a lot of complexity and overhead to the sketch.

Not using them is preferable.

PaulS: Not using them is preferable.

I can believe that. And I have realised that I am just kidding myself with any ideas of a simple re-write of this programme.

And I have realised that I am just kidding myself with any ideas of a simple re-write of this programme.

Why?

Serial << F("Ethernet started, IP=") << Ethernet.localIP() << endl;

becomes:

Serial.print(F("Ethernet started, IP=");
Serial.print(Ethernet.localIP();
Serial.println();

OK, I’ll persevere a bit more. It looks like your conversion should be

   Serial.print(F("Ethernet started, IP="));
   Serial.print(Ethernet.localIP());
   Serial.println();

It looks like your conversion should be

Oops.