How To Use Dev-c++ With Arduino

Mar 29, 2011 This post is part of a series about programming Arduino applications in C. I like playing with my Arduino Uno board and its graphical development environment. It’s a tool that makes it easy to create programs and hides many details, but that leaves me wanting to look beneath, to understand the details that are normally hidden.

The essential tools needed to follow these tutorials are a computer and a compiler toolchain able to compile C++ code and build the programs to run on it.
C++ is a language that has evolved much over the years, and these tutorials explain many features added recently to the language. Therefore, in order to properly follow the tutorials, a recent compiler is needed. It shall support (even if only partially) the features introduced by the 2011 standard.
Many compiler vendors support the new features at different degrees. See the bottom of this page for some compilers that are known to support the features needed. Some of them are free!
If for some reason, you need to use some older compiler, you can access an older version of these tutorials here (no longer updated).

What is a compiler?

Computers understand only one language and that language consists of sets of instructions made of ones and zeros. This computer language is appropriately called machine language.
A single instruction to a computer could look like this:
0000010011110

ArduinoA particular computer's machine language program that allows a user to input two numbers, adds the two numbers together, and displays the total could include these machine code instructions:
0000010011110
0000111110100
0001010011110
0001111010100
0010010111111
0010100000000

As you can imagine, programming a computer directly in machine language using only ones and zeros is very tedious and error prone. To make programming easier, high level languages have been developed. High level programs also make it easier for programmers to inspect and understand each other's programs easier.
This is a portion of code written in C++ that accomplishes the exact same purpose:
Even if you cannot really understand the code above, you should be able to appreciate how much easier it will be to program in the C++ language as opposed to machine language.
Because a computer can only understand machine language and humans wish to write in high level languages high level languages have to be re-written (translated) into machine language at some point. This is done by special programs called compilers, interpreters, or assemblers that are built into the various programming applications.

How To Use Dev-c With Arduino Download


C++ is designed to be a compiled language, meaning that it is generally translated into machine language that can be understood directly by the system, making the generated program highly efficient. For that, a set of tools are needed, known as the development toolchain, whose core are a compiler and its linker.

How To Use Dev-c With Arduino Without



Console programs

Console programs are programs that use text to communicate with the user and the environment, such as printing text to the screen or reading input from a keyboard.
Console programs are easy to interact with, and generally have a predictable behavior that is identical across all platforms. They are also simple to implement and thus are very useful to learn the basics of a programming language: The examples in these tutorials are all console programs.
The way to compile console programs depends on the particular tool you are using.
The easiest way for beginners to compile C++ programs is by using an Integrated Development Environment (IDE). An IDE generally integrates several development tools, including a text editor and tools to compile programs directly from it.
Here you have instructions on how to compile and run console programs using different free Integrated Development Interfaces (IDEs):
IDEPlatformConsole programs
Code::blocksWindows/Linux/MacOSCompile console programs using Code::blocks
Visual Studio ExpressWindowsCompile console programs using VS Express 2013
Dev-C++WindowsCompile console programs using Dev-C++

If you happen to have a Linux or Mac environment with development features, you should be able to compile any of the examples directly from a terminal just by including C++11 flags in the command for the compiler:
CompilerPlatformCommand
GCCLinux, among others...g++ -std=c++0x example.cpp -o example_program
ClangOS X, among others...clang++ -std=c++11 -stdlib=libc++ example.cpp -o example_program

Index
Next:
Structure of a program

How To Use Dev-c With Arduino File

Dev-C++ is a free IDE for Windows that uses either MinGW or TDM-GCC as underlying compiler.
Originally released by Bloodshed Software, but abandoned in 2006, it has recently been forked by Orwell, including a choice of more recent compilers. It can be downloaded from:
http://orwelldevcpp.blogspot.com

Installation

Run the downloaded executable file, and follow its instructions. The default options are fine.

Support for C++11

By default, support for the most recent version of C++ is not enabled. It shall be explicitly enabled by going to:
Tools -> Compiler Options
Here, select the 'Settings' tab, and within it, the 'Code Generation' tab. There, in 'Language standard (-std)' select 'ISO C++ 11':
Ok that. You are now ready to compile C++11!

Compiling console applications

To compile and run simple console applications such as those used as examples in these tutorials it is enough with opening the file with Dev-C++ and hit F11.
As an example, try:
File -> New -> Source File (or Ctrl+N)
There, write the following:
Then:
File -> Save As... (or Ctrl+Alt+S)
And save it with some file name with a .cpp extension, such as example.cpp.
Now, hitting F11 should compile and run the program.
If you get an error on the type of x, the compiler does not understand the new meaning given to auto since C++11. Please, make sure you downloaded the latest version as linked above, and that you enabled the compiler options to compile C++11 as described above.

Tutorial

You are now ready to begin the language tutorial: click here!.