Arduino "core" and other libraries

I'm trying to understand where all the code comes from that Arduino compiles. I may have some preconceived notions about how it all ties together.

First, let me say, I know what directives are. I know what include does. I can write my own classes, structures etc. I know that in order to use certain functions and classes the correct h file must be included. I know where the core h/cpp files are located.

What I don't understand is why there are some classes like Serial which do not require an include directive to work. I assume that Serial is part of the "core" and it's being told somewhere outside the sketch, to be included. But, I can't find the class in the cores folder. So...

  1. Is the Serial class in a text file (h/cpp) somewhere or is it already precompiled in a dll somewhere or?

  2. Is Serial considered part of the "core?" I ask because I can't find it in any of the files in the cores folder.

I'm still very much a beginner, or occasional dabbler with Arduino. One of my first observations, is that in making things simple for absolute noobs, the ide does some things "under the covers" that can cause a great deal of head scratching.

Perhaps being a tiny bit further down that road, I can tell you that the ide does not compile your .ino file, at least not directly - it creates a .cpp file from it and compiles that. On my windows system that .cpp file, together with a whole lot of other files, is located in
C:\Users\ozcar\AppData\Local\Temp\build-some-great-long-name.tmp\
but your mileage, or location, may vary.

If I look at one of those generated .cpp files, I can see lines from my .ino file, but I also see a line
#include "Arduino.h"
That might be a part the answer you are looking for.

I also note some other additions to the .cpp file, like a whole bunch of "forward" declarations for functions defined in the .ino as well as #line directives.

AVR-GCC -- find the standard lib reference here

And there's Java code. Serial is written in Java. The complete sources are with the IDE.

Arduino Foundations page answers many questions.

Start there and explore what has been given.

Serial is not a class. It is an instance of a class!

Mark

chipwitch:

  1. Is the Serial class in a text file (h/cpp) somewhere or is it already precompiled in a dll somewhere or?

  2. Is Serial considered part of the "core?" I ask because I can't find it in any of the files in the cores folder.

Look again at how Serial is used - it is NOT a class, but an instance of a class. What class, depends on which board you're running on. On some boards, probably most, it will be an instance of HardwareSerial, on other boards (Leonardo, Due, etcl) it will be an instance of SerialUSB, or some other class. All they have in common is all inherit from the Stream class.

Regards,
Ray L.

Remember, that the IDE coalesces and munges your code. One of the things it adds is an arduino.h include which contains all the arduino stuff.

UART Serial instances are declared here...
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.h#L141-L158

That header is included in your sketch from Arduino.h here...
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Arduino.h#L224

Both of those files, and all the necessary dot-cpp files, are somewhere on your computer.

Great! I see it instatiated in the header file. Thank you. Serial then, is a HardwareSerial object.

Everyone, thanks for all the suggestions.

Serial then, is a HardwareSerial object.

NO. Most often it is but it could be other thing such as USBHardwareSerial or something I will write next week if I'm in the mood!

Mark

GoForSmoke:
...
And there's Java code. Serial is written in Java. The complete sources are with the IDE.
...

On the arduino?

No. In the IDE that compiles the hex file that is loaded on the Arduino.

Back a ways I wanted to add a function to the serial class and found the source for That was Java.