Show minor edits - Show changes to markup
First, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.
First, #include "Arduino.h", or for versions less than 1.0, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.
First, any #include statements in the main sketch file are moved to the top of the code. Then #include "WProgram.h" is added to the above them. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to the top of your sketch. Note that these prototypes will appear before any type declarations or #include statements in your code, meaning that they cannot contain references to custom types.
First, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted after any comments or pre-processor statements (#includes or #defines), but before any other statements (including type declarations). This means that if you want to use a custom type as a function argument, you should declare it within a separate header file. Also, this generation isn't perfect: it won't create prototypes for functions that have default argument values, or which are declared within a namespace or class.
The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:
The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:
First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to your sketch.
First, any #include statements in the main sketch file are moved to the top of the code. Then #include "WProgram.h" is added to the above them. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to the top of your sketch. Note that these prototypes will appear before any type declarations or #include statements in your code, meaning that they cannot contain references to custom types.
First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/lib/targets/<TARGET>/) includes all the header files needed for the standard Arduino core.
First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.
Finally, as of Arduino 0008, the contents of the current target's main.cxx file are appended to the bottom of your sketch.
Finally, the contents of the current target's main.cxx file are appended to the bottom of your sketch.
The Arduino environment supports multiple target boards with different chips (currently, only AVRs) or CPU speeds. To configure it for a target, you need to edit the main Arduino preferences file. Relevant variables include:
The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:
<BOARD>.name: the name to display in the Boards menu
<BOARD>.build.mcu: the microcontroller on the board (normally "atmega8" or "atmega168").
<BOARD>.f_cpu: the clock speed at which the microcontroller operates (normally "16000000L", or, for an ATmega168 running on its internal clock, "8000000L").
<BOARD>.core: which sub-directory of the hardware/cores/ directory to link sketches against (normally "arduino").
Also useful is this setting in the main preferences.txt file:
build.target: a sub-directory of <ARDUINO>/lib/targets/ (e.g. "arduino") - sketches will be linked against all .c/.cpp/.o files in this directory.
build.mcu: the microcontroller (e.g. "atmega8").
build.f_cpu: the clock speed (e.g. "16000000L"). Used to define the F_CPU constant when compiling.
The include path includes the sketch's directory, the target directory (<ARDUINO>/lib/targets/<TARGET>/) and the avr include directory (<ARDUINO>/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/lib/targets/libraries/) which contain a header file which is included by the main sketch file.
The include path includes the sketch's directory, the target directory (<ARDUINO>/hardware/core/<CORE>/) and the avr include directory (<ARDUINO>/hardware/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/hardware/libraries/) which contain a header file which is included by the main sketch file.
As of Arduino 0008, these .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.
These .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.
Sketches are uploaded by uisp. The upload process is also controlled by variables in the preferences file. These include:
Sketches are uploaded by avrdude.
The upload process is also controlled by variables in the boards and main preferences files. Those in the boards file include:
<BOARD>.upload.protocol: the protocol that avrdude should use to talk to the board (typically "stk500").
<BOARD>.upload.speed: the speed (baud rate) avrdude should use when uploading sketches (typically "19200").
<BOARD>.upload.maximum_size: the maximum size for a sketch on the board (dependent on the chip and the size of the bootloader).
And in the main preferences file:
upload.programmer: the protocol used for upload. the bootloader on the Arduino board uses "stk500", but some external programmers may use others.
upload.erase: whether or not to erase the board before uploading. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.
upload.verify: whether or not to verify the success of the upload. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.
upload.maximum_size: the maximum size of the compiled sketch in bytes; anything bigger will result in an error when you attempt to upload. On the Arduino board, this is 7168 as the ATmega8 has 8 Kb of program space, with 1 Kb taken by the bootloader. If using another chip or an external programmer (and thus, no bootloader), you'll want to adjust this accordingly.
serial.download_rate: the baud rate at which programs are upload. Should be "19200" on current Arduino boards; some older boards use "9600". Should be "115200" for an external AVR-ISP.
The actual command line call to uisp might end up looking something like this:
tools/avr/bin/uisp -dpart=atmega8 -dprog=stk500 -dserial=/dev/cu.usbserial-A1000fKl -dspeed=19200 --upload if=/Users/dmellis/Documents/Arduino/led_blink/applet/led_blink.hex
You'll need to create a blank target. Make a directory called "blank" in <ARDUINO>/lib/targets/. Create a blank file called "WProgram.h". You may need to put the .c or .cpp file in an auxilary tab of your sketch (leaving the primary tab blank). You won't be able to use any of the Arduino functions unless you copy the corresponding files from <ARDUINO>/lib/targets/arduino.
The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or ... (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).
The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or \Documents and Settings\<USER>\Local Settings\Temp (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).
The .hex file is the final output of the compilation which is then uploaded to the board.
The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or ... (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).
Finally, as of Arduino 0008, the contents of the current target's main.cxx file are appended to the bottom of your sketch.
As of Arduino 0008, these .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.
Warning: this may all change in future releases of Arduino.
build.verbose: whether or not to print debugging messages while building a sketch (e.g. "false"). If true, will print the complete command line of each external command executed as part of the build process.
upload.verbose: whether or not to dump debugging messages while upload a sketch to a board (defaults to "false").
Warning: this may all change in future releases of Arduino.
A number of things have to happen for your Arduino code to get onto the Arduino board. First, the Arduino environment performs some small transformations to make sure that the code is correct C or C++ (two common programming languages). It then gets passed to a compiler (avr-gcc), which turns the human readable code into machine readable instructions (or object files). Then, your code gets combined with (linked against), the standard Arduino libraries that provide basic functions like digitalWrite() or Serial.print(). The result is a single Intel hex file, which contains the specific bytes that need to be written to the program memory of the chip on the Arduino board. This file is then uploaded to the board: transmitted over the USB or serial connection via the bootloader already on the chip or with external programming hardware.
A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the "main sketch file". Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using "double quotes" not <angle brackets>).
The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.
First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/lib/targets/<TARGET>/) includes all the header files needed for the standard Arduino core.
Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to your sketch.
The Arduino environment supports multiple target boards with different chips (currently, only AVRs) or CPU speeds. To configure it for a target, you need to edit the main Arduino preferences file. Relevant variables include:
build.target: a sub-directory of <ARDUINO>/lib/targets/ (e.g. "arduino") - sketches will be linked against all .c/.cpp/.o files in this directory.
build.mcu: the microcontroller (e.g. "atmega8").
build.f_cpu: the clock speed (e.g. "16000000L"). Used to define the F_CPU constant when compiling.
Note: that in Arduino 0004 and later, build.extension is unused - the main sketch file is always treated as a .cpp file.
Sketches are compiled by avr-gcc.
The include path includes the sketch's directory, the target directory (<ARDUINO>/lib/targets/<TARGET>/) and the avr include directory (<ARDUINO>/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/lib/targets/libraries/) which contain a header file which is included by the main sketch file.
When you verify a sketch, it is built in a temporary directory in the system temp directory (e.g. /tmp on the Mac). When you upload it, it is built in the applet/ subdirectory of the sketch's directory (which you can access with the "Show Sketch Folder" item in the "Sketch" menu).
The .c and .cpp files of the target are compiled and output with .o extensions to this directory, as is the main sketch file and any other .c or .cpp files in the sketch and any .c or .cpp files in any libraries which are #included in the sketch.
The .hex file is the final output of the compilation which is then uploaded to the board.
Sketches are uploaded by uisp. The upload process is also controlled by variables in the preferences file. These include:
upload.programmer: the protocol used for upload. the bootloader on the Arduino board uses "stk500", but some external programmers may use others.
upload.erase: whether or not to erase the board before uploading. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.
upload.verify: whether or not to verify the success of the upload. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.
upload.maximum_size: the maximum size of the compiled sketch in bytes; anything bigger will result in an error when you attempt to upload. On the Arduino board, this is 7168 as the ATmega8 has 8 Kb of program space, with 1 Kb taken by the bootloader. If using another chip or an external programmer (and thus, no bootloader), you'll want to adjust this accordingly.
serial.download_rate: the baud rate at which programs are upload. Should be "19200" on current Arduino boards; some older boards use "9600". Should be "115200" for an external AVR-ISP.
The actual command line call to uisp might end up looking something like this:
tools/avr/bin/uisp -dpart=atmega8 -dprog=stk500 -dserial=/dev/cu.usbserial-A1000fKl -dspeed=19200 --upload if=/Users/dmellis/Documents/Arduino/led_blink/applet/led_blink.hex
You'll need to create a blank target. Make a directory called "blank" in <ARDUINO>/lib/targets/. Create a blank file called "WProgram.h". You may need to put the .c or .cpp file in an auxilary tab of your sketch (leaving the primary tab blank). You won't be able to use any of the Arduino functions unless you copy the corresponding files from <ARDUINO>/lib/targets/arduino.