7

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?

  • 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? – Azrael93 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
3

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

  • 1
    you should be able to find and reflash the bootloader for the arduino look here arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader – Treesrule14 Sep 30 '14 at 15:37
  • 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 1 '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 1 '14 at 15:07
  • @ChrisStratton since you disagree with the other answers Submit an Answer please – Treesrule14 Oct 1 '14 at 18:42
2

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.

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.

  • Another common misconception is that C is a subset of C++. Arduino core library is written in C++, so it's impossible to program in C using it. – Dmitry Grigoryev Jun 26 '18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.