Arduino Source codes

Hi all,

I am new to Arduino and using Arduino UNO.
I was working with few example codes given by Arduino and i come to know few functions like digitalWrite, analogWrite, pinMode etc.
I want to know where i can find the source code for this kind of functions.
There is one more thing i am experienced in C language and worked on many controllers and processors, for those i was using main() as a function.
But in Arduino, i experienced new approach which is great i mean something new, but i want to know how actually it is working.
There are no header files define in the blinky example. I want to know how the things are working around Arduino IDE.

Thank You & Regards
Shubham

Windows or Linux?

if Windows, start looking here

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino

and spread out.

The Arduino IDE goes to great lengths trying to hide interesting (but apparently scary) details from fragile newbies. I find it endlessly annoying. All of the source code can be found with diligent searching. A much better method is to use the Sloeber / Eclipse IDE. This allows you to follow function calls to their source code with a simple right-click.

BTW, there is a hidden 'main()' function. It looks like this:

#include <Arduino.h>

// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }

// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }

void setupUSB() __attribute__((weak));
void setupUSB() { }

int main(void)
{
	init();

	initVariant();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

You can also find it on GitHub: ArduinoCore-avr/Arduino.h at master · arduino/ArduinoCore-avr · GitHub

Pieter

DKWatson:
if Windows, start looking here

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino

and spread out.

I didn't find any path you mentioned in my windows. Instead, there is one folder Documents\Arduino
but there is no codes or anything, some json files are there only

The key file to search for is Arduino.h, where you find that you'll find the rest.

On Windows, look in C:\Users(username)\AppData\Local\Arduino15.
There should be a packages or hardware folder.

The easiest way to find the active hardware package location is as follows:

  • Select a board from the hardware package from the Tools > Board menu
  • File > Examples > SPI > BarometricPressureSensor
  • Sketch > Show Sketch Folder
  • Move up folder levels until you reach the one that contains boards.txt

From there, you'll find the core library files under the cores folder (cores/arduino in the case of the Uno).

pert:
The easiest way to find the active hardware package location is as follows:

  • Select a board from the hardware package from the Tools > Board menu
  • File > Examples > SPI > BarometricPressureSensor
  • Sketch > Show Sketch Folder
  • Move up folder levels until you reach the one that contains boards.txt

From there, you'll find the core library files under the cores folder (cores/arduino in the case of the Uno).

Thanks this helps me :slight_smile: