2

From what i've researched here is my thoughts on both

  1. C++ I heard that you can create libraries using C++ in arduino. And you can use the Arduino IDE to do that stuff. Here is the proof

http://arduino.cc/en/Hacking/LibraryTutorial

Notice that it uses the C++ syntax.

I also see arduino projects on github written on C++ https://github.com/search?l=C%2B%2B&q=Arduino&type=Repositories&utf8=%E2%9C%93

  1. C

I heard that you can use AVR GCC and code it without the arduino ide. And I heard it's much faster than the arduino language because it's more closer to the metal. But I think it's harder to set up because you need a programmer into the Atmel chip, which is much more costlier compared to directly plugging in the arduino using the USB to printer cable. And you also need to download a bunch of stuff to get coding in pure avr gcc (win-Avr GCC, atmel studio etc.).

Which one should i learn C or C++? I prefer the easy to debug route. Or is it beneficial if i learn both?

5

The basic syntax of C and C++ is very similar, to the point that C code can typically be compiled directly as C++. You'll also find C standard functions (such as printf and malloc) can be used from C++ programs.

The major difference in the core language is that C++ has a lot of extra stuff such as classes and templates. Conventionally, C++ also has a huge standard library which doesn't work on C. However, that's not usually available (nor really appropriate) for Arduino programming, so you don't need to worry too much about it unless you migrate to e.g. desktop programming.

Basically, it's probably sensible to learn C first, because the same knowledge works in C++. You can then move on to the C++-specific stuff, such as classes.

As a side note, the Gnu Compiler Collection (GCC) actually covers both C and C++. It's what the Arduino IDE at Atmel Studio use under-the-hood for all their compilation. It's even possible to work directly with GCC but still upload programs to Arduino via USB.

It's also worth noting that programs compiled within the Arduino IDE aren't necessarily going to run any slower than programs compiled some other way (whether C or C++). The main difference is whether or not you use the Arduino functions. Since they are general purpose, they're not necessarily doing things the most optimal way. You could get more efficiency in theory by manipulating the microcontroller's special registers directly, which is you can do from within the Arduino IDE as well. It's usually very tricky for a beginner though, so it's probably not something you want to attempt until you're more comfortable with C/C++.

  • Granted, as you said it's mostly unrelated to embedded programming, but I'm not sure I'd use the word 'huge' to describe the C++ standard library. Sure, it's a covers a lot more ground than the C standard library, but compared to virtually any other popular programming language, it's quite spartan. – bcrist Feb 14 '15 at 21:19
3

Arduino supports c++, but does not support many of the standard libraries. The vast bulk of the functions in the Arduino IDE are c functions.

You can do almost everything in c, except for a few advanced items.

Due to the limited c++ libraries it will be difficult to learn c++ on Arduino; indeed it is not the ideal platform to learn c, as most of the tutorials will not work (because there is no I/O on Arduino).

  • Several standard Arduino libs are C++, the first that comes to mind is Serial, but there are others! – jfpoilpret Feb 14 '15 at 13:57
  • @jfpoilpret I never said the libraries were not c++, but all the advertised functions are callable in c. This is a question by a beginner who is unlikely to be overriding the serial class (or any other). – Milliways Feb 14 '15 at 21:59
1

@ConnorWolf Way too kind.

Arduino is based on Wiring, which is based on Processing, which is a kludge of Java, resembling C++ running on an embedded prototyping platform ill suited for learning programming by any Definition. Many libraries half written and confusing, implementing only as much as the original author needed, not the entire spec (SPI being a great example).

Get a Pi for the same price, at least it is an end user computer for poor people.

Besides, if you have something that can run the Ardunino IDE why are you learning to program on an Arduino? You need to be proficient in C or C++ before you attempt anything for real on an Arduino. Blinking lights is fine, beyond that, good luck.

Learn C or C++ (preferred as it is newer) on what you have, then start using the Arduino. Eclipse or Microsoft Visual Studio Community are both free and support both languages. (Both also support Arduino development when the time comes, avoid the Arduino IDE it is terrible). There are enough samples for either to keep you busy for a long time. Embedded programming REQUIRES understanding of low level hardware and IS NOT suitable for learning.

Forget modern debugging. Paid engineers grumble when they have to do it and it cost a decent price for the enabling hardware. Stick to the old fashioned printf debugging style.

  • It's perhaps slightly confusing to say C++ is 'newer'. It was certainly invented more recently, but both languages are still being maintained/updated. – Peter Bloomfield Feb 18 '15 at 9:17
0

For starting out? I would say neither. The arduino IDE is based on a programming language called processing. Which you can look at. Honestly, if you have done any programming in the past you will be fine for the basics. The advanced stuff might make you look at working with c++ files. But there is nothinging overly complex there. A lot of the add-on hardware that you can purchase comes with existing arduino libraries. Use these as a baseline.

  • 1
    The arduino text-editor uses C(++). "Processing" is a horrible abortion of a wrapper on Java (it's still java, just much worse). None of this is original, and there are no new languages involved. – Connor Wolf Feb 17 '15 at 22:07

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.