Pages: [1]   Go Down
Author Topic: Advice needed re: learning C++  (Read 3152 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are good references/tutorials/books on C++, especially as used for programming AVRs and other MCUs?

I'm pretty new at this language and find it a little cryptic at times...

I program VB/VBA, and I am an EE by trade.  I know electronics and RF, now need a supplement of C++.

Suggestions appreciated.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just do it!  Best way to learn.  I am an EE also. Can be ugly code at times, gets  better as you go. I look at stuff I wrote in August when I started vs now, huge difference.
Start with some simple stuff, and build up.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Just do it!"  Yes, that's my usual approach...

I've been able to get a lot of the small stuff and concepts down, my project now is a PID temp controller for a kiln...so I am finding out I need to know a whole lot more about C++!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rather then reading reference manuals, I found I was picking up C/C++ faster by just reading as many of the existing example sketches as possible. Many are very simple and great for first learning, later one can even open up and read the many arduino 'core' library files to see how low level programming is used to manipulate the AVRs many registers. Make no mistake, C/C++ can be a write only language if the programmer wants to be very terse and obscure on how they perform tasks, but it's also possible to write and understand very simple and clear functions, the Arduino platform was based on developing easy to use and understand functions like digitalRead(pin#); rather then the low level commands needed to read a I/O port register and pick out the bit of interest.

 With your background you will have little problem picking it up. And the AVR type applications are so down to earth most times, you don't get burdened by having to understand all the Windows API before you can even start writing simple programs.

Good luck and enjoy your Arduino, better then sliced bread.

Lefty
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could try the PID libary
http://www.arduino.cc/playground/Code/PIDLibrary

I have started converting the sparkfun PIC C code for their oven controller into something arduino based. Sounds like a good application for PID also.
Was going well until I got to the display, then I got a little sidetracked, and we bought some furniture so we spent the last couple nights cleaning up the living room, so I need to get back on track with that.


"better then sliced bread" and like sliced bread, younger than Hugh Hefner smiley-cool
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If I had some time, I would learn the language, which is totally different from using it for MCU. That would be like learning French and working in a French restaurant. You learn the language first, then use the language to do stuff or learn more things. I suggest C++ from the ground up by Herb Schildt. You're EE so you will appreciate his clarity and logic in his book. MCU can be programmed in a number of languages besides C.
Logged


Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4092
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I learned plain ol' C first, I think Kernighan & Ritchie is just about as well-written and concise a book can be.

I'm fairly new to C++, but know a bit of other OO stuff, so feeling my way along in the dark so far hasn't been too bad.  My daughter tells me that Stroustrup's is one of the go-to books for C++, will no doubt pick it up when I have time.

A whole lot can be done with Arduino without having to develop classes, etc.
« Last Edit: August 19, 2011, 01:19:17 pm by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can certainly feel your way with C++, especially because arduino has no multi-tasking so resources are all available to the code for that matter. I only need to write constructor but no need for copy constructor or destructor, which are there specifically to deal with resource allocation and release. You also don't do lots of polymorphism except for just compiler lever. There's not much memory for that either. So it boils down to me that encapsulation was most important and not much inheritance. So a quick dip into C++ can get you started, only if you already know C.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Reminds me of a Farside cartoon:
What software engineers say "I only need to write constructor but no need for copy constructor or destructor, which are there specifically to deal with resource allocation and release. You also don't do lots of polymorphism except for just compiler lever. There's not much memory for that either. So it boils down to me that encapsulation was most important and not much inheritance. "

What hardware engineers hear "You can certainly feel your way with C++, ... only if you already know C"  smiley-wink smiley-cool
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So a quick dip into C++ can get you started, only if you already know C.

Well one fallout of the Arduino's popularity, for good or bad, is that there is and will continue to be thousands and thousands of new people learning to program their Arduino boards and not knowing what parts they are learning are C and what parts are C++.  Not sure if that is good or bad, just different from the more traditional learning transition I would think? None of the Arduino documentation seems to deal with this, and it doesn't seem to matter much to the goal of learning to program ones Arduino.

Lefty

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I certainly couldn't say which part was which.
After having done BASIC back in high school, and FORTRAN and some Z80 assembly in college, and exposure to other stuff as well that I couldn't even tell you the names of its been so long, I didn't find Arduino too hard to figure out for the mostly basic stuff I do now. For me it comes down more to understanding what external devices need.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 75
Posts: 7269
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So a quick dip into C++ can get you started, only if you already know C.

Well one fallout of the Arduino's popularity, for good or bad, is that there is and will continue to be thousands and thousands of new people learning to program their Arduino boards and not knowing what parts they are learning are C and what parts are C++.  Not sure if that is good or bad, just different from the more traditional learning transition I would think? None of the Arduino documentation seems to deal with this, and it doesn't seem to matter much to the goal of learning to program ones Arduino.

Lefty



Traditional programming learning should be changed! I learned BASIC at the right age, 7. So everything else was almost natural when I taught myself. On the other hand, the approach to teaching programming language should be the same as teaching any humanly language, start from reading simple but well written programs over and over before learning to write.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27386
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"start from reading simple" >> but well written programs<< "
Well I would say that includes comments too, and rules out a lot of the things that are posted arund here.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If anyone is in a situation like me, check out "Accelerated C++" by Koenig & Moo.  I've only been using it for a couple of days, but it seems like just the ticket for someone with a little programming (other than C) under their belt already, just needing to understand C++.
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I bought a few months ago a C++ book. It call " C++ for Dummies" by Stephen R. Davis It also include a CD-ROM of a IDE to program C++. It call "Code:Block" GNU C++ compiler. And I also bought recently "Sams Teach Yourself C++ in One Hour a Day"  No compiler...About the Ardino, I just receive my order today the book "Ardiuno Cookbook" Also bought recently a book call "The Art of Assembly Language". I have a EET background. I just catch up my knowledge here.

Here the store I bought theses books. http://www.chapters.indigo.ca/home/

I know, some of them are NOT CHEAP !!!  smiley-razz  But they are worth it.
Logged

Pages: [1]   Go Up
Jump to: