3
\$\begingroup\$

I am venturing into Arduino programming. I have done a lot of programming with the PIC using assembly language, but I don't know C or C++. What would be the best way to get started with learning C++? Are there tutorials geared towards micro processors or do I simply learn C++ in general. I have searched for tutorials specifically for Arduino only to find syntax examples but nothing specific to C++. Can anyone recommend a tutorial link, or their favorite book?

\$\endgroup\$
6
\$\begingroup\$

According to my limited knowledge (I'm neither a C- nor C++ expert), the C++ for the Arduino (aka AVR processors) is only a subset of the "normal" C++. For example, you can't create objects dynamically. Hence, the C++ for Arduino is rather a C with a few C++ goodies (e.g. structs with methods) which help to limit variable scopes.

\$\endgroup\$
4
\$\begingroup\$

There aren't many (official) C++ implementations for 8-bit microcontrollers; C++ is rather resource-intensive; your \$\mu\$C might not have enough Flash and/or RAM. 8-bit \$\mu\$Cs are usually programmed in plain C.
Since you know neither C nor C++, I would start with C. It's not difficult if you don't make it difficult for yourself. (It's perfectly possible to write completely unreadable code in C.)

For one project my "softie" colleagues wanted to use OOP (on an HC08), but found that indeed it didn't have enough resources. So they wrote everything in C, but in their development process they created a kind of object model which in the end looked very much like C++ :-). Result: due to ever increasing resources (esp. RAM) us hardware boys had to switch from an 8-bitter to a 32-bit ARM (LPC2148).

\$\endgroup\$
  • 1
    \$\begingroup\$ @stevenvh- All the examples I've seen for the Arduino are in C++. If there was an assembly language for it, I would prefer to learn it so that I don't have to deal with the timing and other things that go with higher language problems. \$\endgroup\$ – SteveR Jul 9 '11 at 17:39
  • \$\begingroup\$ @Steve - well, that certainly contradicts my claims :-/. Assembler on the Arduino should be possible (at least I hope I'm right on this!), GIYF. \$\endgroup\$ – stevenvh Jul 9 '11 at 17:46
  • 1
    \$\begingroup\$ @Steve this old page has some good info on assembly with arduino \$\endgroup\$ – NickHalden Jul 10 '11 at 20:28
  • 1
    \$\begingroup\$ dwelch.com/arduino assembler on arduino is certainly possible. \$\endgroup\$ – old_timer Jul 10 '11 at 23:33
  • 1
    \$\begingroup\$ @Steve R, I find it hard to believe that all the Ardruino examples in C++. Ardruino is based upon a Atmel AVR micro, as such the language of choice is C (for high level language) and assembler (for low level language). Having said that, C++ is possible, but not as popular. I tend to agree with @stevenvh on the resource intensive nature of C++ vs C on a small micro like the Atmel AVRs. \$\endgroup\$ – tehnyit Jul 11 '11 at 8:49
1
\$\begingroup\$

If you know Java, or any other object oriented language, you basically know C++. I am a beginner myself, but for easy arduino projects, you pretty much only use loops and arrays.
If you want to get fancy, you can use libraries Arduino and others have created for more advanced projects

\$\endgroup\$
  • \$\begingroup\$ That is interesting. I do know Visual Basic. \$\endgroup\$ – SteveR Jul 9 '11 at 17:40
  • 6
    \$\begingroup\$ If you think knowing Java means you know C++, you don't know C++. On the other hand, the 10% of C++ used in the Arduino code is fairly simple and (despite no dynamic creation of objects - i.e. no new which is the only way of creating objects in Java) fairly the 'C with classes' approach which Java tried to go back to from modern C++. \$\endgroup\$ – Pete Kirkham Jul 10 '11 at 10:24
  • 1
    \$\begingroup\$ @Pete - excellent comment. There is a widespread misconception that "if you know Java, you know C++" - or "if you know C, you basically know C++" - again, untrue. Just search for the phrase "C/C++" and you'll see how many people lump the 2 languages into the same bucket. And now with C++0x, the languages have even less overlap. \$\endgroup\$ – Radian Jul 10 '11 at 17:42
  • \$\begingroup\$ @Pete - Sorry, I just meant they are very similar in their syntax, and it can be easy to go from one language to the other. Didn't mean to confuse. \$\endgroup\$ – Shubham Jul 10 '11 at 17:53
  • \$\begingroup\$ @Shubham, no they aren't similar on no account. C++ is a multiparadigm language above all. \$\endgroup\$ – Özgür Sep 18 '11 at 8:16

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.