Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is programming an Arduino different than standard C?

Tags:

c++

c

arduino

I have a background in programming embedded systems (TI MSP430, Atmel ATxmega). How is programming an Arduino different than those? What knowledge about C can I take in to programming the Arduino?

like image 398
Nathan Avatar asked May 09 '11 01:05

Nathan


People also ask

How is programming Arduino different from C?

The main difference would be the file associations. An Arduino Sketch is associated to the Arduino IDE, which is basically a C/C++ compiler that generates machinecode for the Arduino boards. The C and CPP files would be associated to your regular IDE or compiler or perhaps even Notepad if you've set it up that way.

Is Arduino C different from C?

The Arduino language is a subset of C/C++, where you can also use assembly for ultra-low level code. When saying “programming on Arduino”, in fact you don't program the Arduino board itself, but the microcontroller inside the board. For example, the Arduino Uno has a AtMega328p microcontroller.

Can I program Arduino with C?

yes, we can program arduino board with the Processing IDE instead of Arduino IDE. Arduino is fundamentally a C/C++ environment, while Processing's underlying language is Java.

Is Arduino easier than C?

You can take your existing C knowledge when using Arduino. The purpose was to allow artists/non-programmers to get started easily with hardware programming and tinkering, so the 'Arduino language' is just a wrapper to simplify development. It should be a lot easier for you, as a C programmer to use Arduino.


1 Answers

While I don't know about the ATXMega, the 8-bit AVR chips like the ATmega328 used on the newer Arduinos use the AVR-GCC compiler. This allows for compiling C and even C++ to an AVR chip. One level above the AVR-GCC is the AVR Libc, a C library that makes programming for the AVR a higher level task (no longer have to refer to registers directly, and so on).

The Arduino IDE uses AVR-GCC and AVR libc library in the backend. In addition, the Arduino IDE makes other libraries available, like a nice Serial interface.

Finally, the Arduino comes with a bootloader burned on the AVR chip. The bootloader simply makes it possible to program the AVR using a serial connection (from USB) instead of an In-Sytem Programmer or Development Board.

Enough backstory, to answer your question: The Arduino can be programmed in C and even C++. The libraries available are written in C and everything will compiled using AVR-GCC. The Arduino IDE isn't even required.

Edit

There seems to be a decent amount of interest in this topic. I wrote a blog post to try and give more in-depth details on the AVR, Arduino, and AVR-GCC.

like image 145
baalexander Avatar answered Sep 28 '22 05:09

baalexander