Arduino: Programming Micro-Controllers

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Arduino

Programming Micro-Controllers
http://openhardwareplatform.blogspot.com/2011/03/inside-arduino-build-process.html
Overview

Before we begin it is important to have an understanding of the Arduino
development environment. In general the Arduino version of the Processing IDE
does a number of things that makes it easier to program the Arduino. Arduino's IDE
allows an individual project, or sketch, to contain multiple files. Each of the files
within a sketch is displayed in a separate tab.

Tabs for a file with an extension of .pde have a label that contains the name of the
file without its extension. On the other hand tabs for files with any other extension
are labeled with the entire file name, including the extension.
During the build process the Arduino IDE performs four major tasks:

1. Combine Files: The .pde files are contatinated together.
2. Transformations: Adds function prototypes and #include statement.
3. Compile Code: Each .c and .cpp is compiled into .o files.
4. Linking: The .o files are linked together with library files.
The Arduindo IDE
1. Combine Files

The first step in the build process involves concatenating the .pde files into a
single program. You should keep in mind that when you build a sketch, the
processes are performed against copies of your files that are placed in a
temporary directory. On the other hand when you "Upload" a sketch, the build
process occurs within the applet directory - a subdirectory of the sketch. The
name of the file that is created during the concatenation process is called
{sketchName}.cpp; where {sketchName} is the name of your "primary" .pde file.
2. Transformations

The Arduino environment makes a few alterations, or transformations, to your code
before it is compiled. The only code that is altered during Arduino's preprocessing is
the concatinated version of the .pde files ({sketchName}.cpp). This .cpp file is altered
in two ways. First off Arduino adds the following line of code before the first line of
any of your code, but after any comments:


#include "WProgram.h"


This line of code imports (includes) a header file that contains some key Arduino
definitions and additional includes that make the world of coding for Arduino
hardware much easier.

The final step of the transformation is to append the contents of the main.cxx file for
the current target to the bottom of the {sketchName}.cpp file.
3. Compile Code

Once the build process completes the Combine Files and Transformations steps,
it creates an "includePaths" List that is used for each components it compiles.

The include path for the compilation process will consist of the sketch's directory, the
target directory ({ArduinoPath}\hardware\arduino\cores\arduino), and the AVR include
directory {ArduinoPath}\hardware\tools\avr\avr\include), as well as any libraries
({ArduinoPath}\libraries) referenced in the {sketchName}.cpp file.


The Arduino IDE individually submits each of the .s, .c and .cpp files that are part of the sketch,
including the {sketchName}.cpp file, to AVR-GCC for compilation. The options used by the
Arduino IDE to compile the these .s, .c, and .cpp files are shown below.
.s Files
avr-gcc -c
-g
-assembler-with-cpp
-mmcu={boardPreferences.get("build.mcu")}
-DF_CPU={boardPreferences.get("build.f_cpu")}
-DARDUINO={Base.REVISION}
-I
-o
.c Files
avr-gcc -c
-g
-Os
-w
-ffunction-sections
-fdata-sections
-mmcu={boardPreferences.get("build.mcu")}
-DF_CPU={boardPreferences.get("build.f_cpu")}
-DARDUINO={Base.REVISION}
-I
-o
.cpp Files
avr-gcc -c
-g
-Os
-w
-fno-exceptions
-ffunction-sections
-fdata-sections
-mmcu={boardPreferences.get("build.mcu")}
-DF_CPU={boardPreferences.get("build.f_cpu")}
-DARDUINO={Base.REVISION}
-I
-o
4. Linking

In this context linking is used to describe the process of combining the object and archive
files into a single .hex file. In order to accomplish this the Arduino IDE goes through three
distinctive stages; ELF File Creation, EEP File Creation and HEX File Creation.


ELF File Creation
The bulk of the linking process occurs during the creation of the .elf file. The Arduino IDE
uses AVR-GCC to combine/link the object files and the archive file into a single Executable
and Linkable Format output - .elf file.
avr-gcc -Os
-Wl,--gc-sections
-mmcu={boardPreferences.get("build.mcu")}
-o
-L
-lm
EEP File Creation
The .eep file is created by performing an AVR-OBJCOPY using the afore-
mentioned .elf file as input. The Arduino IDE executes the AVR-OBJCOPY command
using the following program options.








HEX File Creation
The final step the Arduino IDE performs during the build process is to create the .hex
file. This is the file that is passed to AVRDUDE when uploading code to the Arduino
board.
avr-objcopy -O
-R
ihex
-j
.eeprom
--set-section-flags=.eeprom-alloc,load
--no-change-warnings
--change-section-lma
.eeprom=0
avr-objcopy -O
-R
ihex
.eeprom
Conclusion

The Arduino Team did an excellent job creating a user friendly experience. A big part of
that is removing the burden of creating and maintaining makefiles for your embedded
systems work.

The Arduino IDE is well suited for the novice software develop and of course the
hardware platform is a great tool for many fun and exciting hobbyist endeavors. From a
professional perspective the tool does have its short-comings. Overall I enjoy Arduino,
and the team that developed it.
http://openhardwareplatform.blogspot.com/2011/03/inside-arduino-build-process.html
Arduino Project Ideas
let me GOOGLE that for you...
http://www.instructables.com/id/20-Unbelievable-Arduino-Projects/

http://hacknmod.com/hack/top-40-arduino-projects-of-the-web/

http://www.makeuseof.com/tag/8-cool-components-arduino-projects/

http://www.chrismarion.net/index.php?option=com_content&view=article
&id=121:firehero&catid=43:pyrotechnics&Itemid=226
http://www.kickstarter.com/projects/575960623/ardusat-your-arduino-experiment-in-space
Inside ArduSAT
SCIENCE: Meteor Hunter - Small meteors that strike the atmosphere every day created trails of ionized gas in the
atmosphere in the upper atmosphere. Write an experiment to try and detect meteor impacts, by listening for radio
stations beyond the horizon, reflected by the meteor trails!

FINANCE and SECURITY: True Random Number Generator - Cosmic rays are truly random and can be used to
generate a sequence of truly random numbers. These are crucial (and hence valuable) for devising and testing
financial models, secure codes, simulations and other scientific and commercial applications.

ENGINEERING: Your Eye in the Sky - Try writing an app that would synchronize the output of a head mounted-gyro
to the steering system on the satellite. If youre feeling really ambitious, try downlinking the attitude vector in real-
time to watch the satellite follow your head - you could even tie-in your head-steering to our program that takes
pictures! (Talk to Joel if youre interested in this experiment!)

ENGINEERING: Point-and-shoot - The following settings can be set on the camera: "exposure, gamma, gain, white
balance, color matrix, windowing". Try designing an algorithm that fine-tunes the settings to take even better
pictures or more artistic pictures!

ENTERTAINMENT: Geiger Counter Bingo - Write an app that transmits a message with a random number and letter
every time a particle hits the satellite with enough energy. Have a 'bingo from space' game between HAM radio
amateurs.

ENTERTAINMENT: Photography Competition - See who among your friends can snap the coolest/most interesting
picture from space. The eye of a hurricane, sunrise over the Indian ocean, even aurora from space see what
marvels you can capture!
ArduSAT Ideas

You might also like