10

I am a beginner and I want to learn AVR C/C++. Can I do this using an Arduino? (I'm asking this because I already have one).

If so, could someone tell me using which IDE can I write code in pure C/C++ and then flash it to the Atmega328P on the Arduino? Or, should I get an AVR and a programmer instead?

I've searched all over the internet and I'm really confused by all the terminology. Could someone explain it to me?

sa_leinad
  • 3,118
  • 1
  • 20
  • 49
ICRed
  • 101
  • 1
  • 1
  • 3
  • 1
    So in order to program the 328 I believe you need to install atmel studio to compile your code and then use the command line command avrdude to put your compiled code onto the arduino. – Treesrule14 Sep 30 '14 at 14:34
  • @Treesrule14 that's a possibility, but not the only one, so it's untrue to say that it is necessary. If the Arduino IDE is installed, then so is the avr-gcc compiler on which it depends. – Chris Stratton Sep 30 '14 at 14:42
  • @Treesrule14 I have the atmel studio installed. I just cannot find any resources that might help me flash a program to the chip on the arduino using a bootloader (without a programmer). Is this even possible? – ICRed Sep 30 '14 at 15:00
  • I believe you need a programmer. : ( – Treesrule14 Sep 30 '14 at 15:39
  • 2
    You don't need any IDE. You can compile and upload using the toolchain that comes with Arduino. Look at Arduino.mk for example. – hobbs Sep 30 '14 at 22:10
  • @Treesrule14 - wrong again, you do not need a programmer. Avrdude will talk to the bootloader on the arduino just as readily to upload a hex file compiled from a stand alone C program as it will to upload one built by the Arduino IDE. – Chris Stratton Oct 01 '14 at 14:42
  • @ChrisStratton totally didn't see your first post sorry about that. Have you tried programming with avr-gcc over usb? – Treesrule14 Oct 01 '14 at 18:40
  • avr-gcc is a compiler, not a download tool. But anyone who has every used to the Arduino IDE with a USB-connected arduino has done so, yes. And I and many others have done it with plain C programs built from the command line with avr-gcc and flashed from the command line with avrdude (which is, after all, what the Arduino IDE quietly does on behalf of its user). There are many writeups online, it's a task beyond trivial summary in an SO answer. – Chris Stratton Oct 01 '14 at 19:36

3 Answers3

4

Yes, get an AVR programmer instead.

1) You can flash your arduino board with avrdude/avr-gcc. Install these tools, find the datasheet of atmega328 (google it), use the board pinouts to connect to your programmer (stk500v2/ISP) and voila!

2) Keep in mind that by "manually" flashing your atmaga on arduino board you're removing bootloader that is needed to load your sketches from ARDUINO IDE.

3) Use your favourite C/C++ IDE

soerium
  • 159
  • 3
  • 1
    you should be able to find and reflash the bootloader for the arduino look here http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader – Treesrule14 Sep 30 '14 at 15:37
  • 2
    No! You do not need a programmer, or to remove the bootloader. The Arduino bootloader has zero dependence to the IDE or libraries - you are every bit as free to use it with stand alone C programs as with Arduino sketches. Doing it that way is not only cheaper, but lets you use the same board for both styles of development with no configuration changes. – Chris Stratton Oct 01 '14 at 14:44
  • The author wanted to learn AVR in pure C. He didn't ask - hey guys, how to play with arduino IDE or someth. but how to reuse the atmega on board he already has. – soerium Oct 01 '14 at 15:07
  • @ChrisStratton since you disagree with the other answers Submit an Answer please – Treesrule14 Oct 01 '14 at 18:42
3

If you're a beginner, I suggest you write C in the Arduino IDE. The libraries are very useful and I think the Arduino/Wiring/Processing environment will cover all your needs.

Check out the Lightblue Bean (http://punchthrough.com/bean/) it is a good example of the power of that platform. Even experienced embedded programmers can use it, since the underlying register are still accessible.

I am now programming on the Ti MSP430, and while I can appreciate the possibilities, I miss the simplicity of Arduino; much easier to get started with Arduino.

Go to http://arduino.cc/en/main/software to download the 1.0.6. IDE software, plug your Arduino, go to Tools->Board to select your Arduino, select the appropriate "tty" port in the Tools->Serial_Port. Then write in pure C and download. There are tons of examples included with the IDE.

sachleen
  • 7,365
  • 4
  • 37
  • 55
albator
  • 109
  • 2
2

An Arduino is programmed in C/C++. There is a common misconception that Arduino has its own language. See this link C++ vs. The Arduino Language? for a full discussion on Arduino being C/C++ and the simplifications Arduino offers. Further more, you can see the Arduino core code here.

From the Arduino website:

Can I program the Arduino board in C?
In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process.

Arduino offers an easy learning curve for beginners through to experts. So simply download the latest Arduino IDE, install it and enjoy.

radioxoma
  • 105
  • 3
sa_leinad
  • 3,118
  • 1
  • 20
  • 49