Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you noted, you check off a board target in the development environment so the compiler might know the board. Unfortunately, the IDE does not tell the compiler this information directly. Only the processor type and frequency are passed down.</p> <p>You can see what the IDE does to compile programs. In the preferences menu, turn on verbose output for compilation. Compile a sketch and you will see something like this:</p> <p><strong>C:\Apps\arduino-1.0-windows\arduino-1.0\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -IC:\Apps\arduino-1.0-windows\arduino-1.0\hardware\arduino\cores\arduino -IC:\Apps\arduino-1.0-windows\arduino-1.0\hardware\arduino\variants\standard C:\Users\Jim\AppData\Local\Temp\build4664216036291565363.tmp\Blink.cpp -oC:\Users\Jim\AppData\Local\Temp\build4664216036291565363.tmp\Blink.cpp.o</strong> </p> <p>The -D 's are how the Arduino environment passes defines to the preprocessor. You see that only the CPU speed and arduino version are passed in this way. </p> <p>The IO pins are defined a different manner: The IDE includes one folder that contains a board specific header file.</p> <p>This -I argument includes a folder onto the compiler's search path:</p> <p><em><strong>-IC:\Apps\arduino-1.0-windows\arduino-1.0\hardware\arduino\variants\standard</em></strong> </p> <p>In that folder is a pins_arduino.h file that is appropriate for the board you selected. If you choose a different board, you will see this parameter change.</p> <p>If you are willing to modify your IDE configuration, you can get what you ask for.</p> <p>So to get what you want, you just need to get one #define directive. So here is how to</p> <p>Step 1. Make your own board type. To make a new board type, see the boards.txt file located in this folder:</p> <p>...\arduino-1.0\hardware\arduino</p> <p>The line like this define the include folder (standard in this case):</p> <pre><code>uno.build.variant=standard </code></pre> <p>Copy an entire block, changing the name and the folder</p> <pre><code>myuno.name=My Arduino Uno ... myuno.build.variant=myunoboard </code></pre> <p>With this change, when you select this board target, the myunoboard folder will be placed on the compiler path.</p> <p>Step 2. Make you header that includes your define.</p> <p>In the folder</p> <p>...\arduino-1.0\hardware\arduino\variants\myunoboard</p> <p>make a file <strong>pins_arduino.h</strong>. In that file</p> <pre><code>#include "..\standard\pins_arduino.h" #define BOARD MY_UNO // and/or this form #define __BOARD_MY_UNO </code></pre> <p>Step 3. Repeat for more boards.</p> <p>This will provide the ability to build your code for different board targets.</p> <p>Having said this, I wouldn't really recommend this approach. If you are starting to think about creating code that runs across multiple targets, it may be time to move on from the Arduino IDE. If you were using an environment such as Eclipse, you have one project with any number of build configurations. Each build configuration can specify different preprocessor defines for the board target.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload