Hello, I am totally new to Arduino, and excited to get into mechantronics. I have experience with coding (BASIC, FORTRAN) but have never used C++. Using the basic Arduino language is easy enough for basic control, but as I get into things, and using libraries, I see inside some of the libraries the code is pretty complex, using syntax not in the Arduino syntax list, and lots of stuff I have never seen before. For example, the servo.h library, while simple to use, does lots of calls of other libraries, using syntax I don't understand. I have to assume all the stuff I don't know is C++. I am happy enough for now to use existing libraries (for practical reasons, to get my projects going), I don't like not knowing what is going on under the hood. My question really is, how much C++ do I need to learn to really GET Arduino? Thanks!!! Steven Lightfoot
More than novice, less than expert.
There are people that utilize Arduino for hobbies, they may never need to go beyond the basic Arduino language:
As projects become more complex, you may find that many Arduino "wrapper" commands are causing too much latency in your code execution. Then, C++ will be required to bypass the Arduino command and to execute at a level closer to the hardware.
Other users find they need something that is not available, so they create a library: C++ stuff.
So, there is no simple answer. Regardless of your intent, you will find that some C++ just gets on you regardless. Kind of like cat hair.
Have fun
Hello steven_lightfoot
At the latest when the programme consists of spaghetti code and code blocks repeat themselves, it is time and you should take a look at the C++ Toolbox.
It is not necessary to program classes, but the C++ Toolbox offers tools for structured programming.
Take a look at this very good reference to get started:
Have a nice day and have fun programming in C++.
Hey that is a great answer. Thank you. I like the cat hair allusion. For now I just want to control some DC motors, but I could see myself really getting into this, so I can see that I may need to get some real C++ under my belt. Cheers.
Thanks, great answer. I will review your reference.
You may know most of this but perhaps some things no so much:
Thx, that is helpful.
Standard C is enough for writing your own programs. In detail one should understand the proper use of C conditional expressions and values.
The use of objects is an easy part of the Arduino framework. A big step into C++ classes is required for writing your own libraries.
Agree, and while doing I take cover, as many think that learning C first is a mistaken path.
There are ppl here who, if they call themselves any kind of programmer, will say they are C programmers.
You can go a great distance without needing to look at the insides of any libraries.
Just use them the way they are used in examples.
The big difference to any kind of programming you may have done in the past has less to do with language and more to do with the special considerations that arise in coding for interaction with the real world through switches and LEDs and sensors and motors and so forth.
The logic and structure you can express with C is the same as what you've used for doing the same in Fortran or Basic or whatever. Variables, decisions, iteration and subordination.
C++ one day, should I live long enough and have enough functioning brain cells left.
a7
Early in my programming career i asked a friend how he could code in so many different languages? He said that "2 + 2 is ALWAYS 4, the rest is syntax".
I've coded in allsorts of languages from ada and asm to Z80 machine code. FORTRAN, APL, PHP, MYSQL, QBASIC, ladder logic, relays, HTML, autoLisp, TTL, etc., etc., etc, and my friend was right. In the final analysis, language is just an implementation detail.
My program layout and general structure never really varies, independent of language. If I can visualize it, I can build it, your choice of language. Maybe I'm slower or faster, but my "generic" code will port into most any language with little modification. Not saying it will be optimal, but generally, it'll run "fast enuf".
you can do a lot of good programming on arduino size programs without using more advanced c++ features (inheritance, polymophism, templates) or even classes but will no doubt absorb them over time
Brian Kernighan (The Unix Programming Environment see chap, the C Programming Language) said C doesn't have the guard rails C++ has for very large application (CAD system)
in a talk i attended at Bell Labs ~'86 on object oriented programming, the speaker said within the 1st three sentences that just because you're writing in C++ doesn't mean your doing object oriented programming and that you can do object oriented programming in most languages including assembler but not languages like fortran or basic (those languages also lack pointers which provide direct access to memory and memory mapper I/O
Or use so many different operating systems or text edit programs - once you get up to a certain level of (in)competence, the rest can be just pattern matching and bluffing.
Seven concepts in any of those will get out 98.6 percent of the way. True you may do things in a suboptimal way, but who cares?
a7
I still code in notepad (and befor that edlin and vi). It's universal, you can find it on most any box. I have it completely internalized. It doesn't care what I'm editing, batch files, html docs, source in any language, etc. I can walk in, sit down, and start banging out code. Yeah the ide is better/faster etc., but without it you're STUCK. I've even used just debug to create simple .com programs.
XOR AX, AX
NOT AX
PUSH AX
NOT AX
PUSH AX
RETF
For $0.05, what does that code do on an 80x86 box?
I make very primitive use of features in text editing.
A general rule I preach is that it is better to master a technique than a tool.
My GF has every imaginable kitchen appliance and utensil, and I truly enjoy the results she gets.
Me - one good knife and a cast iron fry pan. And decades of getting along with little else.
a7
Thank you. I dont really know the difference between C and C++, and I dont even really understand what object oriented means, but I will get there!
Yes thanks, I get your point. In the real world I have quite a lot of experience with transducers, being a mechanical engineer. And I agree, I will be able to do a lot without understanding the details of libraries, for now I will use them as black boxes, its simply that I dont really like black boxes!
cool. Great points and I agree.
Seems like you have two competing inclinations - Getting a project done with minimal fuss verses wanting to know what's inside the black box.
Jumps to address 0xFFFF0? (I'm partly guessing the first word pushed is the segment which is shifted left by 4 bits.)
Yes, that is an astute observation. I have an inclination for both. For the time being, I will concentrate on getting some DC motors driving some mechanical oscillators (my immediate goal) with basic Arduino and then settle later in a few months and teach myself some C++ proper.