Need general programming (direction) advice. A little confusion.

I am new to programming and Arduinio in particular. I have been reading a lot about the Arduino world. There is much talk of Java and much about C / C++ and so on.

I have a good grasp of the Arduino programming language and have made several small projects with GPS, IR, PIR, SD cards, I2C and so on... but now want to learn more: what is under the hood and how it works in terms of programming and deeper access of the micro-controller (ATmega328P).

I work full time and have a family: time is limited. Is it best for me to learn standard (ie: Sun Microsystems) Java or better to learn C, or C++ or C#? I do not see a clear "best way" from what I read (and what little I understand now).

I want to be able to understand more than just if / then / else / for / while and so on.

So when I see C code and libs i can understand line by line what the external code is actually doing and so on.

Thanks for any and all advice.

Well, Arduino code is C++, a run-time environment, and a hardware abstraction layer. So if you have a good grasp of the Arduino programming language then you already have a good grasp of C++.

To go deeper, you may need to learn a little assembler.

The only connection between Java and Arduino that I am aware of is that the IDE is written in java.

The Arduino "Language" is C++, though mostly it's pretty C-like. C# would probably be a mistake.
The Arduino IDE is WRITTEN in Java, but otherwise has nothing to do with Java.

I would probably start with trying to learn C, since a C class/textbook/etc is less likely to veer off into topics that are relatively inapplicable to Arduino or Embedded systems in general.

However, even C instruction tends to be focused on "how to do stuff" rather than "how it works underneath." This is normally ok, because you're not really supposed to need to know how it works underneath. But if that's really your goal, I'm not sure how things will go... You might be better off with something specifically about AVR programming. I don't have any particular recommendations; such books seem to divide into pre-arduino (not as beginner-friendly) and post-arduino (friendlier, but less deep.)

On the third hand, it's a tenet of computer science that the specific language you learn shouldn't matter so much - all (most of) the principles remain similar regardless of the actual language. That IS true to some extent, but "style" and "flavor" vary a lot; you can learn a lot about writing Python without learning anything that is immediately applicable to the Arduino world. That's not THAT bad, because learning the "other ways of look at things" is a fine idea. But it can be frustrating. (Note that the 2nd class of a BSCS curricula is usually a "data structures and algorithms" class, and NOT an "advanced programming in the same language you learned in CS101", nor a "now here's another programming language."

On the fourth hand, there are some really excellent MOOCs out there that are not applicable to Arduino, and might be worth checking out. I can recommend: Set of Python classes. Very enthusiastic and evangelical teacher. Open source class materials and textbook. Algorithms (in Java.) Very good; the textbook is a classic, and it was written by the prof. The part2 followup is similar. A more academically rigorous Python class. Bare metal embedded systems and concepts. Sounds like exactly what you want, except for maybe the "bare metal" part, and the fact that it's based on a TI ARM Launchpad rather than an Arduino.

but now want to learn more: what is under the hood and how it works in terms of programming and deeper access of the micro-controller (ATmega328P)

Study the datasheet and look at the sample codes. I would stick with C/C++ or go hardcore with assembly. For what you want to learn, there is no place for other languages in my opinion.

Thanks everyone for the advice... It sounds like my best course of action (since I am focused on micro controllers and the Arduino world specifically) is to :

  1. learn C++. Learn how to manipulate C type char arrays rather than String class, etc. Try to write my Arduino code as "C like" as possible.

  2. Go deeper into the specific Atmel 329p (and others). Buy a good book on the C - Atmel connections and learn more about the hardware (registers, how the ADC works, etc).

  1. IF and only IF I have time left over (which I will not) learn algorithms and other "stuff".

That will be my plan of action: does this sound about right (for what I hope to gain which is getting the most out of the Atmel and Arduino world)?

For your stated goal of using arduino to make farm chores easier, yes, learn C. Note though that there are plenty of classes provided in the arduino libraries so you'll be using C++ constructs too e.g. Serial. No need to write your own classes in most projects though - they tend to be simple enough that they're not necessary.

Most Arduino users don't dig into the details of the hardware at the register level; the compiler's job is to abstract that away for you. It might be interesting stuff, but for building Arduino projects, it's really not necessary and if your time is constrained, this is the obvious area of study to drop.

As to algorithms - that can come later and of course you can get advice on that here.

Most Arduino users don’t dig into the details of the hardware at the register level; the compiler’s job is to abstract that away for you.

It’s not the compilers job. It’s the Arduino environment (the libraries) that gives the abstraction.

I'm like you as I like to know whats happening under the hood.
So you will want to get the reference manual on the chip your using.
In it describes all the peripherials and how they work, usart, ADC, I2c etc...
Also, it describes all the registers and what the bits do.

When you know whats going on at the register level (other wise known a bare metal) then you
have a deeper knowledge on how the hardware works. This is normally hidden from you
by higher level languages that abstract by giving us nice functions to work with.

If you are learning the language you dont have to always download your program to the
microcontroller. You can use a your desktop, and get a free C compilier. It is quicker that
way as far as just learning syntax and trying things out.

Arduino uses AVR GCC/C++ compilier so it is ansi C . Get to know it and the libraries C offers.

The Arduino libraries use C++. I do not know C++ at all. So if you want to go through the
arduino files and see whats going on you'll have to learn a bit of C++.

Westfw gave an excellent overview of the landscape in his response.

Good luck!

I just searched for "AVR GCC/C++ compilier" there is so much out there. I am not sure which compiler I should get to work with the 328P.... does anyone have a link for the "right" compiler for the ATmetl chips that will run on Windows 7? Thank you in advance.

You should be able to use the Arduino IDE. You can overwrite main() in your sketch and leave all Arduino related stuff (e.g. pinMode, digitalWrite) out for now. There is probably already some stuff predefined like register ‘names’ so you don’t have to worry about that.

So this works as a blink example (different and primitive timing)

int main()
  // PB5 is led on pin 13

  // output
  DDRB = 1 << PB5;

  // forever
  for (;;)
    // led on
    PORTB |= 0x20;
    // delay a bit
    for (uint32_t cnt = 0; cnt < 1000000; cnt++)
    // led off
    PORTB &= 0xDF;
    delay a bit
    for (uint32_t cnt = 0; cnt < 1000000; cnt++)

Thanks, I have always wanted to get a little more into this.

Thank you! I will start on C / C++ tonight :slight_smile:

The arduino ide uses AVR GC/C+ compiler. It is used in building your project automatically, so you do not have to install anything other than Arduino IDE.

What I was talking about is learning C/C++ on your desktop using one of the free
compilers. For example I use Pelles C compiler, it comes with an IDE . This compiler
does not compile C code for your chip. It is just a tool for learning C on windows. It just
saves you time and is more convenient than downloading to your board.

Sorry if I confused you.

Here is the link if your interested. smorgasbordet - Pelles C
BTW Pelles is NOT a C++ compiler.